normalize positions if duplicates of cards have already been played

This commit is contained in:
Maximilian Keßler 2023-08-08 16:27:25 +02:00
parent 28b30edd81
commit d95f40e2ae
Signed by: max
GPG Key ID: BCC5A619923C0BA5
4 changed files with 17 additions and 7 deletions

View File

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

View File

@ -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<boost::container::static_vector<player_t, max_card_duplicity>, 10> _card_positions_draw;
boost::container::static_vector<Card, 10> _good_cards_draw;
// This will indicate whether cards that were in hands initially still are in hands
std::bitset<num_players * hand_size> _card_positions_hands;

View File

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

View File

@ -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<double>(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;
}
}