Fix: improve round management, betting validation and game engine test coverage #290

Merged
j.kropff merged 13 commits from fix/game-turn-and-action-bugs into main 2026-04-19 20:31:45 +02:00
Showing only changes of commit 3443b5e8f3 - Show all commits
@@ -262,7 +262,7 @@ public class TaskbarController {
boolean isMyTurn = state.activePlayer == myIndex; boolean isMyTurn = state.activePlayer == myIndex;
boolean isOut = me.getState() == PlayerState.FOLDED; boolean isOut = me.getState() == PlayerState.FOLDED;
boolean isGameFinished = state.phase != null && state.phase.equalsIgnoreCase("FINISHED"); boolean isGameFinished = isHandFinished(state);
updateBasicButtons(isMyTurn, isOut || isGameFinished); updateBasicButtons(isMyTurn, isOut || isGameFinished);
applyActionAvailability(state, me, isMyTurn, isOut || isGameFinished); applyActionAvailability(state, me, isMyTurn, isOut || isGameFinished);
@@ -535,6 +535,28 @@ public class TaskbarController {
return "TURN".equalsIgnoreCase(phase) || "RIVER".equalsIgnoreCase(phase); return "TURN".equalsIgnoreCase(phase) || "RIVER".equalsIgnoreCase(phase);
} }
/**
* Checks if the hand is finished based on the current game state.
*
* @param state The current GameState object representing the state of the game, which includes information
* @return A boolean value indicating whether the hand is finished, which can be determined by
* checking if the phase is "FINISHED" or "SHOWDOWN",
*/
private boolean isHandFinished(GameState state) {
if (state == null) {
return false;
}
if ("FINISHED".equalsIgnoreCase(state.phase)
|| "SHOWDOWN".equalsIgnoreCase(state.phase)) {
return true;
}
return state.players != null
&& state.winnerIndex >= 0
&& state.winnerIndex < state.players.size();
}
/** /**
* Evaluates the risk level of a proposed bet based on the current game state, the amount of * Evaluates the risk level of a proposed bet based on the current game state, the amount of
* the bet and the player's available chips. * the bet and the player's available chips.
@@ -599,6 +621,12 @@ public class TaskbarController {
return; return;
} }
if (isHandFinished(state)) {
LOGGER.info("Action {} ignored: hand is already finished", actionType);
update(state, myPlayerId);
return;
}
Player me = findCurrentPlayer(state); Player me = findCurrentPlayer(state);
if (me == null) { if (me == null) {
LOGGER.error("Action {} blocked: player missing in state", actionType); LOGGER.error("Action {} blocked: player missing in state", actionType);
@@ -914,6 +942,13 @@ public class TaskbarController {
return; return;
} }
GameState state = ensureLatestStateForAction("fold");
if (isHandFinished(state)) {
LOGGER.info("Fold ignored: hand is already finished");
update(state, myPlayerId);
return;
}
gameService.fold(); gameService.fold();
LOGGER.info("Player FOLD"); LOGGER.info("Player FOLD");