simplify types
This commit is contained in:
parent
6e0e88b97a
commit
bdc65411ae
5 changed files with 18 additions and 19 deletions
|
@ -69,8 +69,17 @@ namespace Hanabi
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &os, HanabiStateIF const &hanabi_state);
|
std::ostream &operator<<(std::ostream &os, HanabiStateIF const &hanabi_state);
|
||||||
|
|
||||||
struct Game {
|
struct GameInfo
|
||||||
Game(std::unique_ptr<HanabiStateIF> state, std::vector<Action> actions, std::vector<Card> deck);
|
{
|
||||||
|
std::vector<Hanabi::Card> deck;
|
||||||
|
std::vector<Hanabi::Action> actions;
|
||||||
|
Hanabi::suit_t num_suits;
|
||||||
|
Hanabi::player_t num_players;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Game : private GameInfo {
|
||||||
|
public:
|
||||||
|
Game(std::unique_ptr<HanabiStateIF> state, GameInfo game_info);
|
||||||
|
|
||||||
[[nodiscard]] unsigned cur_turn() const;
|
[[nodiscard]] unsigned cur_turn() const;
|
||||||
|
|
||||||
|
@ -83,8 +92,6 @@ namespace Hanabi
|
||||||
[[nodiscard]] bool holds_state() const;
|
[[nodiscard]] bool holds_state() const;
|
||||||
|
|
||||||
std::unique_ptr<HanabiStateIF> state;
|
std::unique_ptr<HanabiStateIF> state;
|
||||||
std::vector<Action> actions;
|
|
||||||
std::vector<Card> deck;
|
|
||||||
unsigned next_action;
|
unsigned next_action;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -49,15 +49,7 @@ namespace Parsing {
|
||||||
std::vector<Hanabi::Card> const & deck
|
std::vector<Hanabi::Card> const & deck
|
||||||
);
|
);
|
||||||
|
|
||||||
struct GameInfo
|
Hanabi::GameInfo parse_game(boost::json::object const & game_json);
|
||||||
{
|
|
||||||
std::vector<Hanabi::Card> deck;
|
|
||||||
std::vector<Hanabi::Action> actions;
|
|
||||||
Hanabi::suit_t num_suits;
|
|
||||||
Hanabi::player_t num_players;
|
|
||||||
};
|
|
||||||
|
|
||||||
GameInfo parse_game(boost::json::object const & game_json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -114,11 +114,11 @@ namespace Download {
|
||||||
}();
|
}();
|
||||||
|
|
||||||
if (!game_json_opt.has_value() or game_json_opt.value().empty()) {
|
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());
|
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.actions, game_info.deck};
|
return {get_base_state(game_info.num_suits, game_info.num_players, game_info.deck, score_goal), game_info};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Download
|
} // namespace Download
|
||||||
|
|
|
@ -10,8 +10,8 @@ namespace Hanabi {
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::Game(std::unique_ptr<HanabiStateIF> state, std::vector<Action> actions, std::vector<Card> deck):
|
Game::Game(std::unique_ptr<HanabiStateIF> state, Hanabi::GameInfo game_info):
|
||||||
state(std::move(state)), actions(std::move(actions)), deck(std::move(deck)), next_action(0)
|
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,
|
// 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.
|
// as this will mess with our moves.
|
||||||
|
|
|
@ -92,7 +92,7 @@ namespace Parsing {
|
||||||
return actions;
|
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"));
|
auto const [deck, num_suits] = parse_deck(game_json.at("deck"));
|
||||||
const std::vector<Parsing::HanabLiveAction> hanab_live_actions = parse_actions(game_json.at("actions"));
|
const std::vector<Parsing::HanabLiveAction> hanab_live_actions = parse_actions(game_json.at("actions"));
|
||||||
|
|
Loading…
Reference in a new issue