@slugbugblue/trax 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @slugbugblue/trax
2
2
 
3
+ ## 0.8.0 - 2022-04-08
4
+
5
+ - Breaking change: `playMove()` now takes the _next_ move number instead of the
6
+ _last_ move number. It makes more sense to say "move number 1 is @0/" than to
7
+ say "the move following move number 0 is @0/".
8
+ - Added variant name info to the engine as `Trax.name[rules]` as well as
9
+ `trax.name`
10
+ - Restructured the repo to handle additional files, creating `src` and `hooks`
11
+ folders
12
+ - Added a command-line interface (CLI) `cli.js` which npm will install using the
13
+ alias `trax`
14
+ - The CLI usage is self-documenting; run `trax help` to get started
15
+ - Initial commands available: `delete`, `export`, `help`, `import`, `list`,
16
+ `new`, `play`, `select`, `try`, `undo`, `view`
17
+
3
18
  ## 0.7.0 - 2022-03-28
4
19
 
5
20
  - Fixed a bug when including extra characters in a starting notation
package/README.md CHANGED
@@ -9,7 +9,9 @@ information about Trax, including its rules and history, see the official
9
9
  website at [traxgame.com][traxgame].
10
10
 
11
11
  This goal of this javascript project is to allow Trax to be played
12
- programmatically. It can be used as an engine in a web browser or in nodejs.
12
+ programmatically. It can be used as an engine in a web browser, for example at
13
+ [slugbugblue.com][sbb]; or in nodejs, for example by using the `trax` CLI
14
+ provided as part of this project.
13
15
 
14
16
  The Trax engine now enjoys automated testing with 100% code coverage. Any future
15
17
  changes to the engine should meet the same standard.
@@ -17,10 +19,81 @@ changes to the engine should meet the same standard.
17
19
  ## Installation
18
20
 
19
21
  ```bash
22
+ # Install into a javascript project
20
23
  npm install @slugbugblue/trax
24
+
25
+ # Or install globally to use the trax CLI
26
+ npm install -g @slugbugblue/trax
27
+ ```
28
+
29
+ ## CLI Usage
30
+
31
+ The command-line interface is provided as `trax`, available in your path if
32
+ installed globally, or in the `node_modules/.bin` directory and runnable using
33
+ `npx trax` if installed locally.
34
+
35
+ The CLI can be used interactively by passing the `--interactive` or `-i` flag.
36
+ When run interactively, you can avoid worries about the need to escape certain
37
+ characters from the shell, and it can be easier to run multiple commands back to
38
+ back.
39
+
40
+ Help is available for the CLI through the use of the `help` command. Type
41
+ `trax help` to see a list of the available commands, and `trax help play` to see
42
+ information about the `play` command. Aliases and abbreviations are provided to
43
+ minimize typing and to try to avoid the requirement of memorizing the commands.
44
+ For example, the `list` command has an alias of `ls`, and the `select` command
45
+ can be activated using `#`.
46
+
47
+ When you first launch the CLI, you can create a new game using the `new`
48
+ command, and then enter moves for that game using `play`. Since `play` is likely
49
+ to be the most common command used, you can simply omit the command name. For
50
+ example, at the interactive prompt, entering `@0/` is the same as if you had
51
+ entered `play 1. @0/`.
52
+
53
+ Multiple games can be started at once, and the CLI will remember the currently
54
+ active game and apply future actions to that game. Each game will retain its
55
+ `#id` number until it is deleted, and you can use that number to switch between
56
+ games. For example, to make game #1 active, enter `select 1` or `select #1` or
57
+ simply `#1` at the interactive prompt.
58
+
59
+ For ease of working at the command line, the symbols used as the last character
60
+ of the Trax notation can optionally be replaced with letters. Use `s` for slash
61
+ symbol (`/`), `b` for backslash (`\`), and `p` for plus (`+`). While there is no
62
+ need to escape at the interactive prompt, these substitutions will be avilable
63
+ there as well.
64
+
65
+ The CLI uses standard Windows and Linux [XDG][xdg] file locations as provided by
66
+ the [env-paths library][env-path], with current uses being the `config` and
67
+ `data` folders.
68
+
69
+ Examples:
70
+
71
+ ```text
72
+ # Start a new Trax game with Chad playing as white
73
+ > trax new Chad vs
74
+
75
+ # Start a new Loop Trax game with Chad playing as black
76
+ > trax new loop vs Chad
77
+
78
+ # Start a new 8x8 Trax game with Chad as white and Another Player as black
79
+ > trax new 8x8 Chad vs Another Player
80
+
81
+ # Switch back to the first game. Note the quoting required at the command line.
82
+ # This would not be necessary when running at the interactive prompt.
83
+ > trax '#1'
84
+
85
+ # Play two moves, using full notation
86
+ > trax play 1. @0/ 2. A0/
87
+
88
+ # Two more moves, using short notation and symbol substitution
89
+ # B2/ => b2s and A0\ => a0b
90
+ > trax b2s a0b
91
+
92
+ # See the status of all games
93
+ > trax ls
21
94
  ```
22
95
 
23
- ## Usage
96
+ ## API Usage
24
97
 
25
98
  The main Trax engine is provided as `engine.js`, which can be used as follows:
26
99
 
@@ -46,8 +119,8 @@ For specifics, see the [engine.js documentation][engine-docs].
46
119
 
47
120
  ## Roadmap
48
121
 
49
- - Command line interface
50
- - Bot for solo games (?)
122
+ - Game position analysis
123
+ - Bot
51
124
  - Puzzles
52
125
 
53
126
  ## Support
@@ -103,8 +176,11 @@ David Smith and heirs, and are not to be used without permission.
103
176
  [ctrans]: mailto:chad@transtrum.net
104
177
  [dgb]: mailto:donald@traxgame.com
105
178
  [engine-docs]: docs/engine.md
179
+ [env-path]: https://www.npmjs.com/package/env-paths
106
180
  [goldtoken]: https://goldtoken.com/
107
181
  [repo]: https://gitlab.com/slugbugblue/trax
108
182
  [sbb]: https://slugbugblue.com/
109
183
  [traxbook]: http://traxgame.com/shop_book.php
110
184
  [traxgame]: http://traxgame.com/
185
+ [xdg]:
186
+ https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
package/docs/engine.md CHANGED
@@ -35,7 +35,9 @@ class properties and methods:
35
35
 
36
36
  - `Trax.variants`: a Set of the different rule sets the engine supports. Try
37
37
  `Trax.variants.has(rule)` to see if your favorite rule set is supported. Or
38
- `Trax.variants.forEach(s => { console.log(t) })` to list them all.
38
+ `Trax.variants.forEach((rule) => { console.log(rule) })` to list them all.
39
+
40
+ - `Trax.names`: an object of variant rule set names to English names.
39
41
 
40
42
  - `Trax.point(x, y)`: quick access to the [Point class][point-docs], for
41
43
  two-dimensional locations used internally by the Trax engine and which are
@@ -121,6 +123,8 @@ unpredictable and invalid operations by the engine.
121
123
 
122
124
  #### calculated properties
123
125
 
126
+ - `name`: string, a shortcut to get the actual name of the game from its variant
127
+ rule set code
124
128
  - `count`: number, the total number of tiles currently in play
125
129
  - `color`: string, the color (`'w'` or `'b'`) of the player whose turn it is
126
130
  - `gameOver`: boolean, `true` if the game is over
@@ -166,14 +170,25 @@ each move that can be played will be legal.
166
170
  Attempts to play the given `notation`. Updates the game instance if the notation
167
171
  is valid for the current position.
168
172
 
169
- ##### `playMove(currentMoveNumber, nextMoveNotation)`
173
+ Returns an object with at minimum the following key/value pair:
174
+
175
+ - `valid`: `true` if the move is valid and results in a legal position
176
+
177
+ If the move is valid, the following will also be part of the returned object:
178
+
179
+ - `dropped`: a list of the tiles that were played by this move
180
+ - `notation`: the resulting notation of the move
181
+
182
+ ##### `playMove(moveNumber, notation)`
170
183
 
171
184
  Used to play a move, but with an extra safeguard around the status of the game
172
185
  so that if this is called multiple times with the same values, it will ignore
173
186
  subsequent calls, which can be useful in the context of asynchronous
174
187
  communication and retries, such as when this engine is being used as the back
175
188
  end of a web interface. For example, if no moves have been made yet in a game,
176
- this can be called either as `playMove(0, '@0/')` or `playMove(0, '@0+')`.
189
+ this can be called either as `playMove(1, '@0/')` or `playMove(1, '@0+')`.
190
+
191
+ Returns the same object structure as the `play()` method.
177
192
 
178
193
  ##### `provisionalMove(from, to, via)`
179
194
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slugbugblue/trax",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Trax game engine and friends",
5
5
  "keywords": [
6
6
  "trax",
@@ -11,12 +11,15 @@
11
11
  "bugs": "https://gitlab.com/slugbugblue/trax/issues",
12
12
  "license": "Apache-2.0",
13
13
  "author": "Chad Transtrum <chad@transtrum.net>",
14
- "exports": "./engine.js",
14
+ "exports": "./src/engine.js",
15
15
  "repository": "gitlab:slugbugblue/trax",
16
+ "bin": {
17
+ "trax": "./src/cli.js"
18
+ },
16
19
  "scripts": {
17
20
  "test": "xo && c8 ava",
18
21
  "preversion": "npm test",
19
- "postversion": "git push && git push --tags"
22
+ "postversion": "hooks/postversion.sh src/version.js"
20
23
  },
21
24
  "dependencies": {
22
25
  "env-paths": "^3.0.0",
@@ -26,6 +29,7 @@
26
29
  "devDependencies": {
27
30
  "ava": "^4.1.0",
28
31
  "c8": "^7.11.0",
32
+ "genversion": "^3.0.2",
29
33
  "prettier": "^2.6.1",
30
34
  "xo": "^0.48.0"
31
35
  },