From 3443b5e8f3e29b70e5f0c8e283448364bad92416 Mon Sep 17 00:00:00 2001 From: Julian Kropff Date: Sun, 19 Apr 2026 20:02:02 +0200 Subject: [PATCH] Fix: align TaskbarController with Round logic fixes Refs #118 --- .../gameuicomponents/TaskbarController.java | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/gameuicomponents/TaskbarController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/gameuicomponents/TaskbarController.java index e25528a..0b2f398 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/gameuicomponents/TaskbarController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/gameuicomponents/TaskbarController.java @@ -262,7 +262,7 @@ public class TaskbarController { boolean isMyTurn = state.activePlayer == myIndex; boolean isOut = me.getState() == PlayerState.FOLDED; - boolean isGameFinished = state.phase != null && state.phase.equalsIgnoreCase("FINISHED"); + boolean isGameFinished = isHandFinished(state); updateBasicButtons(isMyTurn, isOut || isGameFinished); applyActionAvailability(state, me, isMyTurn, isOut || isGameFinished); @@ -535,6 +535,28 @@ public class TaskbarController { 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 * the bet and the player's available chips. @@ -599,6 +621,12 @@ public class TaskbarController { return; } + if (isHandFinished(state)) { + LOGGER.info("Action {} ignored: hand is already finished", actionType); + update(state, myPlayerId); + return; + } + Player me = findCurrentPlayer(state); if (me == null) { LOGGER.error("Action {} blocked: player missing in state", actionType); @@ -914,6 +942,13 @@ public class TaskbarController { return; } + GameState state = ensureLatestStateForAction("fold"); + if (isHandFinished(state)) { + LOGGER.info("Fold ignored: hand is already finished"); + update(state, myPlayerId); + return; + } + gameService.fold(); LOGGER.info("Player FOLD");