[Refactor] Separate Round logic into its own file (#570)
* Everything works, need to clean up * cleanup * fix rebase issue * clang format * docs * clang format * clang format * address part of review * Protect against edge case when discarding at end of hand * Protect undiscard against popping a discarded card that doesn't exist * Protect against out of bounds access to the `played` cards stack * fix condition in `select_four_of_a_kind_cards_in_played_hand` * change `get_played_top() + 1` to `get_played_size()` * move `can_play/discard_hand` functions to round.c --------- Co-authored-by: MathisMartin31 <mathis.martin31@gmail.com>
This commit is contained in:
+3
-32
@@ -9,6 +9,7 @@
|
||||
#include "audio_utils.h"
|
||||
#include "card.h"
|
||||
#include "game.h"
|
||||
#include "game/round.h"
|
||||
#include "game_variables.h"
|
||||
#include "graphic_utils.h"
|
||||
#include "soundbank.h"
|
||||
@@ -150,8 +151,8 @@ void compute_hand_value_info(void)
|
||||
|
||||
HandValues hand_values = hand_base_values[hand.hand_type];
|
||||
|
||||
set_chips(hand_values.chips);
|
||||
set_mult(hand_values.mult);
|
||||
g_game_vars.chips = hand_values.chips;
|
||||
g_game_vars.mult = hand_values.mult;
|
||||
|
||||
print_hand_type(hand_values.display_name);
|
||||
display_chips();
|
||||
@@ -356,36 +357,6 @@ static void get_hand_distribution(u8 ranks_out[NUM_RANKS], u8 suits_out[NUM_SUIT
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
GBAL_UNUSED
|
||||
static 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;
|
||||
for (int i = 0; i < NUM_SUITS; i++)
|
||||
suits_out[i] = 0;
|
||||
|
||||
CardObject** played = get_played_array();
|
||||
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]++;
|
||||
suits_out[played[i]->card->suit]++;
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the highest N of a kind. So a full-house would return 3.
|
||||
static u8 hand_contains_n_of_a_kind(u8* ranks)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user