Alpha DrawCondition update (#89)

* drawConditions gemaakt en geimplementeerd

* drawConditions gemaakt en geimplementeerd, werkt wanneer je het lokaal draait

* better draw conditions in a shorter amount of lines

* commit for ticho

* working draw conditions (maybe?)

* moved a little bit

* removed a little bit

---------

Co-authored-by: michiel <m.brands.3@st.hanze.nl>
This commit is contained in:
Bas Antonius de Jong
2025-10-01 15:20:02 +02:00
committed by GitHub
parent eb6dc03a3d
commit 2f9b155e6e
2 changed files with 85 additions and 61 deletions

2
.idea/misc.xml generated
View File

@@ -13,7 +13,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_24" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@@ -44,11 +44,13 @@ public final class TicTacToe extends Game {
return State.WIN; return State.WIN;
} }
if (movesLeft <= 0) { nextPlayer();
if (movesLeft <= 2) {
if (checkDraw(new TicTacToe(this))) {
return State.DRAW; return State.DRAW;
} }
}
nextPlayer();
return State.NORMAL; return State.NORMAL;
} }
@@ -81,4 +83,26 @@ public final class TicTacToe extends Game {
// F-Slash // F-Slash
return board[2] != EMPTY && board[2] == board[4] && board[2] == board[6]; return board[2] != EMPTY && board[2] == board[4] && board[2] == board[6];
} }
public boolean checkDraw(TicTacToe game) {
if (game.checkForWin()) {
return false;
}
if (game.movesLeft == 0) {
return true;
}
// try every move on a legal copy
for (Move move : game.getLegalMoves()) {
TicTacToe copy = new TicTacToe(game);
State result = copy.play(move);
if (result == State.WIN) {
return false;
}
if (!checkDraw(copy)) {
return false;
}
}
return true;
}
} }