From d3328725c7559bee3c33293fdee49eb671bb2135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sun, 12 Nov 2023 18:32:19 +0100 Subject: [PATCH] better output in case of too short replays --- include/game_state.h | 5 +++++ include/game_state.hpp | 7 ++++++- src/command_line_interface.cpp | 9 ++++++++- src/game_state.cpp | 5 +++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/include/game_state.h b/include/game_state.h index 62c91fd..c6a2e56 100644 --- a/include/game_state.h +++ b/include/game_state.h @@ -226,6 +226,7 @@ public: [[nodiscard]] virtual player_t turn() const = 0; [[nodiscard]] virtual clue_t num_clues() const = 0; + [[nodiscard]] virtual unsigned score() const = 0; [[nodiscard]] virtual std::vector> hands() const = 0; [[nodiscard]] virtual std::vector cur_hand() const = 0; [[nodiscard]] virtual size_t draw_pile_size() const = 0; @@ -260,6 +261,9 @@ protected: // history by making and reverting the stored actions. struct Game { Game(std::unique_ptr state, std::vector actions, std::vector deck); + + unsigned cur_turn() const; + void make_turn(); void revert_turn(); @@ -296,6 +300,7 @@ public: [[nodiscard]] player_t turn() const final; [[nodiscard]] clue_t num_clues() const final; + [[nodiscard]] unsigned score() const final; [[nodiscard]] std::vector> hands() const final; [[nodiscard]] std::vector cur_hand() const final; [[nodiscard]] size_t draw_pile_size() const final; diff --git a/include/game_state.hpp b/include/game_state.hpp index 52717c3..7bb0514 100644 --- a/include/game_state.hpp +++ b/include/game_state.hpp @@ -589,7 +589,12 @@ namespace Hanabi { template clue_t HanabiState::num_clues() const { return _num_clues; - }; + } + + template + unsigned HanabiState::score() const { + return _score; + } template std::vector> HanabiState::hands() const { diff --git a/src/command_line_interface.cpp b/src/command_line_interface.cpp index d1f7074..442259e 100644 --- a/src/command_line_interface.cpp +++ b/src/command_line_interface.cpp @@ -96,6 +96,7 @@ namespace Hanabi { throw std::logic_error("Invalid game state specification type encountered"); } std::cout << parms.game_state_spec << " cannot be reached with specified replay." << std::endl; + std::cout << "Replay ends at turn " << game.cur_turn() << " with score of " << game.state->score() << "." << std::endl; return state_unreachable; } @@ -117,10 +118,16 @@ namespace Hanabi { // This already evaluates all intermediate game states as well, because stalling is an option // (except for rare cases, where there is a forced win that does not need stalling). size_t const max_draw_pile_size = game.state->draw_pile_size(); + bool printed_replay_end_msg = false; for(size_t remaining_cards = 1; remaining_cards <= max_draw_pile_size; remaining_cards++) { if (!game.goto_draw_pile_size(remaining_cards)) { - std::cout << "The given draw pile size (" << remaining_cards << ") cannot be obtained with the specified replay." << std::endl; + if (not printed_replay_end_msg) + { + std::cout << "Draw pile size of " << game.state->draw_pile_size() -1 << " or lower cannot be obtained with the specified replay:" << std::endl; + std::cout << "Replay ends at turn " << game.cur_turn() << " with score of " << game.state->score() << "." << std::endl; + printed_replay_end_msg = true; + } continue; }; if (std::holds_alternative(parms.clue_spec)) diff --git a/src/game_state.cpp b/src/game_state.cpp index a3ead9e..c026b5c 100644 --- a/src/game_state.cpp +++ b/src/game_state.cpp @@ -21,6 +21,11 @@ namespace Hanabi { } } + unsigned Game::cur_turn() const + { + return next_action + 1; + } + void Game::make_turn() { ASSERT(next_action < actions.size());