From 5e6d28c66377901329b12b585bdc4fb9e13c4cf2 Mon Sep 17 00:00:00 2001 From: MeirGavish Date: Fri, 8 Aug 2025 00:01:36 +0300 Subject: [PATCH] Fixed stack top bugs in joker_effects.c - e.g. Blackboard activated if just the first card in hand was not spades/clubs --- include/game.h | 1 + source/game.c | 10 +++++----- source/joker_effects.c | 15 +++++++++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/include/game.h b/include/game.h index 02c3b01..1d99865 100644 --- a/include/game.h +++ b/include/game.h @@ -77,6 +77,7 @@ typedef struct CardObject CardObject; // forward declaration, actually declared typedef struct JokerObject JokerObject; CardObject** get_hand_array(void); int get_hand_top(void); +int hand_get_size(void); CardObject** get_played_array(void); int get_played_top(void); JokerObject** get_jokers(void); diff --git a/source/game.c b/source/game.c index e067082..fe820c5 100644 --- a/source/game.c +++ b/source/game.c @@ -148,6 +148,11 @@ int get_hand_top(void) { return hand_top; } +int hand_get_size(void) +{ + return hand_top + 1; +} + CardObject **get_played_array(void) { return played; } @@ -853,11 +858,6 @@ void hand_change_sort() sort_cards(); } -int hand_get_size() -{ - return hand_top + 1; -} - int hand_get_max_size() { return hand_size; diff --git a/source/joker_effects.c b/source/joker_effects.c index 7a2eaf3..fa6c897 100644 --- a/source/joker_effects.c +++ b/source/joker_effects.c @@ -1,3 +1,4 @@ +#include "game.h" #include "joker.h" #include "util.h" #include "hand_analysis.h" @@ -178,7 +179,8 @@ static JokerEffect half_joker_effect(Joker *joker, Card *scored_card) { if (scored_card != NULL) return effect; // if card != null, we are not at the end-phase of scoring yet - if (get_played_top() + 1 <= 3) // game.c has hand_get_size() but it's not accesible here + int played_size = get_played_top() + 1; + if (played_size <= 3) effect.mult = 20; return effect; @@ -190,12 +192,13 @@ static JokerEffect joker_stencil_effect(Joker *joker, Card *scored_card) { return effect; // if card != null, we are not at the end-phase of scoring yet // +1 xmult per empty joker slot... - int jokers_top = get_jokers_top(); - effect.xmult = (MAX_JOKERS_HELD_SIZE-1) - jokers_top; + int num_jokers = get_jokers_top() + 1; + + effect.xmult = (MAX_JOKERS_HELD_SIZE) - num_jokers; // ...and also each stencil_joker adds +1 xmult JokerObject** jokers = get_jokers(); - for (int i = 0; i < jokers_top; i++ ) + for (int i = 0; i < num_jokers; i++ ) { if (jokers[i]->joker->id == JOKER_STENCIL_ID) effect.xmult++; @@ -271,8 +274,8 @@ static JokerEffect blackboard_joker_effect(Joker *joker, Card *scored_card) { bool all_cards_are_spades_or_clubs = true; CardObject** hand = get_hand_array(); - int hand_top = get_hand_top(); - for (int i = 0; i < hand_top; i++ ) + int hand_size = hand_get_size(); + for (int i = 0; i < hand_size; i++ ) { u8 suit = hand[i]->card->suit; if (suit == HEARTS || suit == DIAMONDS) {