stub submitPass on Game

This commit is contained in:
Sorrel Bri 2020-05-14 23:21:19 -07:00
parent e41d889177
commit 9b419a416b
2 changed files with 23 additions and 0 deletions

View file

@ -265,6 +265,17 @@ const Game = ({gameData = {}, gameRecord = []} = {}) => {
}); });
}, },
submitPass: function(player) {
if (player !== 'black' && player !== 'white') {
return { ...this, success: false };
}
this.addToRecord({ player, pos: { x: null, y: null } });
if (this.kos.length) helper.clearKo.call(this);
this.turn = player === 'black' ? -1 : 1;
this.boardState = getBoardState(this);
return {...this, legalMoves: getLegalMoves(this), success: true };
},
submitResign: function(player) { submitResign: function(player) {
if (player === 'black') this.winner = -1; if (player === 'black') this.winner = -1;
if (player === 'white') this.winner = 1; if (player === 'white') this.winner = 1;

View file

@ -497,6 +497,18 @@ describe('Game end logic', () => {
Game().initGame().submitResign('black') Game().initGame().submitResign('black')
.getMeta().should.eql({...initialMeta, winner: -1}); .getMeta().should.eql({...initialMeta, winner: -1});
done(); done();
});
it('pass changes game turn', done => {
Game().initGame().submitPass('black')
.getMeta().turn.should.eql(-1);
done();
});
it('pass adds null move to gameRecord', done => {
Game().initGame().submitPass('black').getMeta()
.gameRecord.should.eql([ { player: 'black', pos: { x: null, y: null } } ])
done();
}) })
}) })