diff --git a/include/game_state.hpp b/include/game_state.hpp index 293858b..296d0ad 100644 --- a/include/game_state.hpp +++ b/include/game_state.hpp @@ -386,10 +386,18 @@ namespace Hanabi { } } else { - if (!_draw_pile.empty() and _draw_pile.front().card.suit == drawn.suit and - _draw_pile.front().card.rank == drawn.rank) { - _draw_pile.front().multiplicity++; - } else { + // We don't know where the card came from (between the card having been removed from the draw pile + // and re-adding it now, the user may have arbitrarily permuted the draw pile implicitly) + // so we have to check if it is already contained in the draw pile somewhere + auto it = std::find_if(_draw_pile.begin(), _draw_pile.end(), [&drawn](CardMultiplicity const & mult){ + return mult.card == drawn; + }); + if (it != _draw_pile.end()) + { + it->multiplicity++; + } + else + { _draw_pile.push_front({drawn, 1}); } }