Cavoke  1.1.0
A Platform for creating and hosting multiplayer turn-based board games
Loading...
Searching...
No Matches
cavoke.cpp
1#include "cavoke.h"
2#include <utility>
3
4using json = nlohmann::json;
5
6int main() {
7 // supported commands
8 // 1. VALIDATE <GameSettings>
9 // 2. INIT <GameSettings>
10 // 3. MOVE <GameMove>
11
12 std::string command;
13 std::cin >> command;
14
15 std::string argument;
16 char c;
17 while (std::cin.get(c)) {
18 argument.push_back(c);
19 }
20
21 std::cerr << "RECEIVED COMMAND: '" << command << ' ' << argument << "'"
22 << std::endl;
23
24 json argument_json = json::parse(argument);
25 json result_json;
26
27 if (command == "VALIDATE") {
28 cavoke::InitSettings settings =
29 argument_json.get<cavoke::InitSettings>();
30 std::string message;
31 bool success = cavoke::validate_settings(
32 settings.settings, settings.occupied_positions,
33 [&message](std::string message_) {
34 message = std::move(message_);
35 });
36 result_json = cavoke::ValidationResult{success, message};
37 } else if (command == "INIT") {
38 cavoke::InitSettings settings =
39 argument_json.get<cavoke::InitSettings>();
40 result_json =
41 cavoke::init_state(settings.settings, settings.occupied_positions);
42 } else {
43 cavoke::GameMove move = argument_json.get<cavoke::GameMove>();
44 result_json = cavoke::apply_move(move);
45 }
46
47 std::cerr << "SEND RESULT: '" << result_json << "'" << std::endl;
48 std::cout << result_json;
49}