add more checks: same draw pile after reverting single moves (bug detected)

This commit is contained in:
Maximilian Keßler 2023-11-11 12:41:14 +01:00
parent 1266791750
commit a3972fe637
Signed by: max
GPG Key ID: BCC5A619923C0BA5
3 changed files with 19 additions and 6 deletions

View File

@ -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<CardMultiplicity> 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<CardMultiplicity> draw_pile;
};
// This keeps track of the representation of the gamestate relative to some starting state

View File

@ -103,12 +103,12 @@ namespace Hanabi {
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
HanabiState<num_suits, num_players, hand_size>::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<CardMultiplicity> 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<suit_t num_suits, player_t num_players, hand_index_t hand_size>
@ -208,6 +208,7 @@ namespace Hanabi {
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
unsigned long HanabiState<num_suits, num_players, hand_size>::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<suit_t num_suits, player_t num_players, hand_index_t hand_size>
unsigned long HanabiState<num_suits, num_players, hand_size>::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();
}

View File

@ -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