From bdc65411ae48f2aa2f3dd6bb348aa7191fd3f641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Wed, 15 Nov 2023 23:23:21 +0100 Subject: [PATCH] simplify types --- include/game_interface.h | 15 +++++++++++---- include/parse_game.h | 10 +--------- src/download.cpp | 6 +++--- src/game_interface.cpp | 4 ++-- src/parse_game.cpp | 2 +- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/include/game_interface.h b/include/game_interface.h index 221c003..c69f761 100644 --- a/include/game_interface.h +++ b/include/game_interface.h @@ -69,8 +69,17 @@ namespace Hanabi std::ostream &operator<<(std::ostream &os, HanabiStateIF const &hanabi_state); - struct Game { - Game(std::unique_ptr state, std::vector actions, std::vector deck); + struct GameInfo + { + std::vector deck; + std::vector actions; + Hanabi::suit_t num_suits; + Hanabi::player_t num_players; + }; + + struct Game : private GameInfo { + public: + Game(std::unique_ptr state, GameInfo game_info); [[nodiscard]] unsigned cur_turn() const; @@ -83,8 +92,6 @@ namespace Hanabi [[nodiscard]] bool holds_state() const; std::unique_ptr state; - std::vector actions; - std::vector deck; unsigned next_action; }; diff --git a/include/parse_game.h b/include/parse_game.h index cc2fe64..2047631 100644 --- a/include/parse_game.h +++ b/include/parse_game.h @@ -49,15 +49,7 @@ namespace Parsing { std::vector const & deck ); - struct GameInfo - { - std::vector deck; - std::vector actions; - Hanabi::suit_t num_suits; - Hanabi::player_t num_players; - }; - - GameInfo parse_game(boost::json::object const & game_json); + Hanabi::GameInfo parse_game(boost::json::object const & game_json); } diff --git a/src/download.cpp b/src/download.cpp index 37bb785..c273ec3 100644 --- a/src/download.cpp +++ b/src/download.cpp @@ -114,11 +114,11 @@ namespace Download { }(); if (!game_json_opt.has_value() or game_json_opt.value().empty()) { - return {nullptr, {}, {}}; + return {nullptr, {}}; } - Parsing::GameInfo game_info = Parsing::parse_game(game_json_opt.value()); - return {get_base_state(game_info.num_suits, game_info.num_players, game_info.deck, score_goal), game_info.actions, game_info.deck}; + Hanabi::GameInfo game_info = Parsing::parse_game(game_json_opt.value()); + return {get_base_state(game_info.num_suits, game_info.num_players, game_info.deck, score_goal), game_info}; } } // namespace Download diff --git a/src/game_interface.cpp b/src/game_interface.cpp index 98f5b5a..3781a45 100644 --- a/src/game_interface.cpp +++ b/src/game_interface.cpp @@ -10,8 +10,8 @@ namespace Hanabi { return os; } - Game::Game(std::unique_ptr state, std::vector actions, std::vector deck): - state(std::move(state)), actions(std::move(actions)), deck(std::move(deck)), next_action(0) + Game::Game(std::unique_ptr state, Hanabi::GameInfo game_info): + GameInfo(std::move(game_info)), state(std::move(state)), next_action(0) { // If there is a 'Null' action that only signals the game's end, we want to get rid of it now, // as this will mess with our moves. diff --git a/src/parse_game.cpp b/src/parse_game.cpp index 97dd85a..21127fa 100644 --- a/src/parse_game.cpp +++ b/src/parse_game.cpp @@ -92,7 +92,7 @@ namespace Parsing { return actions; } - GameInfo parse_game(boost::json::object const & game_json) + Hanabi::GameInfo parse_game(boost::json::object const & game_json) { auto const [deck, num_suits] = parse_deck(game_json.at("deck")); const std::vector hanab_live_actions = parse_actions(game_json.at("actions"));