From 0313160bd119337ff1fe5c8cf420ce5b91fe4c71 Mon Sep 17 00:00:00 2001 From: Diogo Medeiros Date: Wed, 3 Apr 2024 08:05:54 +0100 Subject: [PATCH] Bug fix --- src/hanabi/bot.c | 4 +++- src/hanabi/deck.c | 11 +++++++---- src/hanabi/deck.h | 7 ++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/hanabi/bot.c b/src/hanabi/bot.c index 33dc92a..2f04e59 100644 --- a/src/hanabi/bot.c +++ b/src/hanabi/bot.c @@ -59,7 +59,9 @@ uint32_t get_bot_playable(const hand_t *const hand, const deck_t *const deck) { if (!card->number_known) { continue; } - if (is_playable(deck, card) && (is_table(deck) || card->color_known)) { + const bool playable = is_playable(deck, card); + const bool fireworks_at_table = is_fireworks_at_table(deck, card->number - 1); + if (playable && (fireworks_at_table || card->color_known)) { return i; } } diff --git a/src/hanabi/deck.c b/src/hanabi/deck.c index 83249a5..5b1d927 100644 --- a/src/hanabi/deck.c +++ b/src/hanabi/deck.c @@ -112,13 +112,16 @@ int get_lowest_table(const deck_t *const deck) { return min; } -bool is_table(const deck_t *const deck) { +bool is_fireworks_at_table(const deck_t *deck, int table) { for (int i = 1; i < COLORS; i++) { - if (deck->fireworks[i - 1] == deck->fireworks[i]) { - return true; + if (deck->fireworks[i - 1] != deck->fireworks[i]) { + return false; + } + if (deck->fireworks[i] != table) { + return false; } } - return false; + return true; } cJSON *get_deck_json(const deck_t *const deck) { diff --git a/src/hanabi/deck.h b/src/hanabi/deck.h index c9c7ab9..80b0efe 100644 --- a/src/hanabi/deck.h +++ b/src/hanabi/deck.h @@ -50,10 +50,11 @@ int get_score(const deck_t *deck); /// \return The lowest table. int get_lowest_table(const deck_t *deck); -/// Returns whether the deck is a table (all fireworks are at 5). +/// Returns whether the fireworks are at the given table. /// \param deck The deck. -/// \return Whether the deck is a table. -bool is_table(const deck_t *deck); +/// \param table The table. +/// \return Whether the fireworks are at the given table. +bool is_fireworks_at_table(const deck_t *deck, int table); /// Plays a card from the hand. /// \param deck The deck.