improve printing

This commit is contained in:
Maximilian Keßler 2023-08-12 11:09:06 +02:00
parent 76c10dc381
commit df559929b0
Signed by: max
GPG Key ID: BCC5A619923C0BA5
2 changed files with 24 additions and 18 deletions

View File

@ -55,13 +55,12 @@ namespace Hanabi {
template<size_t num_suits>
std::ostream &operator<<(std::ostream &os, const Stacks<num_suits> &stacks) {
for (size_t i = 0; i < stacks.size() - 1; i++) {
os << starting_card_rank - stacks[i];
for (size_t i = 0; i < stacks.size(); i++) {
os << suit_initials[i] << starting_card_rank - stacks[i];
if(i < stacks.size() - 1) {
os << ", ";
}
}
os << starting_card_rank - stacks.back();
return os;
}
@ -235,22 +234,38 @@ namespace Hanabi {
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
void HanabiState<num_suits, num_players, hand_size>::print(std::ostream &os) const {
os << "Stacks: " << _stacks << " (score " << +_score << ")";
os << ", clues: " << +_num_clues << ", turn: " << +_turn << std::endl;
os << ", clues: " << +_num_clues << ", turn: " << +_turn;
if (_endgame_turns_left != no_endgame) {
os << ", " << +_endgame_turns_left << " turns left";
}
os << std::endl;
os << "Draw pile: ";
unsigned num_trash = 0;
for (const auto &[card, mul]: _draw_pile) {
if (is_trash(card)) {
num_trash += mul;
continue;
}
os << card;
if (mul > 1) {
os << " (" << +mul << ")";
}
os << ", ";
}
os << "(size " << +_weighted_draw_pile_size << ")" << std::endl;
if (num_trash > 0) {
os << Cards::trash << " (" << num_trash << ") ";
}
os << "[size " << +_weighted_draw_pile_size << "]" << std::endl;
os << "Hands: ";
for (const auto &hand: _hands) {
for (const auto &card: hand) {
os << card << ", ";
os << "[";
for(hand_index_t index = 0; index < hand.size(); index++) {
os << hand[index];
if (index < hand.size() - 1) {
os << " ";
}
}
os << " | ";
os << "] ";
}
}

View File

@ -24,21 +24,12 @@ namespace Hanabi {
std::cout << "Probability with optimal play: " << res << std::endl;
std::cout << "Enumerated " << game->enumerated_states() << " states" << std::endl;
std::cout << "Visited " << game->position_tablebase().size() << " unique game states. " << std::endl;
for (const auto &[action, probability] : game->get_reasonable_actions()) {
std::cout << action;
if(probability.has_value()) {
std::cout << " " << probability.value();
} else {
std::cout << " unknown";
}
std::cout << ", ";
}
std::cout << std::endl;
unsigned long biggest_key = 0;
for(const auto& [key, prob] : game->position_tablebase()) {
biggest_key = std::max(biggest_key, key);
}
std::cout << "Biggest key generated is " << biggest_key << std::endl;
std::cout << std::endl;
auto game_shared = std::shared_ptr<HanabiStateIF>(game.release());
auto states = game_shared->possible_next_states(0, false);