@slugbugblue/trax 0.3.0 → 0.3.1
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/README.md +11 -1
- package/engine.js +13 -6
- package/package.json +2 -4
- package/tty.js +7 -2
package/README.md
CHANGED
|
@@ -28,9 +28,19 @@ which can be used as follows:
|
|
|
28
28
|
```javascript
|
|
29
29
|
import Trax from '@slugbugblue/trax'
|
|
30
30
|
|
|
31
|
+
// default constructor gives you a Trax game
|
|
31
32
|
let trax = new Trax()
|
|
32
|
-
|
|
33
33
|
trax.play('@0/')
|
|
34
|
+
|
|
35
|
+
// but you can also select Loop Trax
|
|
36
|
+
let loops = new Trax('traxloop')
|
|
37
|
+
|
|
38
|
+
// or 8x8 Trax
|
|
39
|
+
let tiny = new Trax('trax8')
|
|
40
|
+
|
|
41
|
+
// and the constructor lets you start with an initial set of moves
|
|
42
|
+
let puzzle = new Trax('trax', '@0/ a0\\ @2/')
|
|
43
|
+
puzzle.play('@2\\')
|
|
34
44
|
```
|
|
35
45
|
|
|
36
46
|
Explore the file `engine.js` for more information
|
package/engine.js
CHANGED
|
@@ -208,13 +208,20 @@ const Trax = class {
|
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
possible_locations () {
|
|
211
|
-
let
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
211
|
+
let locs = { '0x0': { x:0, y:0 } } // if no tiles are placed, we can play a starting tile
|
|
212
|
+
const maybe = (x, y) => { // add a loc if a tile isn't already there
|
|
213
|
+
let loc = x + 'x' + y
|
|
214
|
+
locs[loc] = locs[loc] || { x, y }
|
|
216
215
|
}
|
|
217
|
-
|
|
216
|
+
for (let tile of Object.values(this.tiles)) {
|
|
217
|
+
locs[tile.x + 'x' + tile.y] = 'tile' // add an existing tile
|
|
218
|
+
maybe(tile.x - 1, tile.y) // and four maybe tiles around it
|
|
219
|
+
maybe(tile.x + 1, tile.y) // which will either be replaced by real tiles
|
|
220
|
+
maybe(tile.x, tile.y - 1) // or will be potentially valid locations
|
|
221
|
+
maybe(tile.x, tile.y + 1)
|
|
222
|
+
}
|
|
223
|
+
// get rid of all the real tiles and return all the maybes
|
|
224
|
+
return Object.values(locs).filter(l => l !== 'tile')
|
|
218
225
|
}
|
|
219
226
|
|
|
220
227
|
possible_moves () { // returns a list of every currently possible move
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slugbugblue/trax",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Trax game engine and friends",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"trax",
|
|
@@ -20,9 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"eslint": "8.x",
|
|
23
|
-
"tape": "5.x"
|
|
24
|
-
"typescript": "^4.5.4",
|
|
25
|
-
"typescript-language-server": "^0.8.1"
|
|
23
|
+
"tape": "5.x"
|
|
26
24
|
},
|
|
27
25
|
"type": "module",
|
|
28
26
|
"engines": {
|
package/tty.js
CHANGED
|
@@ -174,10 +174,15 @@ const display_game = (game='trax', moves='', tentative) => {
|
|
|
174
174
|
let icon = trax.icon
|
|
175
175
|
if (tentative) {
|
|
176
176
|
let drops = trax.drop_tile(tentative)
|
|
177
|
-
|
|
177
|
+
if (drops.valid) {
|
|
178
|
+
icon = trax.tentative_icon(drops)
|
|
179
|
+
} else {
|
|
180
|
+
tentative = false
|
|
181
|
+
}
|
|
178
182
|
}
|
|
179
183
|
console.info(trax.notation)
|
|
180
184
|
print_icon(icon, trax.rules)
|
|
185
|
+
if (tentative) console.info('--- tentative position ---')
|
|
181
186
|
let name = {1: 'white', 2: 'black'}[trax.turn]
|
|
182
187
|
if (trax.over) {
|
|
183
188
|
if (trax.turn) {
|
|
@@ -186,7 +191,7 @@ const display_game = (game='trax', moves='', tentative) => {
|
|
|
186
191
|
console.info('game end' + (tentative ? 's' : 'ed') + ' in a draw')
|
|
187
192
|
}
|
|
188
193
|
} else if (trax.turn) {
|
|
189
|
-
console.info((tentative ? '
|
|
194
|
+
console.info((tentative ? 'leaving ' : '') + name +' to play')
|
|
190
195
|
}
|
|
191
196
|
}
|
|
192
197
|
|