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
package/.eslintignore
ADDED
package/.eslintrc.js
ADDED
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
WIP object oriented board game engine with serializable game state for use in stateless backends
|
package/babel.config.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* eslint-env jest */
|
|
2
|
+
|
|
3
|
+
import { makeMove } from './src/index'
|
|
4
|
+
import gameRules from './tic-tac-toe-verbose.json'
|
|
5
|
+
|
|
6
|
+
describe('functional test', () => {
|
|
7
|
+
test('should load a game', () => {
|
|
8
|
+
const gameState = makeMove(gameRules)
|
|
9
|
+
expect(gameState.status).toBe('waiting')
|
|
10
|
+
})
|
|
11
|
+
test('should add players', () => {
|
|
12
|
+
let gameState = makeMove(gameRules)
|
|
13
|
+
gameState = makeMove(gameRules, gameState, { playerId: 1, type: 'join' })
|
|
14
|
+
gameState = makeMove(gameRules, gameState, { playerId: 2, type: 'join' })
|
|
15
|
+
expect(gameState.players.length).toBe(2)
|
|
16
|
+
})
|
|
17
|
+
test('should start game', () => {
|
|
18
|
+
let gameState = makeMove(gameRules)
|
|
19
|
+
gameState = makeMove(gameRules, gameState, { playerId: 1, type: 'join' })
|
|
20
|
+
gameState = makeMove(gameRules, gameState, { playerId: 2, type: 'join' })
|
|
21
|
+
gameState = makeMove(gameRules, gameState, { type: 'start' })
|
|
22
|
+
expect(gameState.status).toBe('active')
|
|
23
|
+
})
|
|
24
|
+
test('should apply move', () => {
|
|
25
|
+
let gameState = makeMove(gameRules)
|
|
26
|
+
gameState = makeMove(gameRules, gameState, { playerId: 1, type: 'join' })
|
|
27
|
+
gameState = makeMove(gameRules, gameState, { playerId: 2, type: 'join' })
|
|
28
|
+
gameState = makeMove(gameRules, gameState, { type: 'start' })
|
|
29
|
+
gameState = makeMove(
|
|
30
|
+
gameRules,
|
|
31
|
+
gameState,
|
|
32
|
+
{
|
|
33
|
+
playerId: 1,
|
|
34
|
+
type: 'movePiece',
|
|
35
|
+
board: {
|
|
36
|
+
id: gameState.sharedBoard.grid.id
|
|
37
|
+
},
|
|
38
|
+
target: [
|
|
39
|
+
0,
|
|
40
|
+
2
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
expect(gameState.sharedBoard.grid.grid[0][2].pieces.length).toBe(1)
|
|
45
|
+
})
|
|
46
|
+
})
|