diff --git a/include/hand_analysis.h b/include/hand_analysis.h index 4b7f2ec..78e3756 100644 --- a/include/hand_analysis.h +++ b/include/hand_analysis.h @@ -5,8 +5,23 @@ #include -void get_hand_distribution(u8* ranks_out, u8* suits_out); -void get_played_distribution(u8* ranks_out, u8* suits_out); +/** + * @brief Outputs the distribution of ranks and suits in the hand + * @param ranks_out output - updated such as ranks_out[rank] is the number of cards of rank in the + * hand. Must be of size NUM_RANKS. + * @param suits_out output - updated such as suits_out[suit] is the number of cards if suit in the + * hand Must be of size NUM_SUITS + */ +void get_hand_distribution(u8 ranks_out[NUM_RANKS], u8 suits_out[NUM_SUITS]); + +/** + * @brief Outputs the distribution of ranks and suits in the played stack + * @param ranks_out output - updated such as ranks_out[rank] is the number of cards of rank in the + * played stack. Must be of size NUM_RANKS. + * @param suits_out output - updated such as suits_out[suit] is the number of cards if suit in the + * played stack. Must be of size NUM_SUITS + */ +void get_played_distribution(u8 ranks_out[NUM_RANKS], u8 suits_out[NUM_SUITS]); u8 hand_contains_n_of_a_kind(u8* ranks); bool hand_contains_two_pair(u8* ranks); diff --git a/source/hand_analysis.c b/source/hand_analysis.c index 998a736..250da47 100644 --- a/source/hand_analysis.c +++ b/source/hand_analysis.c @@ -3,7 +3,7 @@ #include "card.h" #include "game.h" -void get_hand_distribution(u8* ranks_out, u8* suits_out) +void get_hand_distribution(u8 ranks_out[NUM_RANKS], u8 suits_out[NUM_SUITS]) { for (int i = 0; i < NUM_RANKS; i++) ranks_out[i] = 0; @@ -22,7 +22,7 @@ void get_hand_distribution(u8* ranks_out, u8* suits_out) } } -void get_played_distribution(u8* ranks_out, u8* suits_out) +void get_played_distribution(u8 ranks_out[NUM_RANKS], u8 suits_out[NUM_SUITS]) { for (int i = 0; i < NUM_RANKS; i++) ranks_out[i] = 0; @@ -33,6 +33,10 @@ void get_played_distribution(u8* ranks_out, u8* suits_out) int top = get_played_top(); for (int i = 0; i <= top; i++) { + /* The difference from get_hand_distribution() (not checking if card is selected) + * is in line Balatro behavior, + * see https://github.com/GBALATRO/balatro-gba/issues/341#issuecomment-3691363488 + */ if (!played[i]) continue; ranks_out[played[i]->card->rank]++;