-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
237 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`PlayerHuman vs PlayerAi > Issue #3 1`] = ` | ||
[ | ||
[ | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
], | ||
[ | ||
0, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
0, | ||
], | ||
[ | ||
0, | ||
0, | ||
0, | ||
1, | ||
0, | ||
1, | ||
0, | ||
], | ||
[ | ||
0, | ||
0, | ||
0, | ||
2, | ||
1, | ||
2, | ||
1, | ||
], | ||
[ | ||
0, | ||
0, | ||
0, | ||
1, | ||
2, | ||
2, | ||
2, | ||
], | ||
[ | ||
0, | ||
0, | ||
0, | ||
1, | ||
2, | ||
2, | ||
1, | ||
], | ||
] | ||
`; | ||
|
||
exports[`PlayerHuman vs PlayerAi > Issue #3 2`] = ` | ||
[ | ||
[ | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
], | ||
[ | ||
0, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
0, | ||
], | ||
[ | ||
0, | ||
0, | ||
0, | ||
1, | ||
0, | ||
1, | ||
2, | ||
], | ||
[ | ||
0, | ||
0, | ||
0, | ||
2, | ||
1, | ||
2, | ||
1, | ||
], | ||
[ | ||
0, | ||
0, | ||
0, | ||
1, | ||
2, | ||
2, | ||
2, | ||
], | ||
[ | ||
0, | ||
0, | ||
0, | ||
1, | ||
2, | ||
2, | ||
1, | ||
], | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { TestGame } from '../__testHelpers/test-game' | ||
import { BoardPiece, BoardBase } from '../board' | ||
import { TestPlayer } from '../__testHelpers/test-player' | ||
import { clone } from '../utils' | ||
import { describe, test, expect } from 'vitest' | ||
import { PlayerAi } from '../player' | ||
|
||
describe('PlayerHuman vs PlayerAi', () => { | ||
const testPlayer = new TestPlayer(BoardPiece.PLAYER_1) | ||
const aiPlayer = new PlayerAi(BoardPiece.PLAYER_2) | ||
const players = [testPlayer, aiPlayer] | ||
test('Issue #3', async () => { | ||
const board = new BoardBase() | ||
const game = new TestGame(players, board) | ||
|
||
/* | ||
Next move is Player 2 (AI) | ||
Current board: | ||
0 0 0 0 0 0 0 | ||
0 0 0 1 0 0 0 | ||
0 0 0 1 0 1 0 | ||
0 0 0 2 1 2 1 | ||
0 0 0 1 2 2 2 | ||
0 0 0 1 2 2 1 | ||
Should probably choose column 2 to block immediate Player 1 from winning | ||
*/ | ||
board.map = [ | ||
[ | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
], | ||
[ | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.PLAYER_1, | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
], | ||
[ | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.PLAYER_1, | ||
BoardPiece.EMPTY, | ||
BoardPiece.PLAYER_1, | ||
BoardPiece.EMPTY, | ||
], | ||
[ | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.PLAYER_2, | ||
BoardPiece.PLAYER_1, | ||
BoardPiece.PLAYER_2, | ||
BoardPiece.PLAYER_1, | ||
], | ||
[ | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.PLAYER_1, | ||
BoardPiece.PLAYER_2, | ||
BoardPiece.PLAYER_2, | ||
BoardPiece.PLAYER_2, | ||
], | ||
[ | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.EMPTY, | ||
BoardPiece.PLAYER_1, | ||
BoardPiece.PLAYER_2, | ||
BoardPiece.PLAYER_2, | ||
BoardPiece.PLAYER_1, | ||
], | ||
] | ||
|
||
board.debug() | ||
expect(board.map).toMatchSnapshot() | ||
game.currentPlayerId = 1 | ||
game.start() | ||
board.debug() | ||
console.log() | ||
await game.afterMovePromise | ||
|
||
expect(board.map).toMatchSnapshot() | ||
board.debug() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters