bugfix: correctly revert manual cases even when rotate_next_draw was used

This commit is contained in:
Maximilian Keßler 2023-11-11 13:28:43 +01:00
parent b9b73406f2
commit ab31588dbb
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -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});
}
}