From a3972fe637894b4a1df46d3796261ce5899b047f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sat, 11 Nov 2023 12:41:14 +0100 Subject: [PATCH] add more checks: same draw pile after reverting single moves (bug detected) --- include/game_state.h | 5 ++++- include/game_state.hpp | 18 ++++++++++++++---- include/myassert.h | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/include/game_state.h b/include/game_state.h index 79fe805..3e5a5ff 100644 --- a/include/game_state.h +++ b/include/game_state.h @@ -326,7 +326,8 @@ private: ActionType action_type, Card discarded_or_played = Cards::unknown, hand_index_t index = 0, - bool was_on_8_clues = false + bool was_on_8_clues = false, + std::list draw_pile = {} ); ActionType action_type{}; @@ -338,6 +339,8 @@ private: // Indicates whether before the action was taken, we had 8 clues. // This is important so that we know if we go back to 7 or 8 clues when we revert playing a 5 bool was_on_8_clues {false}; + + std::list draw_pile; }; // This keeps track of the representation of the gamestate relative to some starting state diff --git a/include/game_state.hpp b/include/game_state.hpp index ee4060c..e5c781d 100644 --- a/include/game_state.hpp +++ b/include/game_state.hpp @@ -103,12 +103,12 @@ namespace Hanabi { template HanabiState::BacktrackAction::BacktrackAction( Hanabi::ActionType action_type, Hanabi::Card discarded_or_played, Hanabi::hand_index_t index, - bool was_on_8_clues + bool was_on_8_clues, std::list draw_pile ): action_type(action_type), discarded(discarded_or_played), index(index), - was_on_8_clues(was_on_8_clues) { + was_on_8_clues(was_on_8_clues), draw_pile(std::move(draw_pile)) { } template @@ -208,6 +208,7 @@ namespace Hanabi { template unsigned long HanabiState::play_and_potentially_update(hand_index_t index) { check_draw_pile_integrity(); + auto copy = _draw_pile; ASSERT(index < _hands[_turn].size()); const Card played_card = _hands[_turn][index]; if (!is_playable(played_card)) { @@ -217,7 +218,7 @@ namespace Hanabi { } ASSERT(is_playable(played_card)); - _actions_log.emplace(ActionType::play, played_card, index, _num_clues == 8); + _actions_log.emplace(ActionType::play, played_card, index, _num_clues == 8, copy); --_stacks[played_card.suit]; _score++; @@ -242,6 +243,7 @@ namespace Hanabi { template unsigned long HanabiState::discard_and_potentially_update(hand_index_t index) { check_draw_pile_integrity(); + auto copy = _draw_pile; ASSERT(index < _hands[_turn].size()); ASSERT(_num_clues != max_num_clues); @@ -250,7 +252,7 @@ namespace Hanabi { _pace--; unsigned long multiplicity = draw(index); - _actions_log.emplace(ActionType::discard, discarded_card, index); + _actions_log.emplace(ActionType::discard, discarded_card, index, false, copy); incr_turn(); check_draw_pile_integrity(); @@ -500,6 +502,10 @@ namespace Hanabi { _stacks[last_action.discarded.suit]++; } _score--; + if (not cycle) + { + ASSERT(last_action.draw_pile == _draw_pile); + } check_draw_pile_integrity(); } @@ -518,6 +524,10 @@ namespace Hanabi { _pace++; revert_draw(last_action.index, last_action.discarded, cycle); + if (not cycle) + { + ASSERT(last_action.draw_pile == _draw_pile); + } check_draw_pile_integrity(); } diff --git a/include/myassert.h b/include/myassert.h index 174f12f..d854d0e 100644 --- a/include/myassert.h +++ b/include/myassert.h @@ -1,6 +1,6 @@ #ifndef DYNAMIC_PROGRAM_MYASSERT_H #define DYNAMIC_PROGRAM_MYASSERT_H - +#undef NDEBUG #ifdef NDEBUG #define ASSERT(x) do { (void)sizeof(x);} while (0) #else