From 12ba53d37a1ef568c044a7574eae22e888c7508e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sun, 6 Aug 2023 12:23:53 +0200 Subject: [PATCH] fix bug: cards in draw pilewere not merged correctly --- download.h | 1 + game_state.hpp | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/download.h b/download.h index f20d034..72e13a0 100644 --- a/download.h +++ b/download.h @@ -109,6 +109,7 @@ namespace Download { size_t num_turns_to_replicate ) { Hanabi::HanabiState game(deck); + std::cout << game << std::endl; std::uint8_t index; for (size_t i = 0; i < num_turns_to_replicate; i++) { switch(actions[i].type) { diff --git a/game_state.hpp b/game_state.hpp index 6faddc2..4929523 100644 --- a/game_state.hpp +++ b/game_state.hpp @@ -61,7 +61,7 @@ namespace Hanabi { HanabiState::HanabiState(const std::vector &deck): _turn(0), _num_clues(max_num_clues), - _weighted_draw_pile_size(deck.size() - num_players * hand_size), + _weighted_draw_pile_size(deck.size()), _stacks(), _hands(), _card_positions(draw_pile), @@ -169,7 +169,8 @@ namespace Hanabi { template std::ostream &operator<<(std::ostream &os, const HanabiState hanabi_state) { - os << "Stacks: " << hanabi_state._stacks << std::endl; + os << "Stacks: " << hanabi_state._stacks << " (score " << +hanabi_state._score << ")"; + os << ", clues: " << +hanabi_state._num_clues << std::endl; os << "Draw pile: "; for (const auto &[card, mul]: hanabi_state._draw_pile) { os << card; @@ -178,7 +179,7 @@ namespace Hanabi { } os << ", "; } - os << std::endl; + os << "(size " << +hanabi_state._weighted_draw_pile_size << ")" << std::endl; os << "Hands: "; for (const auto &hand: hanabi_state._hands) { for (const auto &card: hand) { @@ -237,7 +238,7 @@ namespace Hanabi { } // put card back into draw pile (at the back) - if (!_draw_pile.empty() and _draw_pile.back().card == _hands[_turn][index]) { + if (!_draw_pile.empty() and _draw_pile.back().card.suit == _hands[_turn][index].suit and _draw_pile.back().card.rank == _hands[_turn][index].rank) { _draw_pile.back().multiplicity++; } else { _draw_pile.push_back({_hands[_turn][index], 1}); @@ -349,11 +350,15 @@ namespace Hanabi { for(std::uint8_t index = 0; index < hand_size; index++) { if(is_playable(hand[index])) { double sum_of_probabilities = 0; + uint8_t sum_of_mults = 0; for(size_t i = 0; i < _draw_pile.size(); i++) { BacktrackAction action = play(index); sum_of_probabilities += backtrack() * action.multiplicity; + sum_of_mults += action.multiplicity; revert(action); + assert(sum_of_mults <= _weighted_draw_pile_size); } + assert(sum_of_mults == _weighted_draw_pile_size); const double probability_for_this_play = sum_of_probabilities / _weighted_draw_pile_size; UPDATE_PROBABILITY(probability_for_this_play); }