Cavoke  1.1.0
A Platform for creating and hosting multiplayer turn-based board games
Loading...
Searching...
No Matches
cavoke.h
1#ifndef CAVOKE_CAVOKE_H
2#define CAVOKE_CAVOKE_H
3
4#include <iostream>
5#include <nlohmann/json.hpp>
6#include <string>
7#include <vector>
8
9// TODO: logging
10namespace cavoke {
11using json = nlohmann::json;
12
13struct GameState { // NOLINT(cppcoreguidelines-pro-type-member-init)
14 bool is_terminal;
15 std::string global_state;
16 std::vector<std::string> players_state;
17 std::vector<int> winners;
18};
19NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(GameState,
20 is_terminal,
21 global_state,
22 players_state,
23 winners)
24
25struct GameMove { // NOLINT(cppcoreguidelines-pro-type-member-init)
26 int player_id;
27 std::string move;
28 std::string global_state;
29};
30NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(GameMove, player_id, move, global_state)
31
33 json settings;
34 std::vector<int> occupied_positions;
35};
36NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(InitSettings, settings, occupied_positions);
37
39 bool success;
40 std::string message;
41};
42
43NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ValidationResult, success, message);
44
45// called every time admin changes settings or new player arrives
46// returns true if game can be started with current settings; false otherwise
47// use message_callback(<some_message>) to display message to the players
48bool validate_settings(
49 const json &settings,
50 const std::vector<int> &occupied_positions,
51 const std::function<void(std::string)> &message_callback);
52
53// called once when the game session is started
54// generates initial state
55// settings have passed the validation
56GameState init_state(const json &settings,
57 const std::vector<int> &occupied_positions);
58
59// applies move to the state
60GameState apply_move(GameMove &new_move);
61
62} // namespace cavoke
63
64#endif // CAVOKE_CAVOKE_H