Skip to content

Commit

Permalink
don't run bot once game is over
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolodavis committed Feb 14, 2020
1 parent 7c65046 commit aed5cd1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/client/transport/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { Transport } from './transport';
* Otherwise, returns a playerID of a bot that may play now.
*/
export function GetBotPlayer(state, bots) {
if (state.ctx.gameover !== undefined) {
return null;
}

if (state.ctx.stage) {
for (const key of Object.keys(bots)) {
if (key in state.ctx.stage) {
Expand Down
13 changes: 13 additions & 0 deletions src/client/transport/local.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ describe('GetBotPlayer', () => {
);
expect(result).toEqual(null);
});

test('gameover', () => {
const result = GetBotPlayer(
{
ctx: {
currentPlayer: '0',
gameover: true,
},
},
{ '0': {} }
);
expect(result).toEqual(null);
});
});

describe('LocalMaster', () => {
Expand Down

0 comments on commit aed5cd1

Please sign in to comment.