board-game-engine 0.0.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/.eslintignore +2 -0
- package/.eslintrc.js +3 -0
- package/README.md +1 -0
- package/babel.config.js +6 -0
- package/board-game-engine.test.js +46 -0
- package/dist/board-game-engine.js +7037 -0
- package/dist/board-game-engine.min.js +1 -0
- package/jest.config.js +21 -0
- package/package.json +40 -0
- package/src/action/action-factory.js +13 -0
- package/src/action/action.js +34 -0
- package/src/action/move-piece-action.js +11 -0
- package/src/action/select-piece-action.js +23 -0
- package/src/action/swap-action.js +14 -0
- package/src/board/board-factory.js +12 -0
- package/src/board/board-group.js +9 -0
- package/src/board/board.js +11 -0
- package/src/board/grid.js +52 -0
- package/src/board/stack.js +16 -0
- package/src/condition/action-type-matches-condition.js +7 -0
- package/src/condition/bingo-condition.js +50 -0
- package/src/condition/blackout-condition.js +9 -0
- package/src/condition/condition-factory.js +31 -0
- package/src/condition/condition.js +9 -0
- package/src/condition/contains-condition.js +14 -0
- package/src/condition/does-not-contain-condition.js +15 -0
- package/src/condition/is-valid-player-condition.js +7 -0
- package/src/condition/piece-matches-condition.js +23 -0
- package/src/condition/relative-move-condition.js +16 -0
- package/src/condition/some-condition.js +7 -0
- package/src/game/game.ts +362 -0
- package/src/index.ts +1 -0
- package/src/piece/piece-factory.js +5 -0
- package/src/piece/piece.ts +25 -0
- package/src/piece/pile.js +70 -0
- package/src/player/player.ts +13 -0
- package/src/registry.ts +51 -0
- package/src/round/round-factory.js +7 -0
- package/src/round/round.js +41 -0
- package/src/round/sequential-player-turn.js +18 -0
- package/src/space/space.ts +22 -0
- package/src/utils/find-value-path.js +37 -0
- package/src/utils/resolve-board.ts +38 -0
- package/src/utils/resolve-piece.ts +43 -0
- package/tic-tac-toe-verbose.json +54 -0
- package/webpack.config.js +49 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import Pile from "../piece/pile.js";
|
|
2
|
+
|
|
3
|
+
export default function resolvePiece(piece, gameState) {
|
|
4
|
+
// todo: should not be specific to grids
|
|
5
|
+
if (piece?.id) {
|
|
6
|
+
const queue = [gameState.sharedBoard, gameState.personalBoards];
|
|
7
|
+
while (queue.length) {
|
|
8
|
+
const node = queue.pop();
|
|
9
|
+
if (!node) continue;
|
|
10
|
+
|
|
11
|
+
if (Array.isArray(node)) {
|
|
12
|
+
queue.push(...node);
|
|
13
|
+
} else if (node.grid) {
|
|
14
|
+
for (const row of node.grid) queue.push(...row);
|
|
15
|
+
} else if (node.coordinates && node.pieces) {
|
|
16
|
+
const found = node.pieces.find((p) => p.id === piece.id);
|
|
17
|
+
if (found) return found;
|
|
18
|
+
} else if (typeof node === "object") {
|
|
19
|
+
queue.push(...Object.values(node));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null; // piece.id was given but not found
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let pieceGroup
|
|
26
|
+
if (!piece) {
|
|
27
|
+
pieceGroup = gameState.pieces.find(
|
|
28
|
+
(p) =>
|
|
29
|
+
p.name === 'playerMarker' &&
|
|
30
|
+
(!p.player || p.player.id === gameState.players[gameState.currentRound.currentPlayerIndex].id)
|
|
31
|
+
);
|
|
32
|
+
} else {
|
|
33
|
+
pieceGroup = gameState.pieces.find(
|
|
34
|
+
(p) =>
|
|
35
|
+
p.name === piece.name &&
|
|
36
|
+
(!p.player || p.player.id === piece.player?.id)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
if (!pieceGroup) {
|
|
40
|
+
throw new Error(`No piece group found for ${piece.name}`);
|
|
41
|
+
}
|
|
42
|
+
return pieceGroup.getOne();
|
|
43
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"playerCountRange": [2, 2],
|
|
3
|
+
"sharedBoard": {
|
|
4
|
+
"grid": {
|
|
5
|
+
"type": "grid",
|
|
6
|
+
"width": 3,
|
|
7
|
+
"height": 3
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
"pieces": [
|
|
11
|
+
{
|
|
12
|
+
"name": "playerMarker",
|
|
13
|
+
"perPlayer": true
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"winCondition": {
|
|
17
|
+
"type": "bingo",
|
|
18
|
+
"boardPath": ["sharedBoard", "grid"],
|
|
19
|
+
"piece": {
|
|
20
|
+
"name": "playerMarker"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"round": {
|
|
24
|
+
"loopUntil": false,
|
|
25
|
+
"phases": [
|
|
26
|
+
{
|
|
27
|
+
"type": "sequentialPlayerTurn",
|
|
28
|
+
"actions": [
|
|
29
|
+
{
|
|
30
|
+
"type": "movePiece",
|
|
31
|
+
"piece": {
|
|
32
|
+
"name": "playerMarker"
|
|
33
|
+
},
|
|
34
|
+
"from": "player",
|
|
35
|
+
"to": ["sharedBoard", "grid"],
|
|
36
|
+
"conditions": [
|
|
37
|
+
{
|
|
38
|
+
"type": "doesNotContain",
|
|
39
|
+
"piece": "any"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
"drawCondition": {
|
|
48
|
+
"type": "blackout",
|
|
49
|
+
"boardPath": ["sharedBoard", "grid"],
|
|
50
|
+
"piece": {
|
|
51
|
+
"name": "playerMarker"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const common = {
|
|
2
|
+
mode: 'production',
|
|
3
|
+
entry: './src/index.ts',
|
|
4
|
+
output: {
|
|
5
|
+
filename: 'board-game-engine.min.js',
|
|
6
|
+
library: {
|
|
7
|
+
name: 'BoardGameEngine',
|
|
8
|
+
type: 'umd'
|
|
9
|
+
},
|
|
10
|
+
globalObject: 'this'
|
|
11
|
+
},
|
|
12
|
+
module: {
|
|
13
|
+
rules: [{
|
|
14
|
+
test: /\.(js|ts)$/,
|
|
15
|
+
exclude: /node_modules\/(?!@mnbroatch).+/,
|
|
16
|
+
use: {
|
|
17
|
+
loader: 'babel-loader',
|
|
18
|
+
options: {
|
|
19
|
+
presets: [
|
|
20
|
+
'@babel/preset-typescript',
|
|
21
|
+
['@babel/preset-env',
|
|
22
|
+
{
|
|
23
|
+
modules: 'cjs',
|
|
24
|
+
targets: 'last 4 years'
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
],
|
|
28
|
+
plugins: ['add-module-exports']
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}]
|
|
32
|
+
},
|
|
33
|
+
resolve: { extensions: [".js",".ts",".tsx",".jsx",".json"] },
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = [
|
|
37
|
+
common,
|
|
38
|
+
{
|
|
39
|
+
...common,
|
|
40
|
+
output: {
|
|
41
|
+
...common.output,
|
|
42
|
+
filename: 'board-game-engine.js'
|
|
43
|
+
},
|
|
44
|
+
optimization: {
|
|
45
|
+
...common.optimization,
|
|
46
|
+
minimize: false
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
]
|