@slugbugblue/trax 0.7.0 → 0.10.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/.c8rc.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "branches": 95,
3
+ "check-coverage": true,
4
+ "functions": 95,
5
+ "lines": 95,
6
+ "statements": 95
7
+ }
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Do not show the diff for the npm lock file
2
+ package-lock.json -diff
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @slugbugblue/trax
2
2
 
3
+ ## 0.10.0 - 2022-06-12
4
+
5
+ - Added `point.in(topLoft, bottomRight)` to see if a point is inside a
6
+ rectangular bounded area
7
+ - Minor coding style changes due to updated `xo` rules
8
+
9
+ ## 0.9.0 - 2022-04-24
10
+
11
+ - Added tab-completion and completion preview code to the interactive CLI
12
+ - Restructured the CLI by moving most commands to their own file
13
+ - Changed the `view` CLI command to optionally examine previous moves
14
+
15
+ ## 0.8.0 - 2022-04-08
16
+
17
+ - Breaking change: `playMove()` now takes the _next_ move number instead of the
18
+ _last_ move number. It makes more sense to say "move number 1 is @0/" than to
19
+ say "the move following move number 0 is @0/".
20
+ - Added variant name info to the engine as `Trax.name[rules]` as well as
21
+ `trax.name`
22
+ - Restructured the repo to handle additional files, creating `src` and `hooks`
23
+ folders
24
+ - Added a command-line interface (CLI) `cli.js` which npm will install using the
25
+ alias `trax`
26
+ - The CLI usage is self-documenting; run `trax help` to get started
27
+ - Initial commands available: `delete`, `export`, `help`, `import`, `list`,
28
+ `new`, `play`, `select`, `try`, `undo`, `view`
29
+
3
30
  ## 0.7.0 - 2022-03-28
4
31
 
5
32
  - 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
 
@@ -44,11 +117,9 @@ puzzle.play('@2\\')
44
117
 
45
118
  For specifics, see the [engine.js documentation][engine-docs].
46
119
 
47
- ## Roadmap
120
+ ## Related Projects
48
121
 
49
- - Command line interface
50
- - Bot for solo games (?)
51
- - Puzzles
122
+ - [TraxBot][traxbot]: Game position analysis and puzzlebot
52
123
 
53
124
  ## Support
54
125
 
@@ -69,11 +140,11 @@ Thanks to his widow Colleen Foley-Smith for extending that courtesy to allow me
69
140
  to include Trax on [slugbugblue.com][sbb] as well.
70
141
 
71
142
  I would also like to extend a huge heartfelt appreciation to the magnanimous
72
- [Donald G. Bailey][dgb], who, through his excellent [book][traxbook], taught me
73
- the basics (and more!) of Trax. I found him always ready to share his insights
74
- on the mechanics of the game, as well as various approaches to encoding its
75
- complexities. His undeserved kindness and infinite patience in indulging my many
76
- questions can never be repaid.
143
+ [Donald G. Bailey][dgb], who, through his excellent book [Trax Strategy for
144
+ Beginners][traxbook], taught me the basics (and more!) of Trax. I found him
145
+ always ready to share his insights on the mechanics of the game, as well as
146
+ various approaches to encoding its complexities. His undeserved kindness and
147
+ infinite patience in indulging my many questions can never be repaid.
77
148
 
78
149
  ## License
79
150
 
@@ -92,7 +163,7 @@ specific language governing permissions and limitations under the License.
92
163
 
93
164
  ## Trax rules copyright
94
165
 
95
- In the United States, game mechanics are not eligible for coyright protection;
166
+ In the United States, game mechanics are not eligible for copyright protection;
96
167
  however, the specific wording of game rules does fall under copyright law.
97
168
 
98
169
  The official rules for Trax are found at http://traxgame.com/about_rules.php.
@@ -103,8 +174,12 @@ David Smith and heirs, and are not to be used without permission.
103
174
  [ctrans]: mailto:chad@transtrum.net
104
175
  [dgb]: mailto:donald@traxgame.com
105
176
  [engine-docs]: docs/engine.md
177
+ [env-path]: https://www.npmjs.com/package/env-paths
106
178
  [goldtoken]: https://goldtoken.com/
107
179
  [repo]: https://gitlab.com/slugbugblue/trax
108
180
  [sbb]: https://slugbugblue.com/
109
181
  [traxbook]: http://traxgame.com/shop_book.php
182
+ [traxbot]: https://gitlab.com/slugbugblue/traxbot
110
183
  [traxgame]: http://traxgame.com/
184
+ [xdg]:
185
+ 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/docs/point.md CHANGED
@@ -85,6 +85,13 @@ Returns the distance between two points. This will never be a negative number.
85
85
  Returns `true` if the given point or point-like object is at the same location
86
86
  as the existing point.
87
87
 
88
+ ##### `in(topLeft, bottomRight)`
89
+
90
+ Pass in two points (or point-like objects) to define a rectangular bounding box.
91
+
92
+ Returns `true` if the calling point is located inside the box or along any of
93
+ its edges (ie, both bounding points are considered "inside").
94
+
88
95
  #### Plays well with others
89
96
 
90
97
  The Point class also includes functionality to provide useful default results
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slugbugblue/trax",
3
- "version": "0.7.0",
3
+ "version": "0.10.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,8 +29,9 @@
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
- "xo": "^0.48.0"
34
+ "xo": "0.*"
31
35
  },
32
36
  "type": "module",
33
37
  "engines": {