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