From a116ec45e34819dfdd72ccb7105d014b06c47fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 11 Aug 2023 12:12:09 +0200 Subject: [PATCH] simplify play card logic: always consider bombs --- game_state.h | 2 +- game_state.hpp | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/game_state.h b/game_state.h index 8f74732..7a483de 100644 --- a/game_state.h +++ b/game_state.h @@ -211,7 +211,7 @@ protected: void print(std::ostream& os) const final; private: - struct BacktrackAction { + struct BacktrackAction { explicit BacktrackAction( ActionType action_type, Card discarded_or_played = unknown_card, diff --git a/game_state.hpp b/game_state.hpp index 2900649..40c7c4f 100644 --- a/game_state.hpp +++ b/game_state.hpp @@ -143,12 +143,6 @@ namespace Hanabi { template void HanabiState::play(Hanabi::hand_index_t index) { - const Card card = _hands[_turn][index]; - if (!is_playable(card)) { - draw(index); - incr_turn(); - return; - } play_and_potentially_update(index); } @@ -157,6 +151,11 @@ namespace Hanabi { unsigned long HanabiState::play_and_potentially_update(hand_index_t index) { ASSERT(index < _hands[_turn].size()); const Card played_card = _hands[_turn][index]; + if (!is_playable(played_card)) { + const unsigned long multiplicity = draw(index); + incr_turn(); + return multiplicity; + } ASSERT(is_playable(played_card)); _actions_log.emplace(ActionType::play, played_card, index, _num_clues == 8); @@ -169,7 +168,7 @@ namespace Hanabi { _num_clues++; } - unsigned long multiplicity = draw(index); + const unsigned long multiplicity = draw(index); incr_turn(); return multiplicity; @@ -403,7 +402,9 @@ namespace Hanabi { _num_clues--; } revert_draw(last_action.index, last_action.discarded); - _stacks[last_action.discarded.suit]++; + if(_stacks[last_action.discarded.suit] == last_action.discarded.rank) { + _stacks[last_action.discarded.suit]++; + } _score--; }