rework -r option: solve state in reverse order
This commit is contained in:
parent
7eb1364e36
commit
59709e2375
3 changed files with 24 additions and 9 deletions
|
@ -218,6 +218,7 @@ public:
|
||||||
virtual void play(hand_index_t index) = 0;
|
virtual void play(hand_index_t index) = 0;
|
||||||
|
|
||||||
virtual void rotate_next_draw(const Card& card) = 0;
|
virtual void rotate_next_draw(const Card& card) = 0;
|
||||||
|
virtual ActionType last_action_type() const = 0;
|
||||||
virtual void revert() = 0;
|
virtual void revert() = 0;
|
||||||
|
|
||||||
virtual void modify_clues(clue_t change) = 0;
|
virtual void modify_clues(clue_t change) = 0;
|
||||||
|
@ -283,6 +284,7 @@ public:
|
||||||
void play(hand_index_t index) final;
|
void play(hand_index_t index) final;
|
||||||
|
|
||||||
void rotate_next_draw(const Card& card) final;
|
void rotate_next_draw(const Card& card) final;
|
||||||
|
ActionType last_action_type() const final;
|
||||||
|
|
||||||
void revert() final;
|
void revert() final;
|
||||||
|
|
||||||
|
|
|
@ -678,6 +678,13 @@ namespace Hanabi {
|
||||||
std::swap(*card_it, _draw_pile.front());
|
std::swap(*card_it, _draw_pile.front());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
|
||||||
|
ActionType HanabiState<num_suits, num_players, hand_size>::last_action_type() const
|
||||||
|
{
|
||||||
|
assert(not _actions_log.empty());
|
||||||
|
return _actions_log.top().action_type;
|
||||||
|
}
|
||||||
|
|
||||||
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
|
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
|
||||||
probability_t HanabiState<num_suits, num_players, hand_size>::evaluate_state() {
|
probability_t HanabiState<num_suits, num_players, hand_size>::evaluate_state() {
|
||||||
ASSERT(_relative_representation.initialized);
|
ASSERT(_relative_representation.initialized);
|
||||||
|
|
24
src/main.cpp
24
src/main.cpp
|
@ -36,13 +36,17 @@ namespace Hanabi {
|
||||||
}
|
}
|
||||||
game.state->init_backtracking_information();
|
game.state->init_backtracking_information();
|
||||||
auto start = std::chrono::high_resolution_clock::now();
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
auto res = game.state->evaluate_state();
|
boost::rational<probability_base_type> result;
|
||||||
|
if (not print_remaining_states) {
|
||||||
|
result = game.state->evaluate_state();
|
||||||
|
}
|
||||||
auto end = std::chrono::high_resolution_clock::now();
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
std::cout.precision(10);
|
std::cout.precision(10);
|
||||||
if (not (quiet and print_remaining_states)) {
|
|
||||||
|
if (not print_remaining_states) {
|
||||||
std::cout << "Probability with optimal play: ";
|
std::cout << "Probability with optimal play: ";
|
||||||
print_probability(std::cout, res) << std::endl;
|
print_probability(std::cout, result) << std::endl;
|
||||||
}
|
}
|
||||||
if (not quiet) {
|
if (not quiet) {
|
||||||
std::cout << "Took " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start) << "." << std::endl;
|
std::cout << "Took " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start) << "." << std::endl;
|
||||||
|
@ -52,22 +56,24 @@ namespace Hanabi {
|
||||||
|
|
||||||
if (print_remaining_states)
|
if (print_remaining_states)
|
||||||
{
|
{
|
||||||
for(size_t remaining_cards = game.state->draw_pile_size(); remaining_cards > 0; remaining_cards--) {
|
size_t const max_draw_pile_size = game.state->draw_pile_size();
|
||||||
game.forward_until(100, remaining_cards);
|
game.forward_until(100, 1);
|
||||||
|
for(size_t remaining_cards = 1; remaining_cards <= max_draw_pile_size; remaining_cards++) {
|
||||||
|
game.revert_until(remaining_cards);
|
||||||
if (all_clues) {
|
if (all_clues) {
|
||||||
clue_t original_num_clues = game.state->num_clues();
|
clue_t original_num_clues = game.state->num_clues();
|
||||||
for(clue_t num_clues = 0; num_clues <= 8; num_clues++) {
|
for(clue_t num_clues = 0; num_clues <= 8; num_clues++) {
|
||||||
game.state->set_clues(num_clues);
|
game.state->set_clues(num_clues);
|
||||||
res = game.state->evaluate_state();
|
result = game.state->evaluate_state();
|
||||||
std::cout << "Probability with " << remaining_cards << " cards left in deck and " << +num_clues
|
std::cout << "Probability with " << remaining_cards << " cards left in deck and " << +num_clues
|
||||||
<< " clues (" << std::showpos << +(num_clues - original_num_clues) << "): " << std::noshowpos;
|
<< " clues (" << std::showpos << +(num_clues - original_num_clues) << "): " << std::noshowpos;
|
||||||
print_probability(std::cout, res) << std::endl;
|
print_probability(std::cout, result) << std::endl;
|
||||||
}
|
}
|
||||||
game.state->set_clues(original_num_clues);
|
game.state->set_clues(original_num_clues);
|
||||||
} else {
|
} else {
|
||||||
res = game.state->evaluate_state();
|
result = game.state->evaluate_state();
|
||||||
std::cout << "Probability with " << remaining_cards << " cards left in deck: ";
|
std::cout << "Probability with " << remaining_cards << " cards left in deck: ";
|
||||||
print_probability(std::cout, res) << std::endl;
|
print_probability(std::cout, result) << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue