fix lookup method to also include trivials cases

This commit is contained in:
Maximilian Keßler 2023-08-12 10:31:32 +02:00
parent a95efaea4a
commit f137f9f67c
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 22 additions and 1 deletions

View file

@ -273,9 +273,13 @@ namespace Hanabi {
}
if (prompt.starts_with("actions")) {
for (const auto &[action, probability] : game->get_reasonable_actions()) {
auto reasonable_actions = game->get_reasonable_actions();
for (const auto &[action, probability] : reasonable_actions) {
std::cout << action << ": " << probability << std::endl;
}
if(reasonable_actions.empty()) {
std::cout << "Game is over, no actions to take." << std::endl;
}
continue;
}
@ -293,13 +297,23 @@ namespace Hanabi {
best_probability = probability;
}
}
hand_index_t index = 0;
switch(best_action.type) {
case ActionType::play:
std::cout << "Playing " << best_action.card << std::endl;
index = game->find_card_in_hand(best_action.card);
if(!ask_for_card_and_rotate_draw(game,index,true)) {
continue;
};
game->play(game->find_card_in_hand(best_action.card));
break;
case ActionType::discard:
std::cout << "Discarding" << std::endl;
index = game->find_card_in_hand(best_action.card);
if(!ask_for_card_and_rotate_draw(game, index, false)) {
continue;
};
game->discard(game->find_card_in_hand(best_action.card));
break;
case ActionType::clue:
@ -309,6 +323,7 @@ namespace Hanabi {
default:
break;
}
continue;
}
std::cout << "Unrecognized command. Type 'help' for a list of available commands." << std::endl;

View file

@ -604,6 +604,12 @@ namespace Hanabi {
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
std::optional<probability_t> HanabiState<num_suits, num_players, hand_size>::lookup() const {
if (_score == 5 * num_suits) {
return 1;
}
if (_pace < 0 or _endgame_turns_left == 0) {
return 0;
}
const auto id = unique_id();
if(_position_tablebase.contains(id)) {
return _position_tablebase.at(id);