GBAlatro
A Demake of Balatro for the GBA
Loading...
Searching...
No Matches
hand.h
Go to the documentation of this file.
1
7#ifndef HAND_H
8#define HAND_H
9
10#include "card.h"
11
12#include <tonc.h>
13
14#define MAX_HAND_SIZE 16
15
16enum HandState
17{
18 HAND_DRAW,
19 HAND_SELECT,
20 // This is actually a misnomer because it's used for the deck
21 // but it mechanically makes sense to be a state of the hand
22 HAND_SHUFFLING,
23 HAND_DISCARD,
24 HAND_PLAY,
25 HAND_PLAYING
26};
27
28enum HandType
29{
30 NONE,
31 HIGH_CARD,
32 PAIR,
33 TWO_PAIR,
34 THREE_OF_A_KIND,
35 STRAIGHT,
36 FLUSH,
37 FULL_HOUSE,
38 FOUR_OF_A_KIND,
39 STRAIGHT_FLUSH,
40 ROYAL_FLUSH,
41 FIVE_OF_A_KIND,
42 FLUSH_HOUSE,
43 FLUSH_FIVE,
44 HAND_TYPE_MAX = FLUSH_FIVE
45};
46
47// clang-format off
48// Store all contained hands to optimize "whole hand condition" Jokers
49typedef struct ContainedHandTypes
50{
51 union
52 {
53 struct
54 {
55 u16 HIGH_CARD : 1;
56 u16 PAIR : 1;
57 u16 TWO_PAIR : 1;
58 u16 THREE_OF_A_KIND : 1;
59 u16 STRAIGHT : 1;
60 u16 FLUSH : 1;
61 u16 FULL_HOUSE : 1;
62 u16 FOUR_OF_A_KIND : 1;
63 u16 STRAIGHT_FLUSH : 1;
64 u16 ROYAL_FLUSH : 1;
65 u16 FIVE_OF_A_KIND : 1;
66 u16 FLUSH_HOUSE : 1;
67 u16 FLUSH_FIVE : 1;
68 u16 : 3;
69 };
70 u16 value;
71 };
73// clang-format on
74
75// Misc Hand Functions
76
77const char* get_hand_type_name(enum HandType hand_type);
78
79// Hand Structure Manipulation
80
86void set_hand_state(enum HandState);
87
95enum HandState get_hand_state(void);
96
101void compute_hand_value_info(void);
102
110enum HandType get_hand_type(void);
111
120
127
135int get_hand_top(void);
136
144void set_hand_top(int new_hand_top);
145
153int hand_nb_held_cards(void);
154
161
169void hand_set_nb_selected_cards(int new_selections);
170
176void hand_select_card(int index);
177
187void hand_change_sort(bool to_sort_by_suit);
188
192void hand_deselect_all_cards(void);
193
200void swap_cards_in_hand(int idx_a, int idx_b);
201
208
214void sort_cards(void);
215
216// Hand Contents Analysis
217
235int find_flush_in_played_cards(CardObject** played, int top, int min_len, bool* out_selection);
236
255int find_straight_in_played_cards(CardObject** played, int top, int min_len, bool* out_selection);
256
266void select_paired_cards_in_hand(CardObject** played, int top, bool* selection);
267
268#endif
void set_hand_state(enum HandState)
Set the hand state. Primarily used by the GAME_PLAYING game state.
Definition hand.c:95
void hand_set_nb_selected_cards(int new_selections)
Set the current number of selected Cards.
Definition hand.c:125
ContainedHandTypes * get_contained_hands(void)
Get the contained hands within the selected hand.
Definition hand.c:135
int find_flush_in_played_cards(CardObject **played, int top, int min_len, bool *out_selection)
Finds the best flush (set of cards with the same suit) in the given array of played cards.
Definition hand.c:544
enum HandType get_hand_type(void)
Get the current hand type.
Definition hand.c:130
int get_hand_top(void)
Get the position in hand array of the last card obtained.
Definition hand.c:105
enum HandState get_hand_state(void)
Get the hand state.
Definition hand.c:90
void swap_cards_in_hand(int idx_a, int idx_b)
Swaps the order of two cards in hand.
Definition hand.c:174
int find_straight_in_played_cards(CardObject **played, int top, int min_len, bool *out_selection)
Finds the best straight in the given array of played cards.
Definition hand.c:587
CardObject ** get_hand_array(void)
Get the hand array of Cards currently held in hand.
Definition hand.c:100
int hand_get_nb_selected_cards(void)
Get the current number of selected Cards.
Definition hand.c:120
void select_paired_cards_in_hand(CardObject **played, int top, bool *selection)
This is used for the special case in "Four Fingers" where you can add a pair into a straight (e....
Definition hand.c:731
void reorder_card_sprites_layers(void)
Destroy the sprites of the Cards held in hand and recreate then in the same order as the Cards in the...
Definition hand.c:244
void set_hand_top(int new_hand_top)
Set the position in hand array of the last card obtained.
Definition hand.c:110
void hand_select_card(int index)
Set the card at a given index in Hand as selected.
Definition hand.c:303
void hand_change_sort(bool to_sort_by_suit)
Switch to the given sort method. Can sort playing cards in two ways: by rank and suit....
Definition hand.c:294
void compute_hand_value_info(void)
Determine the HandType and ContainedHandTypes of the currently selected Cards, then print the Hand's ...
Definition hand.c:156
void sort_cards(void)
Sort the hand array according to the selected method to do that.
Definition hand.c:280
void hand_deselect_all_cards(void)
Deselect all cards in hand.
Definition hand.c:324
int hand_nb_held_cards(void)
Get the current number of Cards in hand.
Definition hand.c:115