Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Necas209 committed Apr 3, 2024
1 parent e4a4700 commit 0313160
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/hanabi/bot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/hanabi/deck.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions src/hanabi/deck.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0313160

Please sign in to comment.