fix bug on not doing stuff in extraround

This commit is contained in:
Maximilian Keßler 2023-08-06 12:49:52 +02:00
parent 12ba53d37a
commit 89e6e02603
Signed by: max
GPG key ID: BCC5A619923C0BA5
3 changed files with 29 additions and 16 deletions

View file

@ -109,7 +109,6 @@ namespace Download {
size_t num_turns_to_replicate size_t num_turns_to_replicate
) { ) {
Hanabi::HanabiState<num_suits, num_players, hand_size> game(deck); Hanabi::HanabiState<num_suits, num_players, hand_size> game(deck);
std::cout << game << std::endl;
std::uint8_t index; std::uint8_t index;
for (size_t i = 0; i < num_turns_to_replicate; i++) { for (size_t i = 0; i < num_turns_to_replicate; i++) {
switch(actions[i].type) { switch(actions[i].type) {

View file

@ -170,7 +170,7 @@ namespace Hanabi {
template<std::size_t num_suits, player_t num_players, std::size_t hand_size> 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) { std::ostream &operator<<(std::ostream &os, const HanabiState<num_suits, num_players, hand_size> hanabi_state) {
os << "Stacks: " << hanabi_state._stacks << " (score " << +hanabi_state._score << ")"; os << "Stacks: " << hanabi_state._stacks << " (score " << +hanabi_state._score << ")";
os << ", clues: " << +hanabi_state._num_clues << std::endl; os << ", clues: " << +hanabi_state._num_clues << ", turn: " << +hanabi_state._turn << std::endl;
os << "Draw pile: "; os << "Draw pile: ";
for (const auto &[card, mul]: hanabi_state._draw_pile) { for (const auto &[card, mul]: hanabi_state._draw_pile) {
os << card; os << card;
@ -349,6 +349,12 @@ namespace Hanabi {
// First, check for playables // First, check for playables
for(std::uint8_t index = 0; index < hand_size; index++) { for(std::uint8_t index = 0; index < hand_size; index++) {
if(is_playable(hand[index])) { if(is_playable(hand[index])) {
if (_draw_pile.empty()) {
BacktrackAction action = play(index);
const double probability_for_this_play = backtrack();
revert(action);
UPDATE_PROBABILITY(probability_for_this_play);
} else {
double sum_of_probabilities = 0; double sum_of_probabilities = 0;
uint8_t sum_of_mults = 0; uint8_t sum_of_mults = 0;
for (size_t i = 0; i < _draw_pile.size(); i++) { for (size_t i = 0; i < _draw_pile.size(); i++) {
@ -363,12 +369,19 @@ namespace Hanabi {
UPDATE_PROBABILITY(probability_for_this_play); UPDATE_PROBABILITY(probability_for_this_play);
} }
} }
}
// Check for discards now // Check for discards now
if(_pace > 0) { if(_pace > 0) {
for(std::uint8_t index = 0; index < hand_size; index++) { for(std::uint8_t index = 0; index < hand_size; index++) {
if (is_trash(hand[index])) { if (is_trash(hand[index])) {
double sum_of_probabilities = 0; double sum_of_probabilities = 0;
if (_draw_pile.empty()) {
BacktrackAction action = discard(index);
const double probability_for_this_discard = backtrack();
revert(action);
UPDATE_PROBABILITY(probability_for_this_discard);
} else {
for (size_t i = 0; i < _draw_pile.size(); i++) { for (size_t i = 0; i < _draw_pile.size(); i++) {
BacktrackAction action = discard(index); BacktrackAction action = discard(index);
sum_of_probabilities += backtrack() * action.multiplicity; sum_of_probabilities += backtrack() * action.multiplicity;
@ -376,6 +389,7 @@ namespace Hanabi {
} }
const double probability_discard = sum_of_probabilities / _weighted_draw_pile_size; const double probability_discard = sum_of_probabilities / _weighted_draw_pile_size;
UPDATE_PROBABILITY(probability_discard); UPDATE_PROBABILITY(probability_discard);
}
// All discards are equivalent, do not continue searching for different trash // All discards are equivalent, do not continue searching for different trash
break; break;

View file

@ -39,7 +39,7 @@ void test_game() {
} }
void download() { void download() {
auto game = Download::get_game<6,3,5>("1004116.json", 40); auto game = Download::get_game<4,3,5>("1004480.json", 36);
std::cout << game << std::endl; std::cout << game << std::endl;
auto res = game.backtrack(); auto res = game.backtrack();
std::cout << res << std::endl; std::cout << res << std::endl;