From d95f40e2ae0aa701eb1ddc1e05d0ac5e24d10083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Tue, 8 Aug 2023 16:27:25 +0200 Subject: [PATCH] normalize positions if duplicates of cards have already been played --- CMakeLists.txt | 2 +- game_state.h | 1 + game_state.hpp | 15 ++++++++++++--- main.cpp | 6 +++--- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b21b5f4..50bc886 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,4 +16,4 @@ add_executable(dynamic_program main.cpp game_state.h) target_link_libraries(dynamic_program cpr) TARGET_LINK_LIBRARIES(dynamic_program Boost::program_options ) -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG") +#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG") diff --git a/game_state.h b/game_state.h index a0478d2..aa00b78 100644 --- a/game_state.h +++ b/game_state.h @@ -234,6 +234,7 @@ private: // This will save the card positions of all cards that are in the draw pile when we start backtracking // TODO: currently, we support at most 10 useful different cards in draw pile boost::container::static_vector, 10> _card_positions_draw; + boost::container::static_vector _good_cards_draw; // This will indicate whether cards that were in hands initially still are in hands std::bitset _card_positions_hands; diff --git a/game_state.hpp b/game_state.hpp index 1ac87db..44726d3 100644 --- a/game_state.hpp +++ b/game_state.hpp @@ -342,6 +342,7 @@ namespace Hanabi { _draw_pile.push_back({card, nums_in_draw_pile[card]}); if (!is_trash(card)) { _card_positions_draw.push_back({nums_in_draw_pile[card], draw_pile}); + _good_cards_draw.push_back(card); } } } @@ -510,10 +511,18 @@ namespace Hanabi { unsigned long id = 0; // encode all positions of cards that started in draw pile - for(const auto & positions: _card_positions_draw) { - for(player_t player : positions) { + ASSERT(_card_positions_draw.size() == _good_cards_draw.size()); + for(size_t i = 0; i < _card_positions_draw.size(); i++) { + for(player_t player : _card_positions_draw[i]) { id *= num_players + 2; - id += player; + // We normalize here: If a card is already played, then the positions of its other copies + // do not matter, so we can just pretend that they are all in the trash already. + // The resulting states will be equivalent. + if (!is_trash(_good_cards_draw[i])) { + id += player; + } else { + id += trash_or_play_stack; + } } } diff --git a/main.cpp b/main.cpp index e5e6f69..5ec5d7e 100644 --- a/main.cpp +++ b/main.cpp @@ -51,7 +51,7 @@ namespace Hanabi { void test() { { - auto game = Download::get_game("1005195", 43); + auto game = Download::get_game("in/1005195", 43); auto res = game->backtrack(1); CHECK("1005195", res == static_cast(7) / 8); } @@ -109,7 +109,7 @@ int main(int argc, char *argv[]) { #ifndef NDEBUG test(); #endif - check_games(2, 9); +// check_games(2, 9); if(argc == 3) { std::string game(argv[1]); std::string turn (argv[2]); @@ -122,4 +122,4 @@ int main(int argc, char *argv[]) { Hanabi::print_usage(argv[0]); } return 0; -} \ No newline at end of file +}