From afed5fd9a3999d4841657f0826899ae648a74053 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Thu, 24 Jul 2025 22:13:21 +0200 Subject: [PATCH 1/4] Fixed bug with wrong round winner --- lib/presentation/views/round_view.dart | 5 ++++- pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/presentation/views/round_view.dart b/lib/presentation/views/round_view.dart index 45249b4..964351d 100644 --- a/lib/presentation/views/round_view.dart +++ b/lib/presentation/views/round_view.dart @@ -308,7 +308,10 @@ class _RoundViewState extends State { // Iterate through the scores to find the player with the minimum score for (int i = 1; i < scores.length; i++) { - if (scores[i] < minScore) { + + // Check if the current score is less than the minimum score + // and is not negative (to avoid bonus points being considered) + if (scores[i] < minScore && !(scores[i] < 0)) { minScore = scores[i]; winnerIndex = i; } diff --git a/pubspec.yaml b/pubspec.yaml index 367411f..2658056 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: cabo_counter description: "Mobile app for the card game Cabo" publish_to: 'none' -version: 0.5.3+595 +version: 0.5.3+596 environment: sdk: ^3.5.4 From 69a2a7caec4efccdee13f0964901de13ac76a471 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Thu, 24 Jul 2025 22:20:18 +0200 Subject: [PATCH 2/4] Updated function logic --- lib/presentation/views/round_view.dart | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/lib/presentation/views/round_view.dart b/lib/presentation/views/round_view.dart index 964351d..df60a69 100644 --- a/lib/presentation/views/round_view.dart +++ b/lib/presentation/views/round_view.dart @@ -294,30 +294,14 @@ class _RoundViewState extends State { } /// Gets the index of the player who won the previous round. + /// Returns 0 in the first round, as there is no previous round. int _getPreviousRoundWinnerIndex() { if (widget.roundNumber == 1) { return 0; // If it's the first round, there's no previous round, so return 0. } - final previousRound = widget.gameSession.roundList[widget.roundNumber - 2]; - final scores = previousRound.scoreUpdates; - - // Find the index of the player with the minimum score - int minScore = scores[0]; - int winnerIndex = 0; - - // Iterate through the scores to find the player with the minimum score - for (int i = 1; i < scores.length; i++) { - - // Check if the current score is less than the minimum score - // and is not negative (to avoid bonus points being considered) - if (scores[i] < minScore && !(scores[i] < 0)) { - minScore = scores[i]; - winnerIndex = i; - } - } - - return winnerIndex; + final scores = widget.gameSession.roundList[widget.roundNumber - 2].scoreUpdates; + return scores.indexOf(0); } /// Rotates the players list based on the previous round's winner. From e18874c094f2618bc6983725d199f2c9a53f67ad Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Thu, 24 Jul 2025 22:24:27 +0200 Subject: [PATCH 3/4] Added fallback to _getPreviousRoundWinnerIndex() --- lib/presentation/views/round_view.dart | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/presentation/views/round_view.dart b/lib/presentation/views/round_view.dart index df60a69..62319e9 100644 --- a/lib/presentation/views/round_view.dart +++ b/lib/presentation/views/round_view.dart @@ -297,11 +297,17 @@ class _RoundViewState extends State { /// Returns 0 in the first round, as there is no previous round. int _getPreviousRoundWinnerIndex() { if (widget.roundNumber == 1) { - return 0; // If it's the first round, there's no previous round, so return 0. + return 0; // If it's the first round, the order should be the same as the players list. } - final scores = widget.gameSession.roundList[widget.roundNumber - 2].scoreUpdates; - return scores.indexOf(0); + final List scores = widget.gameSession.roundList[widget.roundNumber - 2].scoreUpdates; + final int winnerIndex = scores.indexOf(0); + + // Fallback if no player has 0 points, which should not happen in a valid game. + if (winnerIndex == -1) { + return 0; + } + return winnerIndex; } /// Rotates the players list based on the previous round's winner. From 4972aaa1a9dc88102bf7b8e2debc2c74aaf4b42f Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Thu, 24 Jul 2025 22:28:22 +0200 Subject: [PATCH 4/4] Updated white space --- lib/presentation/views/round_view.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/presentation/views/round_view.dart b/lib/presentation/views/round_view.dart index 62319e9..0c4d454 100644 --- a/lib/presentation/views/round_view.dart +++ b/lib/presentation/views/round_view.dart @@ -301,7 +301,7 @@ class _RoundViewState extends State { } final List scores = widget.gameSession.roundList[widget.roundNumber - 2].scoreUpdates; - final int winnerIndex = scores.indexOf(0); + final int winnerIndex = scores.indexOf(0); // Fallback if no player has 0 points, which should not happen in a valid game. if (winnerIndex == -1) {