fix bug: cards in draw pilewere not merged correctly
This commit is contained in:
parent
bdab3f3b43
commit
12ba53d37a
2 changed files with 10 additions and 4 deletions
|
@ -109,6 +109,7 @@ namespace Download {
|
|||
size_t num_turns_to_replicate
|
||||
) {
|
||||
Hanabi::HanabiState<num_suits, num_players, hand_size> 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) {
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace Hanabi {
|
|||
HanabiState<num_suits, num_players, hand_size>::HanabiState(const std::vector<Card> &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::size_t num_suits, player_t num_players, std::size_t hand_size>
|
||||
std::ostream &operator<<(std::ostream &os, const HanabiState<num_suits, num_players, hand_size> 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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue