@slugbugblue/trax 0.19.0 → 0.21.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/.dockerignore ADDED
@@ -0,0 +1,11 @@
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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @slugbugblue/trax
2
2
 
3
+ ## 0.21.0 -2023-03-12
4
+
5
+ - Update the analysis engine to be more lazy
6
+
7
+ - Call `validateThreats()` to make it work harder
8
+ - This also increases LRU cache hits
9
+ - This makes the suggestions much faster because it skips validations for
10
+ low-scoring moves
11
+
12
+ ## 0.20.0 - 2023-02-11
13
+
14
+ - Provide timing feedback on the puzzlebot's actions
15
+ - Add license information for puzzle sources
16
+ - Add gitlab CI configuration
17
+ - Drop support for node 14; node v16.15 is our minimum supported version
18
+ - More puzzles from Martin M. S. Pedersen -- bringing the total to 100+
19
+ - Enhance the docker configuration and document it in the README
20
+ - Refine faulty threat detection and add test for once case it was failing
21
+
3
22
  ## 0.19.0 - 2023-02-06
4
23
 
5
24
  - Added a simple LRU cache to increase the efficiency of the analysis engine
@@ -0,0 +1,113 @@
1
+ # Contributing to slugbugblue/trax
2
+
3
+ Hi, thanks for considering contributing to this project.
4
+
5
+ If this is your first time working on an open source project, it is recommended
6
+ that you start by reading [How to Contribute to Open Source][howto].
7
+
8
+ ## Ways to contribute
9
+
10
+ ### Improve documentation
11
+
12
+ One of the simplest ways to get started contributing is to find areas of the
13
+ documentation that are unclear, incorrect, or that have typos or other errors,
14
+ and providing feedback and corrections. You don't have to know how to code or
15
+ even how to use git.
16
+
17
+ ### Identify bugs
18
+
19
+ If you are aware of something not working as you think it should, feel free to
20
+ open a new issue to let us know. Browsing through the existing open issues and
21
+ adding comments or making clarifications can also be a great way to get started.
22
+
23
+ ### Fixing bugs
24
+
25
+ If you feel you have a solution to an existing bug, you are welcome to code up
26
+ your solution and submit a merge request. It may take some time to get fully up
27
+ to speed with our coding styles and with the structure of the code, so don't
28
+ feel bad if your merge request receives comments rather than being immediately
29
+ accepted. Simply make any necessary changes, and update the merge request, or
30
+ let us know in a subsequent comment if you think we are misunderstanding the
31
+ merge request.
32
+
33
+ ## Submitting an issue
34
+
35
+ If you choose to submit an issue, please take the time to ensure that you
36
+ provide as much detail as possible about the issue. A poorly worded or poorly
37
+ researched issue report will unnecessarily delay the issue resolution.
38
+
39
+ Even if you don't have the time or expertise to fully diagnose the problem, a
40
+ good issue report can be very helpful to us as we seek to improve the code.
41
+
42
+ ## Submitting a merge request
43
+
44
+ Good merge requests are a fantastic way to contribute to this project. Your
45
+ merge request is going to be accepted more quickly if it is easy to understand.
46
+ Ideally it should be focused on a single item and avoid unrelated commits.
47
+
48
+ Please ask first before embarking on a major change, such as adding a new
49
+ feature or refactoring the code, otherwise you risk spending a significant
50
+ amount of time working on something that will not be merged into the project.
51
+
52
+ If you have never submitted a merge request before, no fear. Here is a [quick
53
+ tutorial][howto-mr] on how to create one.
54
+
55
+ ### Merge request steps
56
+
57
+ - Fork the project and clone it to your own workspace.
58
+ - Get the latest changes and update the project dependencies:
59
+
60
+ ```bash
61
+ $ git checkout develop
62
+ $ git pull upstream develop
63
+ $ rm -rf node_modules
64
+ $ npm install
65
+ ```
66
+
67
+ - Create a new branch to contain your changes:
68
+
69
+ ```bash
70
+ $ git checkout -b <new-branch-name>
71
+ ```
72
+
73
+ - Make your changes.
74
+ - Test your changes.
75
+
76
+ ```bash
77
+ $ npm test
78
+ ```
79
+
80
+ - Push your changes back to your fork.
81
+
82
+ ```bash
83
+ $ git push -u origin <new-branch-name>
84
+ ```
85
+
86
+ 1. Open a merge request in the [slugbugblue/trax][trax-repo] repo.
87
+
88
+ ## Working with the code
89
+
90
+ This repository uses [XO][xo] for linting and [Prettier][prettier] for
91
+ formatting. Running `npm test` will produce an error if your changes do not
92
+ conform. You should consider installing the [XO plugin][xo-plugin] for your
93
+ editor to have the linting errors highlighted for you and automatically fixed on
94
+ save. You can also run `npx xo --fix` from the command line to fix most linting
95
+ errors.
96
+
97
+ This repository uses [AVA][ava] for writing and running tests. While we want as
98
+ much code coverage as possible for all code, we have a minimum requirement of
99
+ 95% of code coverage for the [analysis engine][analyst] and 100% for the [main
100
+ trax engine][engine]. You should be able to get a quick grasp on the testing
101
+ process by simply examining a few of the test files in the [test
102
+ directory][test].
103
+
104
+ [analyst]: src/analyst.js
105
+ [ava]: https://github.com/avajs/ava
106
+ [engine]: src/engine.js
107
+ [howto]: https://opensource.guide/how-to-contribute/
108
+ [howto-mr]: https://opensource.guide/how-to-contribute/#opening-a-pull-request
109
+ [prettier]: https://prettier.io
110
+ [test]: test/
111
+ [trax-repo]: https://gitlab.com/slugbugblue/trax
112
+ [xo]: https://github.com/sidresorhus/xo
113
+ [xo-plugin]: https://github.com/sidresorhus/xo#editor-plugins
package/Dockerfile CHANGED
@@ -1,9 +1,14 @@
1
1
  # Use the latest nodejs long-term-support release,
2
2
  # on the latest Alpine Linux for its small footprint
3
3
  FROM node:lts-alpine
4
- # Install current source code globally
5
- COPY . /src
6
- WORKDIR /src
7
- RUN npm install -g @slugbugblue/trax
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
8
13
  # Use the trax CLI as the starting point
9
- ENTRYPOINT ["/usr/local/bin/trax"]
14
+ ENTRYPOINT ["/trax/src/cli.js"]
package/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2021 Chad Transtrum
189
+ Copyright © 2021-2023 Chad Transtrum
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -4,7 +4,7 @@ This project aims to provide tools for working with Trax games in Javascript.
4
4
 
5
5
  - Trax game-playing engine
6
6
  - Position analysis engine
7
- - Over 60 puzzles to help hone your Trax skills
7
+ - Over 100 puzzles to help hone your Trax skills
8
8
  - Command-line interface for ease of use
9
9
 
10
10
  ## Description
@@ -23,20 +23,47 @@ changes to the engine should meet the same standard.
23
23
 
24
24
  ## Installation
25
25
 
26
+ Installation can be done in one of three ways, each for a slightly different
27
+ purpose.
28
+
29
+ If you want to use this code in your own javascript project:
30
+
26
31
  ```bash
27
- # Install into a javascript project
28
32
  npm install @slugbugblue/trax
33
+ ```
34
+
35
+ If you want to use the trax CLI on your computer:
29
36
 
30
- # Or install globally to use the trax CLI more easily
37
+ ```bash
31
38
  npm install -g @slugbugblue/trax
32
39
  ```
33
40
 
41
+ If you don't have node installed and want to use the CLI as a docker container:
42
+
43
+ ```bash
44
+ git clone https://gitlab.com/slugbugblue/trax.git ~/trax
45
+ docker build -t trax ~/trax
46
+ ```
47
+
34
48
  ## CLI Usage
35
49
 
36
50
  The command-line interface is provided as `trax`, available in your path if
37
51
  installed globally, or in the `node_modules/.bin` directory and runnable using
38
52
  `npx trax` if installed locally.
39
53
 
54
+ > If you installed by creating a Docker image, use the following command to
55
+ > launch the CLI:
56
+ >
57
+ > - `docker run --name trax -itv $HOME/trax:/mnt/data --rm trax`
58
+ >
59
+ > Since that's a bit much to type, it's recommended to create an alias in one of
60
+ > your startup scripts:
61
+ >
62
+ > - `alias trax="docker run --name trax -itv $HOME/trax:/mnt/data --rm trax"`
63
+ >
64
+ > Then you can launch the docker container simply by typing in `trax`, the same
65
+ > as if it were installed globally.
66
+
40
67
  The CLI can be used interactively by running the command with no parameters or
41
68
  by passing the `--interactive` or `-i` flag. When run interactively, you can
42
69
  avoid worries about the need to escape certain characters from the shell, and it
@@ -59,7 +86,7 @@ entered `play 1. @0/`.
59
86
  Multiple games can be started at once, and the CLI will remember the currently
60
87
  active game and apply future actions to that game. Each game will retain its
61
88
  `#id` number until it is deleted, and you can use that number to switch between
62
- games. For example, to make game #1 active, enter `select 1` or `select #1` or
89
+ games. For example, to make game \#1 active, enter `select 1` or `select #1` or
63
90
  simply `#1` at the interactive prompt.
64
91
 
65
92
  For ease of working at the command line, the symbols used as the last character
@@ -68,11 +95,7 @@ symbol (`/`), `b` for backslash (`\`), and `p` for plus (`+`). While there is no
68
95
  need to escape at the interactive prompt, these substitutions will be avilable
69
96
  there as well.
70
97
 
71
- The CLI uses standard Windows and Linux [XDG][xdg] file locations as provided by
72
- the [env-paths library][env-path], with current uses being the `config` and
73
- `data` folders.
74
-
75
- Examples:
98
+ ### Examples
76
99
 
77
100
  ```text
78
101
  # Start a new Trax game with Chad playing as white
@@ -99,6 +122,18 @@ Examples:
99
122
  > trax ls
100
123
  ```
101
124
 
125
+ ### Environment variables
126
+
127
+ The CLI uses standard Windows and Linux [XDG][xdg] file locations as provided by
128
+ the [env-paths library][env-path], with current uses being user-specific
129
+ `config` (`XDG_CONFIG_HOME`) and `data` (`XDG_DATA_HOME`) folders.
130
+
131
+ In addition, the CLI recognizes several environment variables to determine the
132
+ glyphs to use in the user interface. Setting either `NERDFONT` or `NERDFONTS` to
133
+ any non-empty string will use characters from [Nerdfonts][nerfont]. Otherwise,
134
+ any of `POWERLINE`, `P9K_TTY`, or `P9K_SSH` will use characters from [Powerline
135
+ fonts][powerline].
136
+
102
137
  ## API Usage
103
138
 
104
139
  ### Trax engine
@@ -161,6 +196,8 @@ traxgame.com puzzles page][traxpuzzles], and [puzzles curated][puzzlebook] by
161
196
  ## Roadmap
162
197
 
163
198
  - Improve the threats database / analysis engine.
199
+ - Bot should be able to win all puzzles.
200
+ - Analysis should recognize line threats.
164
201
  - Add more puzzles.
165
202
 
166
203
  ## Support
@@ -170,8 +207,8 @@ Issues can be opened on the [gitlab project page][repo].
170
207
 
171
208
  ## Contributing
172
209
 
173
- Contributions are welcome. Ideally in the form of pull requests, but feel free
174
- to open an issue with a bug report or a suggestion as well.
210
+ [Contributions are welcome][contributing]. Ideally in the form of pull requests,
211
+ but feel free to open an issue with a bug report or a suggestion as well.
175
212
 
176
213
  ## Acknowledgments
177
214
 
@@ -188,10 +225,9 @@ always ready to share his insights on the mechanics of the game, as well as
188
225
  various approaches to encoding its complexities. His undeserved kindness and
189
226
  infinite patience in indulging my many questions can never be repaid.
190
227
 
191
- Thanks for [Martin M. S. Pedersen][traxplayer] for contributing ideas, code, and
192
- puzzles to this effort. He's been [curating Trax puzzles][puzzlebook] and
193
- [coding solutions for Trax][gnutrax] for over two decades, and brings a lot of
194
- expertise.
228
+ Thanks to [Martin M. S. Pedersen][traxplayer] for contributing ideas, code, and
229
+ puzzles. He's been [curating Trax puzzles][puzzlebook] and [coding solutions for
230
+ Trax][gnutrax] for over two decades, and brings a lot of expertise.
195
231
 
196
232
  ## License
197
233
 
@@ -218,6 +254,7 @@ The official rules for Trax are found at http://traxgame.com/about_rules.php.
218
254
  As Trax is a proprietary game, these rules are the intellectual property of
219
255
  David Smith and heirs, and are not to be used without permission.
220
256
 
257
+ [contributing]: CONTRIBUTING.md
221
258
  [ctrans]: mailto:chad@transtrum.net
222
259
  [dgb]: mailto:donald@traxgame.com
223
260
  [docs-engine]: docs/engine.md
@@ -225,6 +262,8 @@ David Smith and heirs, and are not to be used without permission.
225
262
  [env-path]: https://www.npmjs.com/package/env-paths
226
263
  [gnutrax]: https://gnutrax.com
227
264
  [goldtoken]: https://goldtoken.com/
265
+ [nerdfont]: https://nerdfonts.com/
266
+ [powerline]: https://github.com/powerline/fonts
228
267
  [puzzlebook]: https://gnutrax.com/book
229
268
  [repo]: https://gitlab.com/slugbugblue/trax
230
269
  [sbb]: https://slugbugblue.com/
package/docs/analyst.md CHANGED
@@ -104,10 +104,12 @@ so that it appears as though all black tiles are white tiles.
104
104
  Analyzes the existing threats for the current game position. Returns an object
105
105
  with both `b` and `w` keys, where each is an object with zero or more "depth"
106
106
  keys. Threats of depth 0 are corners or connectable-pairs. Threats of depth 1
107
- are immediate attacks. Threats of depth 2 are Ls. etc. Note that the threats are
108
- not checked for faultiness at this time. In other words, there may be a faulty L
109
- listed as a threat even if it is not currently possible to activate the L
110
- successfully.
107
+ are immediate attacks. Threats of depth 2 are Ls. etc.
108
+
109
+ Note that the threats are not checked for faultiness at this time. In other
110
+ words, there may be a faulty L listed as a threat even if it is not currently
111
+ possible to activate the L successfully. To ensure that the listed threats are
112
+ valid, use the `validateThreats()` method call.
111
113
 
112
114
  The "depth" keys are arrays of the threats at that level, which means that a
113
115
  simple count of the threats at each level can give a good first guess at the
@@ -119,11 +121,23 @@ following keys:
119
121
  - `match`: The portion of the actual edge string that matched the pattern, which
120
122
  may or may not be exactly the same as the pattern.
121
123
  - `at`: The index of the edge string at which the pattern match began.
124
+ - `value`: The multiplier for this threat. Most often this is `1`, but some
125
+ threats can be re-formed, and this will be `2` in those cases.
122
126
 
123
127
  ##### `faulty`
124
128
 
125
- Contains the same information as `threats` but for removed threats that were
126
- found to be faulty.
129
+ An object with two keys, `w` and `b`, each of which is a list of threats that
130
+ were found to be faulty. This object will be empty if `validateThreats()` has
131
+ not yet been called.
132
+
133
+ Example data:
134
+
135
+ ```javascript
136
+ {
137
+ w: [{ threat: 'Arw?!pW', match: 'arwpa', at: 1, level: 2, value: 1 }],
138
+ b: [],
139
+ }
140
+ ```
127
141
 
128
142
  ##### `score`
129
143
 
@@ -164,6 +178,12 @@ For any given location, determine the type of playable space. Returns one of:
164
178
  - `C`: This location is in a cave, and certain plays at this position result in
165
179
  illegal moves.
166
180
 
181
+ ##### `validateThreats()`
182
+
183
+ Ensure that all of the threats that are present for each color are actually
184
+ valid. If it finds any faulty threats, it will update the `score` and populate
185
+ the `faulty` property with each threat that was found to be invalid.
186
+
167
187
  ### Suggestion class
168
188
 
169
189
  Accessible from `suggest(game)`, this class is returned with several useful
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slugbugblue/trax",
3
- "version": "0.19.0",
3
+ "version": "0.21.0",
4
4
  "description": "Trax game engine and friends",
5
5
  "keywords": [
6
6
  "trax",
@@ -20,6 +20,7 @@
20
20
  "./puzzles": "./src/puzzles.js",
21
21
  "./threats": "./src/threats.js",
22
22
  "./tty": "./src/tty.js",
23
+ "./utils": "./src/utils.js",
23
24
  "./version": "./src/version.js"
24
25
  },
25
26
  "repository": "gitlab:slugbugblue/trax",
@@ -28,10 +29,12 @@
28
29
  },
29
30
  "scripts": {
30
31
  "benchmark": "node benchmark/puzzles.bench.js",
32
+ "genversion": "genversion --es6 src/version.js",
33
+ "git-add": "git add src/version.js benchmark/benchmarks.json",
31
34
  "test": "xo && c8 ava",
32
35
  "prepare": "husky install",
33
36
  "preversion": "npm test",
34
- "version": "genversion --es6 src/version.js && npm run benchmark || git add src/version.js benchmark/benchmarks.json",
37
+ "version": "npm run genversion ; npm run benchmark ; npm run git-add",
35
38
  "postversion": "git push && git push --tags && npm publish"
36
39
  },
37
40
  "dependencies": {
@@ -49,7 +52,14 @@
49
52
  },
50
53
  "type": "module",
51
54
  "engines": {
52
- "node": "^14.14.0 || >=16.0.0"
55
+ "node": ">=16.15.0"
56
+ },
57
+ "c8": {
58
+ "branches": 95,
59
+ "check-coverage": true,
60
+ "functions": 95,
61
+ "lines": 95,
62
+ "statements": 95
53
63
  },
54
64
  "prettier": {
55
65
  "bracketSpacing": true,