fixed turn skip bug

fixed end score bug
now only shows legal and highlight moves when human
This commit is contained in:
Ticho Hidding
2025-11-27 15:41:09 +01:00
parent 710438ec1b
commit 81f4d307a2
2 changed files with 37 additions and 21 deletions

View File

@@ -168,9 +168,13 @@ public final class ReversiGame {
updateCanvas(true);
if (state != GameState.NORMAL) {
if (state == GameState.WIN) {
view.gameOver(true, information.players[currentTurn].name);
} else if (state == GameState.DRAW) {
if (state == GameState.TURN_SKIPPED){
continue;
}
int winningPLayerNumber = getPlayerNumberWithHighestScore();
if (state == GameState.WIN && winningPLayerNumber > -1) {
view.gameOver(true, information.players[winningPLayerNumber].name);
} else if (state == GameState.DRAW || winningPLayerNumber == -1) {
view.gameOver(false, "");
}
@@ -179,6 +183,13 @@ public final class ReversiGame {
}
}
private int getPlayerNumberWithHighestScore(){
Reversi.Score score = game.getScore();
if (score.player1Score() > score.player2Score()) return 0;
if (score.player1Score() < score.player2Score()) return 1;
return -1;
}
private void onMoveResponse(NetworkEvents.GameMoveResponse response) {
if (!isRunning.get()) {
return;
@@ -287,11 +298,13 @@ public final class ReversiGame {
animation.setOnFinished(_ -> {
isPaused.set(false);
if (information.players[game.getCurrentTurn()].isHuman) {
final Move[] legalMoves = game.getLegalMoves();
for (final Move legalMove : legalMoves) {
canvas.drawLegalPosition(legalMove.position(), game.getCurrentPlayer());
}
}
});
animation.play();
@@ -308,6 +321,7 @@ public final class ReversiGame {
}
private void highlightCells(int cellEntered) {
if (information.players[game.getCurrentTurn()].isHuman) {
Move[] legalMoves = game.getLegalMoves();
boolean isLegalMove = false;
for (Move move : legalMoves) {
@@ -328,3 +342,4 @@ public final class ReversiGame {
}
}
}
}

View File

@@ -8,6 +8,7 @@ public final class ReversiAI extends AI<Reversi> {
public Move findBestMove(Reversi game, int depth) {
Move[] moves = game.getLegalMoves();
int inty = (int)(Math.random() * moves.length-.5f);
if (moves.length == 0) return null;
return moves[inty];
}
}