From 3c1fa0d0e4e15cd46f5faa0112d69fcc579d2066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 12 Jan 2024 17:39:51 +0100 Subject: [PATCH] Disable integrity checks by default This should speed up the program drastically --- include/game_state.hpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/include/game_state.hpp b/include/game_state.hpp index 67423b9..b289a6c 100644 --- a/include/game_state.hpp +++ b/include/game_state.hpp @@ -4,6 +4,16 @@ #include "myassert.h" #include "game_state.h" +/** + * Compiling with -DINTEGRITY_CHECK_ON will enable exhaustive integrity check while backtracking. + * These significantly slow down performance, so they are deactivated by default. + */ +#ifdef INTEGRITY_CHECK_ON +#define CHECK_DRAW_PILE_INTEGRITY check_draw_pile_integrity() +#else +#define CHECK_DRAW_PILE_INTEGRITY +#endif + namespace Hanabi { @@ -186,7 +196,7 @@ namespace Hanabi unsigned long HanabiState::play_and_potentially_update(hand_index_t index, bool cycle) { - check_draw_pile_integrity(); + CHECK_DRAW_PILE_INTEGRITY; ASSERT(index < _hands[_turn].size()); const Card played_card = _hands[_turn][index]; @@ -210,7 +220,7 @@ namespace Hanabi const unsigned long multiplicity = draw(index, cycle, !strike); incr_turn(); - check_draw_pile_integrity(); + CHECK_DRAW_PILE_INTEGRITY; return multiplicity; } @@ -224,7 +234,7 @@ namespace Hanabi unsigned long HanabiState::discard_and_potentially_update(hand_index_t index, bool cycle) { - check_draw_pile_integrity(); + CHECK_DRAW_PILE_INTEGRITY; ASSERT(index < _hands[_turn].size()); ASSERT(_num_clues != max_num_clues); @@ -238,7 +248,7 @@ namespace Hanabi _actions_log.emplace(ActionType::discard, discarded_card, index); incr_turn(); - check_draw_pile_integrity(); + CHECK_DRAW_PILE_INTEGRITY; return multiplicity; } @@ -589,7 +599,7 @@ namespace Hanabi void HanabiState::revert_play(bool cycle) { - check_draw_pile_integrity(); + CHECK_DRAW_PILE_INTEGRITY; const BacktrackAction last_action = _actions_log.top(); _actions_log.pop(); ASSERT(last_action.action_type == ActionType::play); @@ -609,13 +619,13 @@ namespace Hanabi // If we misplayed, then we lost the card and have to regain it now _num_copies_left[last_action.discarded]++; } - check_draw_pile_integrity(); + CHECK_DRAW_PILE_INTEGRITY; } template void HanabiState::revert_discard(bool cycle) { - check_draw_pile_integrity(); + CHECK_DRAW_PILE_INTEGRITY; const BacktrackAction last_action = _actions_log.top(); _actions_log.pop(); @@ -631,7 +641,7 @@ namespace Hanabi _num_copies_left[last_action.discarded]++; revert_draw(last_action.index, last_action.discarded, cycle, false); - check_draw_pile_integrity(); + CHECK_DRAW_PILE_INTEGRITY; } template @@ -1190,7 +1200,7 @@ namespace Hanabi // encode number of clues clue_t const scaled_clues = clue_t(2) * _num_clues; assert(scaled_clues.denominator() == 1); - ret.push_back((clue_t(2) * _num_clues).numerator()); + ret.push_back(scaled_clues.numerator()); // we can encode draw pile size and extra turn in one metric, since we only have extra turns if draw pile is empty const std::uint8_t draw_pile_size_and_extra_turns = [this]() -> uint8_t {