@slugbugblue/trax 0.20.0 → 0.22.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,25 @@
1
1
  # @slugbugblue/trax
2
2
 
3
+ ## 0.22.0 - 2023-03-25
4
+
5
+ - Pull point.js into its own package: `@slugbugblue/point`
6
+ - Pull lru.js into its own package: `@slugbugblue/lru`
7
+ - Pull puzzles.js into its own package: `@slugbugblue/trax-puzzles`
8
+ - Pull tty.js into its own package: `@slugbugblue/trax-tty`
9
+ - Pull analyst.js into its own package: `@slugbugblue/trax-analyst`
10
+ - Pull cli.js into its own package: `@slugbugblue/trax-cli`
11
+
12
+ ## 0.21.0 - 2023-03-12
13
+
14
+ - Update the analysis engine to be more lazy
15
+
16
+ - The LRU cache is more likely to have a hit because it no longer separates
17
+ validated from unvalidated analyses
18
+ - Suggestions are much faster because it now skips validations for low-scoring
19
+ moves
20
+ - You will now need to call `validateThreats()` to remove faulty threats
21
+ manually
22
+
3
23
  ## 0.20.0 - 2023-02-11
4
24
 
5
25
  - Provide timing feedback on the puzzlebot's actions
package/README.md CHANGED
@@ -1,11 +1,6 @@
1
1
  # Trax
2
2
 
3
- This project aims to provide tools for working with Trax games in Javascript.
4
-
5
- - Trax game-playing engine
6
- - Position analysis engine
7
- - Over 100 puzzles to help hone your Trax skills
8
- - Command-line interface for ease of use
3
+ This project provides the ability to work with Trax games in Javascript.
9
4
 
10
5
  ## Description
11
6
 
@@ -15,111 +10,15 @@ information about Trax, including its [rules][traxrules] and
15
10
 
16
11
  The goal of this javascript project is to allow Trax to be played
17
12
  programmatically. It can be used as an engine in a web browser, for example at
18
- [slugbugblue.com][sbb]; or in nodejs, for example by using the `trax` CLI
19
- provided as part of this project.
13
+ [slugbugblue.com][sbb]; or in nodejs, for example by using the [trax
14
+ CLI][trax-cli] provided as a child of this project.
20
15
 
21
16
  The Trax engine now enjoys automated testing with 100% code coverage. Any future
22
- changes to the engine should meet the same standard.
23
-
24
- ## Installation
25
-
26
- ```bash
27
- # Install into a javascript project
28
- npm install @slugbugblue/trax
29
-
30
- # Or install globally to use the trax CLI more easily
31
- npm install -g @slugbugblue/trax
32
-
33
- # Or create a docker image
34
- docker build -t trax .
35
- ```
36
-
37
- ## CLI Usage
38
-
39
- The command-line interface is provided as `trax`, available in your path if
40
- installed globally, or in the `node_modules/.bin` directory and runnable using
41
- `npx trax` if installed locally.
42
-
43
- > If you installed by creating a Docker image, use the following command to
44
- > launch the CLI:
45
- >
46
- > - `docker run --name trax -itv $HOME/trax:/mnt/data --rm trax`
47
- >
48
- > Since that's a bit much to type, it's recommended to create an alias in one of
49
- > your startup scripts:
50
- >
51
- > - `alias trax="docker run --name trax -itv $HOME/trax:/mnt/data --rm trax"`
52
- >
53
- > Then you can launch the docker container simply by typing in `trax`, the same
54
- > as if it were installed globally.
55
-
56
- The CLI can be used interactively by running the command with no parameters or
57
- by passing the `--interactive` or `-i` flag. When run interactively, you can
58
- avoid worries about the need to escape certain characters from the shell, and it
59
- can be easier to run multiple commands back to back.
60
-
61
- Help is available for the CLI through the use of the `help` command. Type
62
- `trax help` (or `npx trax help` with a local installation, or simply `help` if
63
- run interactively) to see a list of the available commands, and `trax help play`
64
- to see information about the `play` command. Aliases and abbreviations are
65
- provided to minimize typing and to try to avoid the requirement of memorizing
66
- the commands. For example, the `list` command has an alias of `ls`, and the
67
- `select` command can be activated using `#`.
68
-
69
- When you first launch the CLI, you can create a new game using the `new`
70
- command, and then enter moves for that game using `play`. Since `play` is likely
71
- to be the most common command used, you can simply omit the command name. For
72
- example, at the interactive prompt, entering `@0/` is the same as if you had
73
- entered `play 1. @0/`.
74
-
75
- Multiple games can be started at once, and the CLI will remember the currently
76
- active game and apply future actions to that game. Each game will retain its
77
- `#id` number until it is deleted, and you can use that number to switch between
78
- games. For example, to make game #1 active, enter `select 1` or `select #1` or
79
- simply `#1` at the interactive prompt.
80
-
81
- For ease of working at the command line, the symbols used as the last character
82
- of the Trax notation can optionally be replaced with letters. Use `s` for slash
83
- symbol (`/`), `b` for backslash (`\`), and `p` for plus (`+`). While there is no
84
- need to escape at the interactive prompt, these substitutions will be avilable
85
- there as well.
86
-
87
- The CLI uses standard Windows and Linux [XDG][xdg] file locations as provided by
88
- the [env-paths library][env-path], with current uses being the `config` and
89
- `data` folders.
90
-
91
- Examples:
92
-
93
- ```text
94
- # Start a new Trax game with Chad playing as white
95
- > trax new Chad vs
96
-
97
- # Start a new Loop Trax game with Chad playing as black
98
- > trax new loop vs Chad
99
-
100
- # Start a new 8x8 Trax game with Chad as white and Another Player as black
101
- > trax new 8x8 Chad vs Another Player
102
-
103
- # Switch back to the first game. Note the quoting required at the command line.
104
- # This would not be necessary when running at the interactive prompt.
105
- > trax '#1'
106
-
107
- # Play two moves, using full notation
108
- > trax play 1. @0/ 2. A0/
109
-
110
- # Two more moves, using short notation and symbol substitution
111
- # B2/ => b2s and A0\ => a0b
112
- > trax b2s a0b
113
-
114
- # See the status of all games
115
- > trax ls
116
- ```
17
+ changes should meet the same standard.
117
18
 
118
19
  ## API Usage
119
20
 
120
- ### Trax engine
121
-
122
- The main Trax engine is provided in `engine.js`, which can be used as follows:
21
+ The Trax engine can be used as follows:
123
22
 
124
23
  ```javascript
125
24
  import { Trax } from '@slugbugblue/trax'
@@ -139,47 +38,7 @@ let puzzle = new Trax('trax', '@0/ a0\\ @2/')
139
38
  puzzle.play('@2\\')
140
39
  ```
141
40
 
142
- For specifics, see the [engine.js documentation][docs-engine].
143
-
144
- ### Analysis
145
-
146
- The analysis engine is provided in `analyst.js`, and it can be used as follows:
147
-
148
- ```javascript
149
- import { Trax } from '@slugbugblue/trax'
150
- import { analyze } from '@slugbugblue/trax/analyst'
151
-
152
- let trax = new Trax('trax', '@0/ @1\\')
153
-
154
- let analysis = analyze(trax)
155
-
156
- console.log('Edge analysis:', analysis.edge)
157
- console.log('Threat analysis:', analysis.threats)
158
- console.log('Score analysis:', analysis.scores)
159
- ```
160
-
161
- For additional information, refer to the [analyst.js
162
- documentation][docs-analyst].
163
-
164
- ### Threats database
165
-
166
- The threats database is currently hand-coded in `threats.js`, so refer to that
167
- file if you want to try to update the analysis engine's understanding of
168
- threats.
169
-
170
- ### Puzzles database
171
-
172
- The puzzles database is provided in `puzzles.js`, and contains puzzles that I've
173
- been using to test the analysis engine, publicly available puzzles from [the
174
- traxgame.com puzzles page][traxpuzzles], and [puzzles curated][puzzlebook] by
175
- [Martin M. S. Pedersen][traxplayer].
176
-
177
- ## Roadmap
178
-
179
- - Improve the threats database / analysis engine.
180
- - Bot should be able to win all puzzles.
181
- - Analysis should recognize line threats.
182
- - Add more puzzles.
41
+ For specifics, see the [engine.js documentation][docs].
183
42
 
184
43
  ## Support
185
44
 
@@ -208,7 +67,7 @@ infinite patience in indulging my many questions can never be repaid.
208
67
 
209
68
  Thanks to [Martin M. S. Pedersen][traxplayer] for contributing ideas, code, and
210
69
  puzzles. He's been [curating Trax puzzles][puzzlebook] and [coding solutions for
211
- Trax][gnutrax] for over two decades, and brings a lot of expertise.
70
+ Trax][gnutrax] for over two decades, and has a lot of expertise in this area.
212
71
 
213
72
  ## License
214
73
 
@@ -238,19 +97,15 @@ David Smith and heirs, and are not to be used without permission.
238
97
  [contributing]: CONTRIBUTING.md
239
98
  [ctrans]: mailto:chad@transtrum.net
240
99
  [dgb]: mailto:donald@traxgame.com
241
- [docs-engine]: docs/engine.md
242
- [docs-analyst]: docs/analyst.md
243
- [env-path]: https://www.npmjs.com/package/env-paths
100
+ [docs]: docs/engine.md
244
101
  [gnutrax]: https://gnutrax.com
245
102
  [goldtoken]: https://goldtoken.com/
246
103
  [puzzlebook]: https://gnutrax.com/book
247
104
  [repo]: https://gitlab.com/slugbugblue/trax
248
105
  [sbb]: https://slugbugblue.com/
106
+ [trax-cli]: https://gitlab.com/slugbugblue/trax-cli
249
107
  [traxbook]: http://traxgame.com/shop_book.php
250
108
  [traxgame]: http://traxgame.com/
251
109
  [traxhistory]: http://www.traxgame.com/about_history.php
252
110
  [traxplayer]: mailto:traxplayer@gmail.com
253
- [traxpuzzles]: http://www.traxgame.com/games_puzzles.php
254
111
  [traxrules]: http://www.traxgame.com/about_rules.php
255
- [xdg]:
256
- https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
package/docs/engine.md CHANGED
@@ -427,4 +427,4 @@ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
427
427
  CONDITIONS OF ANY KIND, either express or implied. See the License for the
428
428
  specific language governing permissions and limitations under the License.
429
429
 
430
- [point-docs]: point.md
430
+ [point-docs]: https://gitlab.com/slugbugblue/point
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@slugbugblue/trax",
3
- "version": "0.20.0",
4
- "description": "Trax game engine and friends",
3
+ "version": "0.22.0",
4
+ "description": "Trax game engine",
5
5
  "keywords": [
6
6
  "trax",
7
7
  "traxgame",
@@ -14,33 +14,22 @@
14
14
  "types": "./src/types.d.ts",
15
15
  "exports": {
16
16
  ".": "./src/engine.js",
17
- "./analyst": "./src/analyst.js",
18
- "./lru": "./src/lru.js",
19
- "./point": "./src/point.js",
20
- "./puzzles": "./src/puzzles.js",
21
- "./threats": "./src/threats.js",
22
- "./tty": "./src/tty.js",
23
- "./utils": "./src/utils.js",
24
- "./version": "./src/version.js"
17
+ "./version": "./src/version.js",
18
+ "./version.js": "./src/version.js"
25
19
  },
26
20
  "repository": "gitlab:slugbugblue/trax",
27
- "bin": {
28
- "trax": "./src/cli.js"
29
- },
30
21
  "scripts": {
31
- "benchmark": "node benchmark/puzzles.bench.js",
32
22
  "genversion": "genversion --es6 src/version.js",
33
- "git-add": "git add src/version.js benchmark/benchmarks.json",
23
+ "git-add": "git add src/version.js",
34
24
  "test": "xo && c8 ava",
35
25
  "prepare": "husky install",
36
26
  "preversion": "npm test",
37
- "version": "npm run genversion ; npm run benchmark ; npm run git-add",
27
+ "version": "npm run genversion ; npm run git-add",
38
28
  "postversion": "git push && git push --tags && npm publish"
39
29
  },
40
30
  "dependencies": {
41
- "env-paths": "^3.0.0",
42
- "make-dir": "^3.1.0",
43
- "yaml": "^2.0.0-11"
31
+ "@slugbugblue/lru": "^1.0.0",
32
+ "@slugbugblue/point": "^1.0.0"
44
33
  },
45
34
  "devDependencies": {
46
35
  "ava": "^5.1.0",
@@ -55,11 +44,11 @@
55
44
  "node": ">=16.15.0"
56
45
  },
57
46
  "c8": {
58
- "branches": 95,
47
+ "branches": 100,
59
48
  "check-coverage": true,
60
- "functions": 95,
61
- "lines": 95,
62
- "statements": 95
49
+ "functions": 100,
50
+ "lines": 100,
51
+ "statements": 100
63
52
  },
64
53
  "prettier": {
65
54
  "bracketSpacing": true,
package/src/engine.js CHANGED
@@ -15,23 +15,14 @@
15
15
 
16
16
  // Trax internals. Woot.
17
17
 
18
- // Tile type names are determined by listing the line color at each edge,
19
- // starting from the top and going clockwise, and then sorted alphabetically
20
- // and given a single letter name, so 'bbww' becomes 'a', which gives us six
21
- // different tile names: a-f
18
+ import { Point } from '@slugbugblue/point'
22
19
 
23
- import { Point } from '@slugbugblue/trax/point'
24
-
25
- // Type definitions
26
20
  // Fun trax helper constants
27
21
 
28
22
  const zero = new Point(0, 0)
29
23
  const moveNumberRegex = /^(\d+)[.):]?$/
30
24
  const notationRegex = /^([@a-z]+)(\d+)([/\\+])$/i
31
25
 
32
- /** @type ValidTiles[] */
33
- const tileTypes = ['a', 'b', 'c', 'd', 'e', 'f']
34
-
35
26
  /** Tiles are represented by the letters a-f.
36
27
  * a b c d e f
37
28
  * +--#--+ +--#--+ +--#--+ +--o--+ +--o--+ +--o--+
@@ -40,7 +31,12 @@ const tileTypes = ['a', 'b', 'c', 'd', 'e', 'f']
40
31
  * | o | | # | | o | | # | | o | | # |
41
32
  * +--o--+ +--#--+ +--o--+ +--#--+ +--o--+ +--#--+
42
33
  *
43
- * Slashes are represented by / \ or +.
34
+ * @readonly
35
+ * @type ValidTiles[]
36
+ * */
37
+ const tileTypes = ['a', 'b', 'c', 'd', 'e', 'f']
38
+
39
+ /** Slashes are represented by / \ or +.
44
40
  * @readonly
45
41
  * @type {Record<ValidTiles, Slash>}
46
42
  */
@@ -252,7 +248,6 @@ export class Trax {
252
248
  /** Restore a previously saved position.
253
249
  * @arg {SaveState} saved - the previously saved state
254
250
  * @see save for saving the state
255
- * @returns {void}
256
251
  */
257
252
  restore(saved) {
258
253
  // So we need to be able to restore it when we are done
package/src/types.d.ts CHANGED
@@ -7,125 +7,6 @@
7
7
  /** Color is a single character to represent white or black. */
8
8
  type Color = 'w' | 'b'
9
9
 
10
- /** Colorize is a fancy function for colorizing text. */
11
- type Colorize = (text: string, def?: string | number) => string
12
-
13
- /** Colorer is a little too fancy. Hence the gnarly typescript. */
14
- type Colorer = {
15
- (text: string, def?: string | number): string
16
- black: Colorize
17
- command: Colorize
18
- default: Colorize
19
- error: Colorize
20
- fatal: Colorize
21
- help: Colorize
22
- id: Colorize
23
- variable: Colorize
24
- optional: Colorize
25
- short: Colorize
26
- white: Colorize
27
- }
28
-
29
- /** An object representing a space on the perimeter of a Trax position.
30
- * x,y: the coordinates of the space
31
- * c: the color present beside the space (w, b, l: both w and b, r: none)
32
- * t: the type of possible moves: n-normal, x-none, c-cave, C-restricted cave
33
- * b,w: if present, the number of the line to match with its other end
34
- * pb, pw: if present, can pair with the next line in one turn
35
- * xb, xw: the label of this space for each color
36
- */
37
- type EdgeLocation = {
38
- x: number
39
- y: number
40
- c: string
41
- t: string
42
- b?: number
43
- w?: number
44
- pb?: boolean
45
- pw?: boolean
46
- zb?: string
47
- zw?: string
48
- idx?: number
49
- }
50
-
51
- type EdgeObject = {
52
- b: string
53
- w: string
54
- edge: RawEdge
55
- }
56
-
57
- /** Object representing a concrete threat found in a position. */
58
- type FoundThreat = {
59
- threat: string
60
- match: string
61
- at: number
62
- value: number
63
- level: number
64
- }
65
-
66
- /** Threats found for each color that cannot actually be activated. */
67
- type FaultyThreats = {
68
- b: FoundThreat[]
69
- w: FoundThreat[]
70
- }
71
-
72
- /** An object with keys representing each level, with arrays for each threat of
73
- * that level. */
74
- type ColorThreats = Record<string, FoundThreat[]>
75
-
76
- /** All the threats found for both the white and black player. */
77
- type FoundThreatsCollection = { b: ColorThreats; w: ColorThreats }
78
-
79
- /** A note with a move number */
80
- type GameNote = {
81
- move: number
82
- note: string
83
- }
84
-
85
- /** Notes saved in the game object in the CLI. */
86
- type GameNotes = GameNote[]
87
-
88
- /** A point-like object has numerical x and y properties. */
89
- type PointLike = {
90
- x: number
91
- y: number
92
- }
93
-
94
- /** An object used to track an analysis on a position. */
95
- type PositionScore = {
96
- move: string
97
- score: number
98
- analysis?: Analysis
99
- }
100
-
101
- /** A puzzle. */
102
- type Puzzle = {
103
- id: string
104
- src: string
105
- game: TraxVariant
106
- notation: string
107
- icon: string
108
- level: number
109
- max: number
110
- player: number
111
- title?: string
112
- desc?: string
113
- hint?: string
114
- hints?: string[]
115
- }
116
-
117
- type PuzzleSource = {
118
- name: string
119
- url?: string
120
- copyright?: string
121
- license?: string
122
- licenseUrl?: string
123
- }
124
-
125
- /** Array of objects representing the spaces surrounding the perimeter of a
126
- * Trax position. */
127
- type RawEdge = EdgeLocation[]
128
-
129
10
  /** Treat the save state as an opaque object,
130
11
  * produced by save() and fed into restore().
131
12
  */
@@ -149,14 +30,6 @@ type SaveState = {
149
30
  */
150
31
  type Slash = '/' | '\\' | '+'
151
32
 
152
- /** Threat definition. */
153
- type Threat = {
154
- depth: number
155
- pattern: string
156
- rx: RegExp
157
- value: number
158
- }
159
-
160
33
  /** A single tile on the board. */
161
34
  type Tile = {
162
35
  id: TileId
@@ -182,5 +55,15 @@ type TileType = ValidTiles | 'x'
182
55
  /** All of the variants supported by the engine. */
183
56
  type TraxVariant = 'trax' | 'traxloop' | 'trax8'
184
57
 
185
- /** Tile types are represented by one of the following single characters. */
58
+ /** Tile type names are determined by listing the line color at each edge,
59
+ * starting from the top and going clockwise, and then sorted alphabetically
60
+ * and given a single letter name, so 'bbww' becomes 'a', which gives us six
61
+ * different tile names: a-f, as follows:
62
+ * a b c d e f
63
+ * +--#--+ +--#--+ +--#--+ +--o--+ +--o--+ +--o--+
64
+ * | # | | # | | # | | o | | o | | o |
65
+ * oo ## ooo#ooo ## oo oo ## ####### ## oo
66
+ * | o | | # | | o | | # | | o | | # |
67
+ * +--o--+ +--#--+ +--o--+ +--#--+ +--o--+ +--#--+
68
+ */
186
69
  type ValidTiles = 'a' | 'b' | 'c' | 'd' | 'e' | 'f'
package/src/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '0.20.0'
2
+ export const version = '0.22.0'
package/.dockerignore DELETED
@@ -1,11 +0,0 @@
1
- .dockerignore
2
- .git*
3
- .husky
4
- .npmignore
5
- benchmark
6
- coverage
7
- Dockerfile
8
- docs
9
- jsconfig.json
10
- node_modules
11
- test
package/.gitlab-ci.yml DELETED
@@ -1,90 +0,0 @@
1
- include:
2
- - template: Security/SAST.gitlab-ci.yml
3
- - template: Security/Secret-Detection.gitlab-ci.yml
4
-
5
- stages:
6
- - test
7
- - sast
8
- - benchmark
9
- - release
10
-
11
- sast:
12
- stage: sast
13
-
14
- nodejs-scan-sast:
15
- allow_failure: false
16
- rules:
17
- - if: "$SAST_DISABLED"
18
- when: never
19
- - if: "$SAST_EXCLUDED_ANALYZERS =~ /nodejs-scan/"
20
- when: never
21
- - if: "$CI_COMMIT_BRANCH == 'main'"
22
- exists:
23
- - "**/package.json"
24
-
25
- semgrep-sast:
26
- allow_failure: false
27
- rules:
28
- - if: "$SAST_DISABLED"
29
- when: never
30
- - if: "$SAST_EXCLUDED_ANALYZERS =~ /semgrep/"
31
- when: never
32
- - if: "$CI_COMMIT_BRANCH == 'main'"
33
- exists:
34
- - "**/*.js"
35
-
36
- secret_detection:
37
- allow_failure: false
38
-
39
- code-coverage:
40
- stage: test
41
- image: node:lts-alpine
42
- cache:
43
- key: lts
44
- paths:
45
- - node_modules/
46
- script:
47
- - node --version
48
- - npm install
49
- - npm test
50
- coverage: /^All files\s*\|\s*([\d.]+)/
51
-
52
- node16:
53
- stage: test
54
- image: node:16.15.0-alpine
55
- cache:
56
- key: node16
57
- paths:
58
- - node_modules/
59
- script:
60
- - node --version
61
- - npm install
62
- - npm test
63
-
64
- benchmark:
65
- stage: benchmark
66
- image: node:lts-alpine
67
- cache:
68
- key: lts
69
- paths:
70
- - node_modules/
71
- rules:
72
- - if: $CI_COMMIT_TAG =~ /^v\d\+\.\d+\.\d+$/
73
- script:
74
- - npm run benchmark
75
- - awk '/^## /{p++}p==1;p==2{exit}' CHANGELOG.md > RELEASE.$CI_COMMIT_TAG.md
76
- artifacts:
77
- paths:
78
- - RELEASE.$CI_COMMIT_TAG.md
79
- expire_in: 1 day
80
-
81
- release:
82
- stage: release
83
- image: registry.gitlab.com/gitlab-org/release-cli:latest
84
- rules:
85
- - if: $CI_COMMIT_TAG =~ /^v\d\+\.\d+\.\d+$/
86
- script:
87
- - echo "Releasing $CI_COMMIT_TAG"
88
- release:
89
- tag_name: $CI_COMMIT_TAG
90
- description: ./RELEASE.$CI_COMMIT_TAG.md
package/.husky/pre-commit DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname -- "$0")/_/husky.sh"
3
-
4
- npm outdated
5
- npm test
package/Dockerfile DELETED
@@ -1,14 +0,0 @@
1
- # Use the latest nodejs long-term-support release,
2
- # on the latest Alpine Linux for its small footprint
3
- FROM node:lts-alpine
4
- # Install current source code
5
- WORKDIR /trax
6
- COPY . .
7
- RUN npm install
8
- # Ensure the data files can be persisted
9
- WORKDIR /mnt/data
10
- ENV XDG_CONFIG_HOME=/mnt/data
11
- ENV XDG_DATA_HOME=/mnt/data
12
- VOLUME /mnt/data
13
- # Use the trax CLI as the starting point
14
- ENTRYPOINT ["/trax/src/cli.js"]