Endgame-Analyzer/include/parse_game.h

65 lines
2 KiB
C++

#ifndef DYNAMIC_PROGRAM_PARSE_GAME_H
#define DYNAMIC_PROGRAM_PARSE_GAME_H
#include <boost/json.hpp>
#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<Card>, 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<HanabLiveAction>, boost::json::value const &jv);
/*
* @brief Parse deck from hanab.live format
* @return List of cards (in order) and number of suits
*/
std::pair<std::vector<Hanabi::Card>, Hanabi::suit_t> parse_deck(const boost::json::value &deck_json);
/**
* @brief Parse actions from hanab.live format.
* @return List of actions
*/
std::vector<HanabLiveAction> parse_actions(const boost::json::value &action_json);
std::vector<Hanabi::Action> convert_actions(
std::vector<HanabLiveAction> const & hanab_live_actions,
std::vector<Hanabi::Card> const & deck
);
struct GameInfo
{
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);
}
#endif //DYNAMIC_PROGRAM_PARSE_GAME_H