fix: fix tic-tac-toe test
This commit is contained in:
parent
b33c901c11
commit
a8ff79e4e5
|
|
@ -125,8 +125,8 @@ export function createTurnRule() {
|
||||||
const playCmd = received as Command;
|
const playCmd = received as Command;
|
||||||
if (playCmd.name !== 'play') continue;
|
if (playCmd.name !== 'play') continue;
|
||||||
|
|
||||||
const row = playCmd.params[1] as number;
|
const row = Number(playCmd.params[1]);
|
||||||
const col = playCmd.params[2] as number;
|
const col = Number(playCmd.params[2]);
|
||||||
|
|
||||||
if (isNaN(row) || isNaN(col) || row < 0 || row > 2 || col < 0 || col > 2) continue;
|
if (isNaN(row) || isNaN(col) || row < 0 || row > 2 || col < 0 || col > 2) continue;
|
||||||
if (isCellOccupied(this, row, col)) continue;
|
if (isCellOccupied(this, row, col)) continue;
|
||||||
|
|
|
||||||
|
|
@ -95,17 +95,17 @@ describe('Tic-Tac-Toe', () => {
|
||||||
startTicTacToe(game);
|
startTicTacToe(game);
|
||||||
|
|
||||||
// Fill board with no winner (cat's game)
|
// Fill board with no winner (cat's game)
|
||||||
// X: (0,0), (0,2), (1,1), (2,0)
|
// X: (1,1), (0,2), (2,2), (1,0), (2,1)
|
||||||
// O: (0,1), (1,0), (1,2), (2,1), (2,2)
|
// O: (0,0), (2,0), (0,1), (1,2)
|
||||||
game.dispatchCommand('play X 0 0'); // X
|
game.dispatchCommand('play X 1 1'); // X
|
||||||
game.dispatchCommand('play O 0 1'); // O
|
game.dispatchCommand('play O 0 0'); // O
|
||||||
game.dispatchCommand('play X 0 2'); // X
|
game.dispatchCommand('play X 0 2'); // X
|
||||||
game.dispatchCommand('play O 1 0'); // O
|
game.dispatchCommand('play O 2 0'); // O
|
||||||
game.dispatchCommand('play X 1 1'); // X (center)
|
game.dispatchCommand('play X 2 2'); // X
|
||||||
|
game.dispatchCommand('play O 0 1'); // O
|
||||||
|
game.dispatchCommand('play X 1 0'); // X
|
||||||
game.dispatchCommand('play O 1 2'); // O
|
game.dispatchCommand('play O 1 2'); // O
|
||||||
game.dispatchCommand('play X 2 0'); // X
|
game.dispatchCommand('play X 2 1'); // X (last move, draw)
|
||||||
game.dispatchCommand('play O 2 1'); // O
|
|
||||||
game.dispatchCommand('play X 2 2'); // X (last move, draw)
|
|
||||||
|
|
||||||
const state = getBoardState(game);
|
const state = getBoardState(game);
|
||||||
expect(state.winner).toBe('draw');
|
expect(state.winner).toBe('draw');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue