From 6f5419b2d877e8f095a055fa7e25f7d6494527ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sat, 11 Nov 2023 23:30:01 +0100 Subject: [PATCH] fix find_card_in_hand function: respect different representation of trash --- include/game_state.hpp | 13 +++++++------ src/main.cpp | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/game_state.hpp b/include/game_state.hpp index 0b3e78a..52717c3 100644 --- a/include/game_state.hpp +++ b/include/game_state.hpp @@ -256,12 +256,13 @@ namespace Hanabi { template std::uint8_t HanabiState::find_card_in_hand( const Hanabi::Card &card) const { - for (std::uint8_t i = 0; i < hand_size; i++) { - if (_hands[_turn][i].rank == card.rank && _hands[_turn][i].suit == card.suit) { - return i; - } - } - return -1; + auto it = std::find_if(_hands[_turn].begin(), _hands[_turn].end(),[&card, this](Card const & card_in_hand){ + return card_in_hand == card or (is_trash(card) and is_trash(card_in_hand)); + }); + if (it != _hands[_turn].end()) { + return std::distance(_hands[_turn].begin(), it); + } + return -1; } template diff --git a/src/main.cpp b/src/main.cpp index f1c57ca..2d66e07 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,7 @@ namespace Hanabi { game.goto_draw_pile_size(draw_pile_size); if (draw_pile_size != 0 and game.state->draw_pile_size() != static_cast(draw_pile_size)) { - std::cout << "This given draw pile size (" << draw_pile_size << ") cannot be obtained with the specified replay." << std::endl; + std::cout << "The given draw pile size (" << draw_pile_size << ") cannot be obtained with the specified replay." << std::endl; return; } game.state->modify_clues(clue_modifier); @@ -60,7 +60,7 @@ namespace Hanabi { for(size_t remaining_cards = 1; remaining_cards <= max_draw_pile_size; remaining_cards++) { if (!game.goto_draw_pile_size(remaining_cards)) { - std::cout << "This given draw pile size (" << remaining_cards << ") cannot be obtained with the specified replay." << std::endl; + std::cout << "The given draw pile size (" << remaining_cards << ") cannot be obtained with the specified replay." << std::endl; continue; }; if (all_clues) {