Skip to content

Commit

Permalink
disable move if playerID is null
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolodavis committed May 1, 2018
1 parent 9c8ecb9 commit ca9f6ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function canPlayerMakeMove(G, ctx, opts) {
// In multiplayer mode, the default playerID is null, which corresponds
// to a spectator that can't make moves.
if (playerID === null) {
return true;
return false;
}

// In singleplayer mode (and most unit tests), the default playerID
Expand Down
5 changes: 5 additions & 0 deletions src/core/flow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ test('canMakeMove', () => {
state = reducer(state, makeMove('C'));
expect(state.G).toMatchObject({ C: true });

// But not if the playerID is null (spectator).
state.G = {};
state = reducer(state, makeMove('A', null, null));
expect(state.G).not.toMatchObject({ A: true });

// But not once the game is over.
state.ctx.gameover = true;
state.G = {};
Expand Down

0 comments on commit ca9f6ca

Please sign in to comment.