fix find_card_in_hand function: respect different representation of trash

This commit is contained in:
Maximilian Keßler 2023-11-11 23:30:01 +01:00
parent 0a8facb585
commit 6f5419b2d8
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 9 additions and 8 deletions

View file

@ -256,12 +256,13 @@ namespace Hanabi {
template<suit_t num_suits, player_t num_players, hand_index_t hand_size> template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
std::uint8_t HanabiState<num_suits, num_players, hand_size>::find_card_in_hand( std::uint8_t HanabiState<num_suits, num_players, hand_size>::find_card_in_hand(
const Hanabi::Card &card) const { const Hanabi::Card &card) const {
for (std::uint8_t i = 0; i < hand_size; i++) { auto it = std::find_if(_hands[_turn].begin(), _hands[_turn].end(),[&card, this](Card const & card_in_hand){
if (_hands[_turn][i].rank == card.rank && _hands[_turn][i].suit == card.suit) { return card_in_hand == card or (is_trash(card) and is_trash(card_in_hand));
return i; });
} if (it != _hands[_turn].end()) {
} return std::distance(_hands[_turn].begin(), it);
return -1; }
return -1;
} }
template<suit_t num_suits, player_t num_players, hand_index_t hand_size> template<suit_t num_suits, player_t num_players, hand_index_t hand_size>

View file

@ -25,7 +25,7 @@ namespace Hanabi {
game.goto_draw_pile_size(draw_pile_size); game.goto_draw_pile_size(draw_pile_size);
if (draw_pile_size != 0 and game.state->draw_pile_size() != static_cast<size_t>(draw_pile_size)) { if (draw_pile_size != 0 and game.state->draw_pile_size() != static_cast<size_t>(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; return;
} }
game.state->modify_clues(clue_modifier); 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++) { for(size_t remaining_cards = 1; remaining_cards <= max_draw_pile_size; remaining_cards++) {
if (!game.goto_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; continue;
}; };
if (all_clues) { if (all_clues) {