From ab31588dbb89e90f011abd29d1e2032888f3db97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sat, 11 Nov 2023 13:28:43 +0100 Subject: [PATCH] bugfix: correctly revert manual cases even when rotate_next_draw was used --- include/game_state.hpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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}); } }