mirror of
https://github.com/2OOP/pism.git
synced 2026-02-05 03:14:50 +00:00
new reversi test (both players no legal moves)
This commit is contained in:
@@ -150,8 +150,19 @@ public final class Reversi extends TurnBasedGame {
|
|||||||
nextTurn();
|
nextTurn();
|
||||||
if (getLegalMoves().length == 0) {
|
if (getLegalMoves().length == 0) {
|
||||||
skipMyTurn();
|
skipMyTurn();
|
||||||
|
if (getLegalMoves().length > 0) {
|
||||||
return State.MOVE_SKIPPED;
|
return State.MOVE_SKIPPED;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
Score score = getScore();
|
||||||
|
if (score.player1Score() == score.player2Score()) {
|
||||||
|
return State.DRAW;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return State.WIN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return State.NORMAL;
|
return State.NORMAL;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -184,10 +195,10 @@ public final class Reversi extends TurnBasedGame {
|
|||||||
public Game.Score getScore(){
|
public Game.Score getScore(){
|
||||||
int player1Score = 0, player2Score = 0;
|
int player1Score = 0, player2Score = 0;
|
||||||
for (int count = 0; count < rowSize * columnSize; count++) {
|
for (int count = 0; count < rowSize * columnSize; count++) {
|
||||||
if (board[count] == 'W') {
|
if (board[count] == 'B') {
|
||||||
player1Score += 1;
|
player1Score += 1;
|
||||||
}
|
}
|
||||||
if (board[count] == 'B') {
|
if (board[count] == 'W') {
|
||||||
player2Score += 1;
|
player2Score += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,6 +149,34 @@ class ReversiTest {
|
|||||||
game.play(ai.findBestMove(game,5));
|
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
|
@Test
|
||||||
void testAISelectsLegalMove() {
|
void testAISelectsLegalMove() {
|
||||||
Game.Move move = ai.findBestMove(game,4);
|
Game.Move move = ai.findBestMove(game,4);
|
||||||
|
|||||||
Reference in New Issue
Block a user