fix find_card_in_hand function: respect different representation of trash
This commit is contained in:
parent
0a8facb585
commit
6f5419b2d8
2 changed files with 9 additions and 8 deletions
|
@ -256,12 +256,13 @@ namespace Hanabi {
|
|||
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(
|
||||
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<suit_t num_suits, player_t num_players, hand_index_t hand_size>
|
||||
|
|
|
@ -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<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;
|
||||
}
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue