mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
fixed turn skip bug
fixed end score bug now only shows legal and highlight moves when human
This commit is contained in:
@@ -168,9 +168,13 @@ public final class ReversiGame {
|
|||||||
updateCanvas(true);
|
updateCanvas(true);
|
||||||
|
|
||||||
if (state != GameState.NORMAL) {
|
if (state != GameState.NORMAL) {
|
||||||
if (state == GameState.WIN) {
|
if (state == GameState.TURN_SKIPPED){
|
||||||
view.gameOver(true, information.players[currentTurn].name);
|
continue;
|
||||||
} else if (state == GameState.DRAW) {
|
}
|
||||||
|
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, "");
|
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) {
|
private void onMoveResponse(NetworkEvents.GameMoveResponse response) {
|
||||||
if (!isRunning.get()) {
|
if (!isRunning.get()) {
|
||||||
return;
|
return;
|
||||||
@@ -287,11 +298,13 @@ public final class ReversiGame {
|
|||||||
animation.setOnFinished(_ -> {
|
animation.setOnFinished(_ -> {
|
||||||
isPaused.set(false);
|
isPaused.set(false);
|
||||||
|
|
||||||
|
if (information.players[game.getCurrentTurn()].isHuman) {
|
||||||
final Move[] legalMoves = game.getLegalMoves();
|
final Move[] legalMoves = game.getLegalMoves();
|
||||||
|
|
||||||
for (final Move legalMove : legalMoves) {
|
for (final Move legalMove : legalMoves) {
|
||||||
canvas.drawLegalPosition(legalMove.position(), game.getCurrentPlayer());
|
canvas.drawLegalPosition(legalMove.position(), game.getCurrentPlayer());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
animation.play();
|
animation.play();
|
||||||
@@ -308,6 +321,7 @@ public final class ReversiGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void highlightCells(int cellEntered) {
|
private void highlightCells(int cellEntered) {
|
||||||
|
if (information.players[game.getCurrentTurn()].isHuman) {
|
||||||
Move[] legalMoves = game.getLegalMoves();
|
Move[] legalMoves = game.getLegalMoves();
|
||||||
boolean isLegalMove = false;
|
boolean isLegalMove = false;
|
||||||
for (Move move : legalMoves) {
|
for (Move move : legalMoves) {
|
||||||
@@ -328,3 +342,4 @@ public final class ReversiGame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ public final class ReversiAI extends AI<Reversi> {
|
|||||||
public Move findBestMove(Reversi game, int depth) {
|
public Move findBestMove(Reversi game, int depth) {
|
||||||
Move[] moves = game.getLegalMoves();
|
Move[] moves = game.getLegalMoves();
|
||||||
int inty = (int)(Math.random() * moves.length-.5f);
|
int inty = (int)(Math.random() * moves.length-.5f);
|
||||||
|
if (moves.length == 0) return null;
|
||||||
return moves[inty];
|
return moves[inty];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user