Optimize "whole hand" conditions checks for Joker effects (#213)

* Introduce a ContainedHandTypes type

* Separate computing of hand_type and _contained_hand_types variables

---------

Co-authored-by: MathisMartin31 <mathis.martin31@gmail.com>
This commit is contained in:
Geralt
2026-01-22 14:22:48 +02:00
committed by GitHub
co-authored by MathisMartin31
parent 8e1867d235
commit 02799ddc54
3 changed files with 193 additions and 182 deletions
+15 -79
View File
@@ -516,12 +516,8 @@ static u32 jolly_joker_effect(
SCORE_ON_EVENT_ONLY(JOKER_EVENT_INDEPENDENT, joker_event)
u32 effect_flags_ret = JOKER_EFFECT_FLAG_NONE;
// 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)
if (get_contained_hands()->PAIR)
{
*joker_effect = &shared_joker_effect;
@@ -543,12 +539,7 @@ static u32 zany_joker_effect(
u32 effect_flags_ret = JOKER_EFFECT_FLAG_NONE;
// 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) >= 3)
if (get_contained_hands()->THREE_OF_A_KIND)
{
*joker_effect = &shared_joker_effect;
@@ -570,11 +561,7 @@ static u32 mad_joker_effect(
u32 effect_flags_ret = JOKER_EFFECT_FLAG_NONE;
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_two_pair(ranks))
if (get_contained_hands()->TWO_PAIR)
{
*joker_effect = &shared_joker_effect;
@@ -596,11 +583,7 @@ static u32 crazy_joker_effect(
u32 effect_flags_ret = JOKER_EFFECT_FLAG_NONE;
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_straight(ranks))
if (get_contained_hands()->STRAIGHT)
{
*joker_effect = &shared_joker_effect;
@@ -622,11 +605,7 @@ static u32 droll_joker_effect(
u32 effect_flags_ret = JOKER_EFFECT_FLAG_NONE;
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_flush(suits))
if (get_contained_hands()->FLUSH)
{
*joker_effect = &shared_joker_effect;
@@ -648,11 +627,7 @@ static u32 sly_joker_effect(
u32 effect_flags_ret = JOKER_EFFECT_FLAG_NONE;
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_n_of_a_kind(ranks) >= 2)
if (get_contained_hands()->PAIR)
{
*joker_effect = &shared_joker_effect;
@@ -674,11 +649,7 @@ static u32 wily_joker_effect(
u32 effect_flags_ret = JOKER_EFFECT_FLAG_NONE;
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_n_of_a_kind(ranks) >= 3)
if (get_contained_hands()->THREE_OF_A_KIND)
{
*joker_effect = &shared_joker_effect;
@@ -700,11 +671,7 @@ static u32 clever_joker_effect(
u32 effect_flags_ret = JOKER_EFFECT_FLAG_NONE;
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_two_pair(ranks))
if (get_contained_hands()->TWO_PAIR)
{
*joker_effect = &shared_joker_effect;
@@ -726,11 +693,7 @@ static u32 devious_joker_effect(
u32 effect_flags_ret = JOKER_EFFECT_FLAG_NONE;
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_straight(ranks))
if (get_contained_hands()->STRAIGHT)
{
*joker_effect = &shared_joker_effect;
@@ -752,11 +715,7 @@ static u32 crafty_joker_effect(
u32 effect_flags_ret = JOKER_EFFECT_FLAG_NONE;
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_flush(suits))
if (get_contained_hands()->FLUSH)
{
*joker_effect = &shared_joker_effect;
@@ -1314,12 +1273,7 @@ static u32 the_duo_joker_effect(
u32 effect_flags_ret = JOKER_EFFECT_FLAG_NONE;
// 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)
if (get_contained_hands()->PAIR)
{
*joker_effect = &shared_joker_effect;
@@ -1341,12 +1295,7 @@ static u32 the_trio_joker_effect(
u32 effect_flags_ret = JOKER_EFFECT_FLAG_NONE;
// 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) >= 3)
if (get_contained_hands()->THREE_OF_A_KIND)
{
*joker_effect = &shared_joker_effect;
@@ -1368,12 +1317,7 @@ static u32 the_family_joker_effect(
u32 effect_flags_ret = JOKER_EFFECT_FLAG_NONE;
// 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) >= 4)
if (get_contained_hands()->FOUR_OF_A_KIND)
{
*joker_effect = &shared_joker_effect;
@@ -1395,11 +1339,7 @@ static u32 the_order_joker_effect(
u32 effect_flags_ret = JOKER_EFFECT_FLAG_NONE;
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_straight(ranks))
if (get_contained_hands()->STRAIGHT)
{
*joker_effect = &shared_joker_effect;
@@ -1421,11 +1361,7 @@ static u32 the_tribe_joker_effect(
u32 effect_flags_ret = JOKER_EFFECT_FLAG_NONE;
u8 suits[NUM_SUITS];
u8 ranks[NUM_RANKS];
get_played_distribution(ranks, suits);
if (hand_contains_flush(suits))
if (get_contained_hands()->FLUSH)
{
*joker_effect = &shared_joker_effect;