mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Changed checkForEarlyDraw so it doesn't need a game as input.
This commit is contained in:
@@ -49,7 +49,7 @@ public final class TicTacToe extends TurnBasedGame {
|
|||||||
nextTurn();
|
nextTurn();
|
||||||
|
|
||||||
if (movesLeft <= 2) {
|
if (movesLeft <= 2) {
|
||||||
if (movesLeft <= 0 || checkForEarlyDraw(this)) {
|
if (movesLeft <= 0 || checkForEarlyDraw()) {
|
||||||
return GameState.DRAW;
|
return GameState.DRAW;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,11 +85,11 @@ public final class TicTacToe extends TurnBasedGame {
|
|||||||
return this.getBoard()[2] != EMPTY && this.getBoard()[2] == this.getBoard()[4] && this.getBoard()[2] == this.getBoard()[6];
|
return this.getBoard()[2] != EMPTY && this.getBoard()[2] == this.getBoard()[4] && this.getBoard()[2] == this.getBoard()[6];
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkForEarlyDraw(TicTacToe game) {
|
private boolean checkForEarlyDraw() {
|
||||||
for (final Move move : game.getLegalMoves()) {
|
for (final Move move : this.getLegalMoves()) {
|
||||||
final TicTacToe copy = new TicTacToe(game);
|
final TicTacToe copy = new TicTacToe(this);
|
||||||
|
|
||||||
if (copy.play(move) == GameState.WIN || !checkForEarlyDraw(copy)) {
|
if (copy.play(move) == GameState.WIN || !copy.checkForEarlyDraw()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user