add submitResign to Game

This commit is contained in:
Sorrel Bri 2020-05-14 20:59:49 -07:00
parent 7aed5b7bf9
commit ef0e53756e
2 changed files with 15 additions and 0 deletions

View file

@ -263,6 +263,13 @@ const Game = ({gameData = {}, gameRecord = []} = {}) => {
gameData: { komi, handicap, boardSize }, gameData: { komi, handicap, boardSize },
gameRecord: [...this.gameRecord.slice(0, index)] gameRecord: [...this.gameRecord.slice(0, index)]
}); });
},
submitResign: function(player) {
if (player === 'black') this.winner = -1;
if (player === 'white') this.winner = 1;
this.turn = 0;
return this;
} }
} }
}; };

View file

@ -469,6 +469,14 @@ describe('Game history functionality', () => {
fifthMoveGame.boardState['10-4'].stone.should.eql(1) fifthMoveGame.boardState['10-4'].stone.should.eql(1)
fifthMoveGame.boardState['4-10'].stone.should.eql(0) fifthMoveGame.boardState['4-10'].stone.should.eql(0)
done(); done();
});
});
describe('Game end logic', () => {
it('resignation results in game end', done => {
Game().initGame().submitResign('black')
.getMeta().should.eql({...initialMeta, winner: -1});
done();
}) })
}) })