board-game-engine 0.0.8 → 0.0.9
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/dist/board-game-engine.js +23 -22
- package/dist/board-game-engine.min.js +1 -1
- package/e2e/bge.spec.js +267 -0
- package/e2e/bgio-minimal.spec.js +70 -0
- package/e2e/examples.spec.js +34 -0
- package/e2e/fixtures/bge-checkers.html +39 -0
- package/e2e/fixtures/bge-minimal.html +43 -0
- package/e2e/fixtures/bge-ttt.html +45 -0
- package/e2e/fixtures/bgio-minimal-debug.html +47 -0
- package/e2e/fixtures/bgio-minimal.html +44 -0
- package/e2e/fixtures/minimal-game.json +4 -0
- package/examples/checkers.json +793 -0
- package/examples/connect-four.json +126 -0
- package/examples/eights.json +653 -0
- package/examples/index.html +219 -0
- package/examples/reversi.json +215 -0
- package/examples/tic-tac-toe.json +53 -0
- package/package.json +8 -5
- package/playwright-report/index.html +85 -0
- package/playwright.config.cjs +23 -0
- package/src/client/client.js +2 -1
- package/src/game-factory/bank/bank.js +1 -1
- package/src/game-factory/condition/is-full-condition.js +1 -1
- package/src/game-factory/condition/would-condition.js +1 -1
- package/src/game-factory/expand-game-rules.js +7 -12
- package/src/game-factory/move/move-factory.js +1 -1
- package/src/game-factory/space-group/space-group.js +1 -1
- package/src/index.js +1 -1
- package/src/utils/get-steps.js +1 -1
- package/test-results/.last-run.json +4 -0
- package/babel.config.js +0 -6
- package/board-game-engine.test.js +0 -7
- package/jest.config.js +0 -21
- package/tic-tac-toe-verbose.json +0 -54
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { devices } = require('@playwright/test')
|
|
2
|
+
|
|
3
|
+
const PORT = 5174
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
testDir: 'e2e',
|
|
7
|
+
fullyParallel: false,
|
|
8
|
+
forbidOnly: !!process.env.CI,
|
|
9
|
+
retries: process.env.CI ? 2 : 0,
|
|
10
|
+
workers: 1,
|
|
11
|
+
reporter: 'html',
|
|
12
|
+
use: {
|
|
13
|
+
baseURL: `http://localhost:${PORT}`,
|
|
14
|
+
trace: 'on-first-retry',
|
|
15
|
+
viewport: { width: 800, height: 600 },
|
|
16
|
+
},
|
|
17
|
+
projects: [{ name: 'firefox', use: { ...devices['Desktop Firefox'] } }],
|
|
18
|
+
webServer: {
|
|
19
|
+
command: `npx http-server . -p ${PORT} -c-1`,
|
|
20
|
+
url: `http://localhost:${PORT}`,
|
|
21
|
+
reuseExistingServer: !process.env.CI,
|
|
22
|
+
},
|
|
23
|
+
}
|
package/src/client/client.js
CHANGED
|
@@ -3,7 +3,7 @@ import Condition from "./condition.js";
|
|
|
3
3
|
export default class IsFull extends Condition {
|
|
4
4
|
checkCondition(bgioArguments, rule, payload, context) {
|
|
5
5
|
return {
|
|
6
|
-
conditionIsMet: payload.target.spaces.every(space => space
|
|
6
|
+
conditionIsMet: payload.target.spaces.every(space => space?.entities.length)
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -17,7 +17,7 @@ export default class WouldCondition extends Condition {
|
|
|
17
17
|
const payload = {
|
|
18
18
|
arguments: targets.reduce((acc, target, i) => ({
|
|
19
19
|
...acc,
|
|
20
|
-
[argNameMap[context.moveInstance.rule.
|
|
20
|
+
[argNameMap[context.moveInstance.rule.moveType][i]]: target
|
|
21
21
|
}), {})
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -21,11 +21,11 @@ import transformJSON from "../utils/json-transformer.js";
|
|
|
21
21
|
// want to treat as first-class citizens
|
|
22
22
|
const invariantEntities = [
|
|
23
23
|
{
|
|
24
|
-
|
|
24
|
+
entityType: "Space",
|
|
25
25
|
count: "Infinity",
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
|
-
|
|
28
|
+
entityType: "Board",
|
|
29
29
|
name: 'sharedBoard'
|
|
30
30
|
},
|
|
31
31
|
{
|
|
@@ -51,7 +51,7 @@ function expandInitialPlacements (rules, entities) {
|
|
|
51
51
|
|
|
52
52
|
if (rules.personalBoard) {
|
|
53
53
|
entities.push({
|
|
54
|
-
|
|
54
|
+
entityType: "Board",
|
|
55
55
|
name: 'personalBoard',
|
|
56
56
|
perPlayer: true
|
|
57
57
|
})
|
|
@@ -75,7 +75,7 @@ function expandInitialPlacements (rules, entities) {
|
|
|
75
75
|
|
|
76
76
|
if (placement.destination.name === 'personalBoard') {
|
|
77
77
|
return {
|
|
78
|
-
|
|
78
|
+
moveType: 'ForEach',
|
|
79
79
|
arguments: {
|
|
80
80
|
targets: {
|
|
81
81
|
type: 'ctxPath',
|
|
@@ -83,7 +83,7 @@ function expandInitialPlacements (rules, entities) {
|
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
85
|
move: {
|
|
86
|
-
|
|
86
|
+
moveType: 'PlaceNew',
|
|
87
87
|
entity: {
|
|
88
88
|
state,
|
|
89
89
|
conditions: [{
|
|
@@ -120,7 +120,7 @@ function expandInitialPlacements (rules, entities) {
|
|
|
120
120
|
}
|
|
121
121
|
} else {
|
|
122
122
|
return {
|
|
123
|
-
|
|
123
|
+
moveType: 'PlaceNew',
|
|
124
124
|
entity: {
|
|
125
125
|
state,
|
|
126
126
|
conditions: [{
|
|
@@ -145,12 +145,7 @@ function expandInitialPlacements (rules, entities) {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
const keyMappings = [
|
|
149
|
-
['thatMatches', 'conditions'],
|
|
150
|
-
['entityType', 'type'],
|
|
151
|
-
['moveType', 'type'],
|
|
152
|
-
['endConditions', 'endIf'],
|
|
153
|
-
]
|
|
148
|
+
const keyMappings = []
|
|
154
149
|
|
|
155
150
|
const simpleReplacements = [
|
|
156
151
|
[
|
|
@@ -8,7 +8,7 @@ export default class SpaceGroup extends Entity {
|
|
|
8
8
|
|
|
9
9
|
makeSpaces (bank) {
|
|
10
10
|
return Array(this.getSpacesCount()).fill()
|
|
11
|
-
.map((_, i) => bank.createEntity({
|
|
11
|
+
.map((_, i) => bank.createEntity({ entityType: 'Space', index: i }))
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
getEmptySpaces() {
|
package/src/index.js
CHANGED
package/src/utils/get-steps.js
CHANGED
|
@@ -9,7 +9,7 @@ const argNamesMap = {
|
|
|
9
9
|
|
|
10
10
|
// this might not be where special handling for setstate wants to live
|
|
11
11
|
export default function getSteps (bgioState, moveRule) {
|
|
12
|
-
return argNamesMap[moveRule.
|
|
12
|
+
return argNamesMap[moveRule.moveType]
|
|
13
13
|
.filter(argName => moveRule.arguments[argName].playerChoice)
|
|
14
14
|
.map(argName => ({
|
|
15
15
|
argName,
|
package/babel.config.js
DELETED
package/jest.config.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
testEnvironment: 'node',
|
|
3
|
-
transform: {
|
|
4
|
-
'^.+\\.(js|ts)$': ['babel-jest', {
|
|
5
|
-
presets: [
|
|
6
|
-
'@babel/preset-typescript',
|
|
7
|
-
['@babel/preset-env', {
|
|
8
|
-
modules: 'cjs',
|
|
9
|
-
targets: { node: 'current' }
|
|
10
|
-
}]
|
|
11
|
-
],
|
|
12
|
-
plugins: ['add-module-exports']
|
|
13
|
-
}]
|
|
14
|
-
},
|
|
15
|
-
clearMocks: true,
|
|
16
|
-
moduleFileExtensions: ['js', 'ts', 'json'],
|
|
17
|
-
testMatch: [
|
|
18
|
-
'**/__tests__/**/*.(js|ts)',
|
|
19
|
-
'**/*.(test|spec).(js|ts)'
|
|
20
|
-
]
|
|
21
|
-
}
|
package/tic-tac-toe-verbose.json
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
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
|
-
}
|