@slugbugblue/trax 0.18.0 → 0.20.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/.gitlab-ci.yml ADDED
@@ -0,0 +1,90 @@
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 CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env sh
2
2
  . "$(dirname -- "$0")/_/husky.sh"
3
3
 
4
+ npm outdated
4
5
  npm test
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @slugbugblue/trax
2
2
 
3
+ ## 0.20.0 - 2023-02-11
4
+
5
+ - Provide timing feedback on the puzzlebot's actions
6
+ - Add license information for puzzle sources
7
+ - Add gitlab CI configuration
8
+ - Drop support for node 14; node v16.15 is our minimum supported version
9
+ - More puzzles from Martin M. S. Pedersen -- bringing the total to 100+
10
+ - Enhance the docker configuration and document it in the README
11
+ - Refine faulty threat detection and add test for once case it was failing
12
+
13
+ ## 0.19.0 - 2023-02-06
14
+
15
+ - Added a simple LRU cache to increase the efficiency of the analysis engine
16
+
3
17
  ## 0.18.0 - 2023-02-05
4
18
 
5
19
  - Analysis improvements:
@@ -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,5 +1,14 @@
1
- FROM node:19.5.0-slim
2
- COPY . /src
3
- WORKDIR /src
4
- RUN npm install -g @slugbugblue/trax
5
- ENTRYPOINT ["/usr/local/bin/trax"]
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"]
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 50 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
@@ -29,6 +29,9 @@ npm install @slugbugblue/trax
29
29
 
30
30
  # Or install globally to use the trax CLI more easily
31
31
  npm install -g @slugbugblue/trax
32
+
33
+ # Or create a docker image
34
+ docker build -t trax .
32
35
  ```
33
36
 
34
37
  ## CLI Usage
@@ -37,6 +40,19 @@ The command-line interface is provided as `trax`, available in your path if
37
40
  installed globally, or in the `node_modules/.bin` directory and runnable using
38
41
  `npx trax` if installed locally.
39
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
+
40
56
  The CLI can be used interactively by running the command with no parameters or
41
57
  by passing the `--interactive` or `-i` flag. When run interactively, you can
42
58
  avoid worries about the need to escape certain characters from the shell, and it
@@ -153,13 +169,16 @@ threats.
153
169
 
154
170
  ### Puzzles database
155
171
 
156
- The puzzles database is provided in `puzzles.js`, and so far just contains
157
- puzzles that I've been using to test the analysis engine, along with the list of
158
- publicly available puzzles at [the traxgame.com puzzles page][traxpuzzles].
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].
159
176
 
160
177
  ## Roadmap
161
178
 
162
179
  - Improve the threats database / analysis engine.
180
+ - Bot should be able to win all puzzles.
181
+ - Analysis should recognize line threats.
163
182
  - Add more puzzles.
164
183
 
165
184
  ## Support
@@ -169,8 +188,8 @@ Issues can be opened on the [gitlab project page][repo].
169
188
 
170
189
  ## Contributing
171
190
 
172
- Contributions are welcome. Ideally in the form of pull requests, but feel free
173
- to open an issue with a bug report or a suggestion as well.
191
+ [Contributions are welcome][contributing]. Ideally in the form of pull requests,
192
+ but feel free to open an issue with a bug report or a suggestion as well.
174
193
 
175
194
  ## Acknowledgments
176
195
 
@@ -187,10 +206,9 @@ always ready to share his insights on the mechanics of the game, as well as
187
206
  various approaches to encoding its complexities. His undeserved kindness and
188
207
  infinite patience in indulging my many questions can never be repaid.
189
208
 
190
- Thanks for [Martin M. S. Pedersen][traxplayer] for contributing ideas, code, and
191
- puzzles to this effort. He's been [curating Trax puzzles][puzzlebook] and
192
- [coding solutions for Trax][gnutrax] for over two decades, and brings a lot of
193
- expertise.
209
+ Thanks to [Martin M. S. Pedersen][traxplayer] for contributing ideas, code, and
210
+ 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.
194
212
 
195
213
  ## License
196
214
 
@@ -217,6 +235,7 @@ The official rules for Trax are found at http://traxgame.com/about_rules.php.
217
235
  As Trax is a proprietary game, these rules are the intellectual property of
218
236
  David Smith and heirs, and are not to be used without permission.
219
237
 
238
+ [contributing]: CONTRIBUTING.md
220
239
  [ctrans]: mailto:chad@transtrum.net
221
240
  [dgb]: mailto:donald@traxgame.com
222
241
  [docs-engine]: docs/engine.md
package/docs/analyst.md CHANGED
@@ -119,11 +119,22 @@ following keys:
119
119
  - `match`: The portion of the actual edge string that matched the pattern, which
120
120
  may or may not be exactly the same as the pattern.
121
121
  - `at`: The index of the edge string at which the pattern match began.
122
+ - `value`: The multiplier for this threat. Most often this is `1`, but some
123
+ threats can be re-formed, and this will be `2` in those cases.
122
124
 
123
125
  ##### `faulty`
124
126
 
125
- Contains the same information as `threats` but for removed threats that were
126
- found to be faulty.
127
+ An object with two keys, `w` and `b`, each of which is a list of threats that
128
+ were found to be fauly.
129
+
130
+ Example data:
131
+
132
+ ```javascript
133
+ {
134
+ w: [{ threat: 'Arw?!pW', match: 'arwpa', at: 1, level: 2, value: 1 }],
135
+ b: [],
136
+ }
137
+ ```
127
138
 
128
139
  ##### `score`
129
140
 
package/docs/lru.md ADDED
@@ -0,0 +1,151 @@
1
+ # lru.js API documentation
2
+
3
+ This module provides a simple Least Recently Used cache.
4
+
5
+ Internally, this uses a Map, which give us insertion-ordering for free. The
6
+ first item in the list is the oldest. The last item is the most recently set or
7
+ accessed. Most of the base functionality of the Map are replicated.
8
+
9
+ Since I don't need it to be super fancy, there isn't a lot of extra
10
+ functionality here.
11
+
12
+ ## Example usage
13
+
14
+ ```javascript
15
+ import { LRU } from '@slugbugblue/trax/lru.js'
16
+
17
+ const cache = new LRU(100)
18
+
19
+ cache.set('a', 1)
20
+ cache.set('b', 2)
21
+
22
+ // Get an item from the cache
23
+ console.log(cache.get('a')) // 1
24
+
25
+ // Accessing a key makes it the most recent:
26
+ console.log(cache.keys()) // [Map Iterator] { 'b', 'a' }
27
+ console.log(cache.hits) // 1
28
+
29
+ console.log(cache.get('z')) // undefined
30
+ console.log(cache.misses) // 1
31
+
32
+ console.log(cache.size) // 2
33
+ console.log(cache.capacity) // 100
34
+ ```
35
+
36
+ ## API
37
+
38
+ ### LRU class
39
+
40
+ An LRU cache is a way to remember a limited set of items, with the oldest
41
+ expiring when the capacity is reached.
42
+
43
+ #### constructor
44
+
45
+ ##### `new LRU(capacity)`
46
+
47
+ Create the cache by specifying the maximum number of items it should hold.
48
+
49
+ #### computed properties
50
+
51
+ ##### `capacity`
52
+
53
+ The maximum number of items the cache can hold. This cannot be changed after the
54
+ cache creation.
55
+
56
+ ##### `size`
57
+
58
+ The number of items currently stored in the cache.
59
+
60
+ ##### `hits`
61
+
62
+ The number of times a `get` call has found an item in the cache.
63
+
64
+ ##### `misses`
65
+
66
+ The number of times a `get` call has not found an item in the cache.
67
+
68
+ ##### `expired`
69
+
70
+ The number of times an item has been removed from the cache.
71
+
72
+ #### methods
73
+
74
+ ##### `get(key)`
75
+
76
+ Retrieve an item from the cache. If the item is found in the cache, `hits` will
77
+ be updated, the item will be marked as the most-recently-used item, and the
78
+ value will be returned. If the item is not present in the cache, `misses` will
79
+ be updated, and `undefined` will be returned.
80
+
81
+ Note that if you had stored `undefined` as the value in the cache, the return of
82
+ `undefined` doesn't necessarily represent a cache miss.
83
+
84
+ ##### `peek(key)`
85
+
86
+ Retrieve an item from the cache, if present, but without updating any of the
87
+ LRU-specific information about the retrieval attempt. The item's age will not be
88
+ updated. If the item is not present in the cache, `undefined` will be returned.
89
+
90
+ ##### `set(key, value)`
91
+
92
+ Store an item in the cache. If the item is already present in the cache, it will
93
+ be replaced and marked as the most-recently-used item.
94
+
95
+ ##### `delete(key)`
96
+
97
+ Remove an item from the cache.
98
+
99
+ ##### `clear()`
100
+
101
+ Clears all items and statistics from the cache. The maximum capacity will not
102
+ change.
103
+
104
+ ##### `entries()`
105
+
106
+ Returns an iterator that operates over all the \[key, value\] pairs stored in
107
+ the cache. The entries will be in order from oldest to newest.
108
+
109
+ ##### `has(key)`
110
+
111
+ Returns true if a key is found in the cache, false otherwise.
112
+
113
+ ##### `keys()`
114
+
115
+ Returns an iterator that operates over all the keys stored in the cache. The
116
+ keys will be returned oldest first, newest last.
117
+
118
+ ##### `values()`
119
+
120
+ Returns an iterator that operates over all the values stored in the cache. The
121
+ values will be returned oldest first, newest last.
122
+
123
+ #### Plays well with others
124
+
125
+ The LRU class also includes functionality to provide useful default results when
126
+ used in other contexts.
127
+
128
+ ##### `toString()`
129
+
130
+ Returns a string representation of the cache in the format `LRU(75 of 1000)`.
131
+ This allows simple logging calls with `console.log(cache)`.
132
+
133
+ ##### `util.inspect.custom()`
134
+
135
+ When running in the node command line interpreter, an LRU cache instance will be
136
+ pretty-printed using the magic of `util.inspect`.
137
+
138
+ ## License
139
+
140
+ Copyright 2023 Chad Transtrum
141
+
142
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
143
+ the files in this project except in compliance with the License. You may obtain
144
+ a copy of the License at
145
+
146
+ http://www.apache.org/licenses/LICENSE-2.0
147
+
148
+ Unless required by applicable law or agreed to in writing, software distributed
149
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
150
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
151
+ specific language governing permissions and limitations under the License.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slugbugblue/trax",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "description": "Trax game engine and friends",
5
5
  "keywords": [
6
6
  "trax",
@@ -14,11 +14,13 @@
14
14
  "types": "./src/types.d.ts",
15
15
  "exports": {
16
16
  ".": "./src/engine.js",
17
- "./point": "./src/point.js",
18
17
  "./analyst": "./src/analyst.js",
18
+ "./lru": "./src/lru.js",
19
+ "./point": "./src/point.js",
19
20
  "./puzzles": "./src/puzzles.js",
20
21
  "./threats": "./src/threats.js",
21
22
  "./tty": "./src/tty.js",
23
+ "./utils": "./src/utils.js",
22
24
  "./version": "./src/version.js"
23
25
  },
24
26
  "repository": "gitlab:slugbugblue/trax",
@@ -27,10 +29,12 @@
27
29
  },
28
30
  "scripts": {
29
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",
30
34
  "test": "xo && c8 ava",
31
35
  "prepare": "husky install",
32
36
  "preversion": "npm test",
33
- "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",
34
38
  "postversion": "git push && git push --tags && npm publish"
35
39
  },
36
40
  "dependencies": {
@@ -48,7 +52,14 @@
48
52
  },
49
53
  "type": "module",
50
54
  "engines": {
51
- "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
52
63
  },
53
64
  "prettier": {
54
65
  "bracketSpacing": true,