fix bug on not doing stuff in extraround
This commit is contained in:
parent
12ba53d37a
commit
89e6e02603
3 changed files with 29 additions and 16 deletions
|
@ -109,7 +109,6 @@ 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) {
|
||||
|
|
|
@ -170,7 +170,7 @@ 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 << " (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: ";
|
||||
for (const auto &[card, mul]: hanabi_state._draw_pile) {
|
||||
os << card;
|
||||
|
@ -349,18 +349,25 @@ namespace Hanabi {
|
|||
// First, check for playables
|
||||
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++) {
|
||||
if (_draw_pile.empty()) {
|
||||
BacktrackAction action = play(index);
|
||||
sum_of_probabilities += backtrack() * action.multiplicity;
|
||||
sum_of_mults += action.multiplicity;
|
||||
const double probability_for_this_play = backtrack();
|
||||
revert(action);
|
||||
assert(sum_of_mults <= _weighted_draw_pile_size);
|
||||
UPDATE_PROBABILITY(probability_for_this_play);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -369,13 +376,20 @@ namespace Hanabi {
|
|||
for(std::uint8_t index = 0; index < hand_size; index++) {
|
||||
if (is_trash(hand[index])) {
|
||||
double sum_of_probabilities = 0;
|
||||
for(size_t i = 0; i < _draw_pile.size(); i++) {
|
||||
if (_draw_pile.empty()) {
|
||||
BacktrackAction action = discard(index);
|
||||
sum_of_probabilities += backtrack() * action.multiplicity;
|
||||
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++) {
|
||||
BacktrackAction action = discard(index);
|
||||
sum_of_probabilities += backtrack() * action.multiplicity;
|
||||
revert(action);
|
||||
}
|
||||
const double probability_discard = sum_of_probabilities / _weighted_draw_pile_size;
|
||||
UPDATE_PROBABILITY(probability_discard);
|
||||
}
|
||||
const double probability_discard = sum_of_probabilities / _weighted_draw_pile_size;
|
||||
UPDATE_PROBABILITY(probability_discard);
|
||||
|
||||
// All discards are equivalent, do not continue searching for different trash
|
||||
break;
|
||||
|
|
2
main.cpp
2
main.cpp
|
@ -39,7 +39,7 @@ void test_game() {
|
|||
}
|
||||
|
||||
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;
|
||||
auto res = game.backtrack();
|
||||
std::cout << res << std::endl;
|
||||
|
|
Loading…
Reference in a new issue