2023-08-05 00:34:31 +02:00
|
|
|
#ifndef DYNAMIC_PROGRAM_DOWNLOAD_H
|
|
|
|
#define DYNAMIC_PROGRAM_DOWNLOAD_H
|
|
|
|
|
|
|
|
#include <iostream>
|
2023-08-05 11:55:46 +02:00
|
|
|
#include <variant>
|
2023-08-12 19:43:22 +02:00
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <boost/json.hpp>
|
2023-08-05 00:34:31 +02:00
|
|
|
|
|
|
|
#include "game_state.h"
|
2023-08-06 15:02:50 +02:00
|
|
|
#include "myassert.h"
|
2023-08-05 00:34:31 +02:00
|
|
|
|
|
|
|
namespace Hanabi {
|
2023-08-12 19:15:05 +02:00
|
|
|
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);
|
2023-08-05 00:34:31 +02:00
|
|
|
}
|
|
|
|
|
2023-08-05 13:51:55 +02:00
|
|
|
namespace Download {
|
|
|
|
|
|
|
|
struct Action {
|
|
|
|
Hanabi::ActionType type{};
|
2023-09-14 17:06:06 +02:00
|
|
|
int8_t target{};
|
2023-08-05 13:51:55 +02:00
|
|
|
};
|
|
|
|
|
2023-08-12 19:15:05 +02:00
|
|
|
Action tag_invoke(boost::json::value_to_tag<Action>, boost::json::value const &jv);
|
2023-08-12 12:14:41 +02:00
|
|
|
|
2023-08-12 19:15:05 +02:00
|
|
|
std::pair<std::vector<Hanabi::Card>, Hanabi::rank_t> parse_deck(const boost::json::value &deck_json);
|
2023-08-12 18:58:12 +02:00
|
|
|
|
2023-08-12 19:15:05 +02:00
|
|
|
std::vector<Action> parse_actions(const boost::json::value &action_json);
|
2023-08-06 22:06:58 +02:00
|
|
|
|
2023-08-12 19:15:05 +02:00
|
|
|
std::optional<boost::json::object> download_game_json(int game_id);
|
2023-08-05 00:34:31 +02:00
|
|
|
|
2023-08-12 19:15:05 +02:00
|
|
|
std::optional<boost::json::object> open_game_json(const char *filename);
|
2023-08-05 00:34:31 +02:00
|
|
|
|
2023-08-12 19:15:05 +02:00
|
|
|
/**
|
|
|
|
* @brief Create game object from given source
|
|
|
|
* @param game_spec Either an id to download from hanab.live or a filename with a json specification
|
|
|
|
* @param turn Turn to skip to
|
|
|
|
* @param draw_pile_break Minimum draw pile size of produced game
|
|
|
|
* @return Game state
|
|
|
|
*
|
|
|
|
* If both turn and draw_pile_break are specified, the game skips until the specified turn or the first time the
|
|
|
|
* draw pile hits the given size, whichever comes first
|
|
|
|
*
|
|
|
|
* @note Turns start counting at 1, since this is also the way hanab.live does it.
|
|
|
|
*/
|
|
|
|
std::unique_ptr<Hanabi::HanabiStateIF> get_game(std::variant<int, const char*> game_spec, unsigned turn = 1, size_t draw_pile_break = 0);
|
2023-08-06 22:06:58 +02:00
|
|
|
|
2023-08-12 19:15:05 +02:00
|
|
|
} // namespace Download
|
2023-08-05 00:34:31 +02:00
|
|
|
|
|
|
|
#endif // DYNAMIC_PROGRAM_DOWNLOAD_H
|