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.
Files changed (46) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.js +3 -0
  3. package/README.md +1 -0
  4. package/babel.config.js +6 -0
  5. package/board-game-engine.test.js +46 -0
  6. package/dist/board-game-engine.js +7037 -0
  7. package/dist/board-game-engine.min.js +1 -0
  8. package/jest.config.js +21 -0
  9. package/package.json +40 -0
  10. package/src/action/action-factory.js +13 -0
  11. package/src/action/action.js +34 -0
  12. package/src/action/move-piece-action.js +11 -0
  13. package/src/action/select-piece-action.js +23 -0
  14. package/src/action/swap-action.js +14 -0
  15. package/src/board/board-factory.js +12 -0
  16. package/src/board/board-group.js +9 -0
  17. package/src/board/board.js +11 -0
  18. package/src/board/grid.js +52 -0
  19. package/src/board/stack.js +16 -0
  20. package/src/condition/action-type-matches-condition.js +7 -0
  21. package/src/condition/bingo-condition.js +50 -0
  22. package/src/condition/blackout-condition.js +9 -0
  23. package/src/condition/condition-factory.js +31 -0
  24. package/src/condition/condition.js +9 -0
  25. package/src/condition/contains-condition.js +14 -0
  26. package/src/condition/does-not-contain-condition.js +15 -0
  27. package/src/condition/is-valid-player-condition.js +7 -0
  28. package/src/condition/piece-matches-condition.js +23 -0
  29. package/src/condition/relative-move-condition.js +16 -0
  30. package/src/condition/some-condition.js +7 -0
  31. package/src/game/game.ts +362 -0
  32. package/src/index.ts +1 -0
  33. package/src/piece/piece-factory.js +5 -0
  34. package/src/piece/piece.ts +25 -0
  35. package/src/piece/pile.js +70 -0
  36. package/src/player/player.ts +13 -0
  37. package/src/registry.ts +51 -0
  38. package/src/round/round-factory.js +7 -0
  39. package/src/round/round.js +41 -0
  40. package/src/round/sequential-player-turn.js +18 -0
  41. package/src/space/space.ts +22 -0
  42. package/src/utils/find-value-path.js +37 -0
  43. package/src/utils/resolve-board.ts +38 -0
  44. package/src/utils/resolve-piece.ts +43 -0
  45. package/tic-tac-toe-verbose.json +54 -0
  46. package/webpack.config.js +49 -0
package/.eslintignore ADDED
@@ -0,0 +1,2 @@
1
+ node_modules
2
+ dist
package/.eslintrc.js ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ extends: ['standard']
3
+ }
package/README.md ADDED
@@ -0,0 +1 @@
1
+ WIP object oriented board game engine with serializable game state for use in stateless backends
@@ -0,0 +1,6 @@
1
+ // only used for jest
2
+ module.exports = {
3
+ presets: [
4
+ ['@babel/preset-env', { targets: { node: 'current' } }]
5
+ ]
6
+ }
@@ -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
+ })