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
14enum HandState
15{
16 HAND_TAGS,
17 HAND_DRAW,
18 HAND_SELECT,
19 // This is actually a misnomer because it's used for the deck
20 // but it mechanically makes sense to be a state of the hand
21 HAND_SHUFFLING,
22 HAND_DISCARD,
23 HAND_PLAY,
24 HAND_PLAYING
25};
26
27enum HandType
28{
29 NONE,
30 HIGH_CARD,
31 PAIR,
32 TWO_PAIR,
33 THREE_OF_A_KIND,
34 STRAIGHT,
35 FLUSH,
36 FULL_HOUSE,
37 FOUR_OF_A_KIND,
38 STRAIGHT_FLUSH,
39 ROYAL_FLUSH,
40 FIVE_OF_A_KIND,
41 FLUSH_HOUSE,
42 FLUSH_FIVE,
43 HAND_TYPE_MAX = FLUSH_FIVE
44};
45
46// clang-format off
47// Store all contained hands to optimize "whole hand condition" Jokers
48typedef struct ContainedHandTypes
49{
50 union
51 {
52 struct
53 {
54 u16 HIGH_CARD : 1;
55 u16 PAIR : 1;
56 u16 TWO_PAIR : 1;
57 u16 THREE_OF_A_KIND : 1;
58 u16 STRAIGHT : 1;
59 u16 FLUSH : 1;
60 u16 FULL_HOUSE : 1;
61 u16 FOUR_OF_A_KIND : 1;
62 u16 STRAIGHT_FLUSH : 1;
63 u16 ROYAL_FLUSH : 1;
64 u16 FIVE_OF_A_KIND : 1;
65 u16 FLUSH_HOUSE : 1;
66 u16 FLUSH_FIVE : 1;
67 u16 : 3;
68 };
69 u16 value;
70 };
72// clang-format on
73
74// Misc Hand Functions
75
76const char* get_hand_type_name(enum HandType hand_type);
77
78// Hand Structure Manipulation
79
85void set_hand_state(enum HandState);
86
94enum HandState get_hand_state(void);
95
100void compute_hand_value_info(void);
101
109enum HandType get_hand_type(void);
110
119
126
134int get_hand_top(void);
135
143void set_hand_top(int new_hand_top);
144
152int hand_nb_held_cards(void);
153
160
168void hand_set_nb_selected_cards(int new_selections);
169
175void hand_select_card(int index);
176
186void hand_change_sort(bool to_sort_by_suit);
187
191void hand_deselect_all_cards(void);
192
199void swap_cards_in_hand(int idx_a, int idx_b);
200
207
213void sort_cards(void);
214
215// Hand Contents Analysis
216
234int find_flush_in_played_cards(CardObject** played, int top, int min_len, bool* out_selection);
235
254int find_straight_in_played_cards(CardObject** played, int top, int min_len, bool* out_selection);
255
265void select_paired_cards_in_hand(CardObject** played, int top, bool* selection);
266
267#endif
void set_hand_state(enum HandState)
Set the hand state. Primarily used by the GAME_PLAYING game state.
Definition hand.c:96
void hand_set_nb_selected_cards(int new_selections)
Set the current number of selected Cards.
Definition hand.c:126
ContainedHandTypes * get_contained_hands(void)
Get the contained hands within the selected hand.
Definition hand.c:136
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:545
enum HandType get_hand_type(void)
Get the current hand type.
Definition hand.c:131
int get_hand_top(void)
Get the position in hand array of the last card obtained.
Definition hand.c:106
enum HandState get_hand_state(void)
Get the hand state.
Definition hand.c:91
void swap_cards_in_hand(int idx_a, int idx_b)
Swaps the order of two cards in hand.
Definition hand.c:175
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:588
CardObject ** get_hand_array(void)
Get the hand array of Cards currently held in hand.
Definition hand.c:101
int hand_get_nb_selected_cards(void)
Get the current number of selected Cards.
Definition hand.c:121
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:732
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:245
void set_hand_top(int new_hand_top)
Set the position in hand array of the last card obtained.
Definition hand.c:111
void hand_select_card(int index)
Set the card at a given index in Hand as selected.
Definition hand.c:304
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:295
void compute_hand_value_info(void)
Determine the HandType and ContainedHandTypes of the currently selected Cards, then print the Hand's ...
Definition hand.c:157
void sort_cards(void)
Sort the hand array according to the selected method to do that.
Definition hand.c:281
void hand_deselect_all_cards(void)
Deselect all cards in hand.
Definition hand.c:325
int hand_nb_held_cards(void)
Get the current number of Cards in hand.
Definition hand.c:116