Skip to content

Commit

Permalink
long form move syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolodavis committed Sep 10, 2019
1 parent 65472e1 commit 4b202ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/core/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ function Game(game) {
moveFn = game.flow.moveMap[action.type];
}

if (moveFn instanceof Object && moveFn.impl) {
moveFn = moveFn.impl;
}

if (moveFn !== null) {
const ctxWithPlayerID = { ...ctx, playerID: action.playerID };
const args = [G, ctxWithPlayerID].concat(action.args);
Expand Down
11 changes: 9 additions & 2 deletions src/core/game.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ describe('basic', () => {
moves: {
A: G => G,
B: () => null,
C: {
impl: () => 'C',
},
},

flow: {
Expand All @@ -31,18 +34,22 @@ describe('basic', () => {
});

test('sanity', () => {
expect(game.moveNames).toEqual(['A', 'B', 'PA.A']);
expect(game.moveNames).toEqual(['A', 'B', 'C', 'PA.A']);
expect(typeof game.processMove).toEqual('function');
});

test('processMove', () => {
const testObj = { test: true };
expect(game.processMove(testObj, { type: 'A' })).toEqual(testObj);
expect(game.processMove(testObj, { type: 'C' })).toEqual(testObj);
expect(game.processMove(testObj, { type: 'D' })).toEqual(testObj);
expect(game.processMove(testObj, { type: 'B' })).toEqual(null);
expect(game.processMove(testObj, { type: 'PA.A' })).toEqual('PA.A');
});

test('long-form move syntax', () => {
expect(game.processMove({}, { type: 'C' })).toEqual('C');
});

test('flow override', () => {
const f = { processGameEvent: () => {} };
const game = Game({
Expand Down

0 comments on commit 4b202ee

Please sign in to comment.