adds jokers 6-16. Extract hand type detection logic from hand_get_type to be used by jokers as well

This commit is contained in:
theturtlemafia
2025-07-28 18:27:48 -04:00
parent 095fb455cc
commit a72458c2c3
6 changed files with 332 additions and 98 deletions
+164
View File
@@ -1,5 +1,6 @@
#include "joker.h"
#include "util.h"
#include "hand_analysis.h"
static JokerEffect default_joker_effect(Joker *joker, Card *scored_card) {
@@ -31,12 +32,175 @@ static JokerEffect gluttonous_joker_effect(Joker *joker, Card *scored_card) {
return sinful_joker_effect(scored_card, CLUBS);
}
static JokerEffect jolly_joker_effect(Joker *joker, Card *scored_card) {
JokerEffect effect = {0};
if (scored_card != NULL)
return effect; // if card != null, we are not at the end-phase of scoring yet
// This is really inefficient but the only way at the moment to check for whole-hand conditions
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_n_of_a_kind(ranks) >= 2)
effect.mult = 8;
return effect;
}
static JokerEffect zany_joker_effect(Joker *joker, Card *scored_card) {
JokerEffect effect = {0};
if (scored_card != NULL)
return effect; // if card != null, we are not at the end-phase of scoring yet
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_n_of_a_kind(ranks) >= 3)
effect.mult = 12;
return effect;
}
static JokerEffect mad_joker_effect(Joker *joker, Card *scored_card) {
JokerEffect effect = {0};
if (scored_card != NULL)
return effect; // if card != null, we are not at the end-phase of scoring yet
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_two_pair(ranks))
effect.mult = 10;
return effect;
}
static JokerEffect crazy_joker_effect(Joker *joker, Card *scored_card) {
JokerEffect effect = {0};
if (scored_card != NULL)
return effect; // if card != null, we are not at the end-phase of scoring yet
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_straight(ranks))
effect.mult = 12;
return effect;
}
static JokerEffect droll_joker_effect(Joker *joker, Card *scored_card) {
JokerEffect effect = {0};
if (scored_card != NULL)
return effect; // if card != null, we are not at the end-phase of scoring yet
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_flush(suits))
effect.mult = 10;
return effect;
}
static JokerEffect sly_joker_effect(Joker *joker, Card *scored_card) {
JokerEffect effect = {0};
if (scored_card != NULL)
return effect; // if card != null, we are not at the end-phase of scoring yet
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_n_of_a_kind(ranks) >= 2)
effect.chips = 50;
return effect;
}
static JokerEffect wily_joker_effect(Joker *joker, Card *scored_card) {
JokerEffect effect = {0};
if (scored_card != NULL)
return effect; // if card != null, we are not at the end-phase of scoring yet
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_n_of_a_kind(ranks) >= 3)
effect.chips = 100;
return effect;
}
static JokerEffect clever_joker_effect(Joker *joker, Card *scored_card) {
JokerEffect effect = {0};
if (scored_card != NULL)
return effect; // if card != null, we are not at the end-phase of scoring yet
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_two_pair(ranks))
effect.chips = 80;
return effect;
}
static JokerEffect devious_joker_effect(Joker *joker, Card *scored_card) {
JokerEffect effect = {0};
if (scored_card != NULL)
return effect; // if card != null, we are not at the end-phase of scoring yet
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_straight(ranks))
effect.chips = 100;
return effect;
}
static JokerEffect crafty_joker_effect(Joker *joker, Card *scored_card) {
JokerEffect effect = {0};
if (scored_card != NULL)
return effect; // if card != null, we are not at the end-phase of scoring yet
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_flush(suits))
effect.chips = 80;
return effect;
}
static JokerEffect half_joker_effect(Joker *joker, Card *scored_card) {
JokerEffect effect = {0};
if (scored_card != NULL)
return effect; // if card != null, we are not at the end-phase of scoring yet
if (get_hand_top() + 1 <= 3) // game.c has hand_get_size() but it's not accesible here
effect.mult = 20;
return effect;
}
const JokerInfo joker_registry[] = {
{ COMMON_JOKER, 2, default_joker_effect }, // DEFAULT_JOKER_ID = 0
{ COMMON_JOKER, 5, greedy_joker_effect }, // GREEDY_JOKER_ID = 1
{ COMMON_JOKER, 5, lusty_joker_effect }, // etc...
{ COMMON_JOKER, 5, wrathful_joker_effect },
{ COMMON_JOKER, 5, gluttonous_joker_effect },
{ COMMON_JOKER, 3, jolly_joker_effect },
{ COMMON_JOKER, 4, zany_joker_effect },
{ COMMON_JOKER, 4, mad_joker_effect },
{ COMMON_JOKER, 4, crazy_joker_effect },
{ COMMON_JOKER, 4, droll_joker_effect },
{ COMMON_JOKER, 3, sly_joker_effect },
{ COMMON_JOKER, 4, wily_joker_effect },
{ COMMON_JOKER, 4, clever_joker_effect },
{ COMMON_JOKER, 4, devious_joker_effect },
{ COMMON_JOKER, 4, crafty_joker_effect },
{ COMMON_JOKER, 5, half_joker_effect },
};
static const size_t joker_registry_size = NUM_ELEM_IN_ARR(joker_registry);