#ifndef DYNAMIC_PROGRAM_PARSE_GAME_H #define DYNAMIC_PROGRAM_PARSE_GAME_H #include #include "game_state.h" namespace Hanabi { // These are overloads that the boost/json library uses for parsing. // They convert a Card from/to json. // This has to be in the same namespace as Hanabi::Card. Card tag_invoke(boost::json::value_to_tag, boost::json::value const &jv); void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Hanabi::Card const &card); } namespace Parsing { /** * Represents a single action (turn) in a Hanab game. * Note that this is slightly differen than Hanabi::Action, * since this uses indices for specifying the discarded/played cards. * We only want to work with this type while parsing, converting to Hanabi::Action after. */ struct HanabLiveAction { Hanabi::ActionType type{}; /** * In case the action is of type discard or play, * this value refers to the index of the discarded/played card in the deck. */ int8_t target{}; }; // Overload for parsing from json to HanabLiveAction HanabLiveAction tag_invoke(boost::json::value_to_tag, boost::json::value const &jv); /* * @brief Parse deck from hanab.live format * @return List of cards (in order) and number of suits */ std::pair, Hanabi::suit_t> parse_deck(const boost::json::value &deck_json); /** * @brief Parse actions from hanab.live format. * @return List of actions */ std::vector parse_actions(const boost::json::value &action_json); std::vector convert_actions( std::vector const & hanab_live_actions, 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); } #endif //DYNAMIC_PROGRAM_PARSE_GAME_H