mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
new reversi test (both players no legal moves)
This commit is contained in:
@@ -150,7 +150,18 @@ public final class Reversi extends TurnBasedGame {
|
||||
nextTurn();
|
||||
if (getLegalMoves().length == 0) {
|
||||
skipMyTurn();
|
||||
return State.MOVE_SKIPPED;
|
||||
if (getLegalMoves().length > 0) {
|
||||
return State.MOVE_SKIPPED;
|
||||
}
|
||||
else {
|
||||
Score score = getScore();
|
||||
if (score.player1Score() == score.player2Score()) {
|
||||
return State.DRAW;
|
||||
}
|
||||
else {
|
||||
return State.WIN;
|
||||
}
|
||||
}
|
||||
}
|
||||
return State.NORMAL;
|
||||
}
|
||||
@@ -184,10 +195,10 @@ public final class Reversi extends TurnBasedGame {
|
||||
public Game.Score getScore(){
|
||||
int player1Score = 0, player2Score = 0;
|
||||
for (int count = 0; count < rowSize * columnSize; count++) {
|
||||
if (board[count] == 'W') {
|
||||
if (board[count] == 'B') {
|
||||
player1Score += 1;
|
||||
}
|
||||
if (board[count] == 'B') {
|
||||
if (board[count] == 'W') {
|
||||
player2Score += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,6 +149,34 @@ class ReversiTest {
|
||||
game.play(ai.findBestMove(game,5));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGameShouldEndIfNoValidMoves() {
|
||||
//European Grand Prix Ghent 2017: Replay Hassan - Verstuyft J. (3-17)
|
||||
game.play(new Game.Move(19, 'B'));
|
||||
game.play(new Game.Move(20, 'W'));
|
||||
game.play(new Game.Move(29, 'B'));
|
||||
game.play(new Game.Move(22, 'W'));
|
||||
game.play(new Game.Move(21, 'B'));
|
||||
game.play(new Game.Move(34, 'W'));
|
||||
game.play(new Game.Move(23, 'B'));
|
||||
game.play(new Game.Move(13, 'W'));
|
||||
game.play(new Game.Move(26, 'B'));
|
||||
game.play(new Game.Move(18, 'W'));
|
||||
game.play(new Game.Move(12, 'B'));
|
||||
game.play(new Game.Move(4, 'W'));
|
||||
game.play(new Game.Move(17, 'B'));
|
||||
game.play(new Game.Move(31, 'W'));
|
||||
Game.State stateTurn15 = game.play(new Game.Move(39, 'B'));
|
||||
assertEquals(Game.State.NORMAL, stateTurn15);
|
||||
Game.State stateTurn16 = game.play(new Game.Move(16, 'W'));
|
||||
assertEquals(Game.State.WIN, stateTurn16);
|
||||
Game.State stateTurn17 = game.play(new Game.Move(5, 'B'));
|
||||
assertNull(stateTurn17);
|
||||
Game.Score score = game.getScore();
|
||||
assertEquals(3, score.player1Score());
|
||||
assertEquals(17, score.player2Score());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAISelectsLegalMove() {
|
||||
Game.Move move = ai.findBestMove(game,4);
|
||||
|
||||
Reference in New Issue
Block a user