-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
50 lines (46 loc) · 1.71 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* This file is temporary until the GUI will not be implemented.
*/
#include "game.h"
#include "handler.h"
#include <iostream>
#include <string>
#include <sstream>
#include <QJsonDocument>
#include <vector>
#include <QJsonArray>
std::pair<std::string, std::vector<int>> parse_input(const std::string& input) {
std::string command;
std::stringstream ss(input);
ss >> command;
std::vector<int> tokens;
std::string current_token;
while (ss >> current_token) {
tokens.push_back(std::stoi(current_token));
}
return {command, tokens};
}
int main() {
// TODO : only one game type is supported with 4 players
jackal::Game current_game(jackal::game_type::DEFAULT);
// A temporary version of the player's interaction with game
// Pirate coords new coords
// Input format : col_coord row_coord col_coord row_coord
std::string command;
QJsonObject result;
while (std::getline(std::cin, command)) {
auto tokens = parse_input(command);
QJsonObject a = jackal::Handler::get_possible_moves(current_game, 0);
std::cout << QJsonDocument(a).toJson(QJsonDocument::Compact).toStdString() << std::endl;
if (tokens.second.size() == 1) {
result = current_game.process_move(tokens.first, tokens.second[0]);
}
else if (tokens.first == "ship_move"){
result = current_game.process_move(tokens.first, -1, tokens.second[0], tokens.second[1]);
}
else {
result = current_game.process_move(tokens.first, tokens.second[0], tokens.second[1], tokens.second[2]);
}
std::cout << QJsonDocument(result).toJson(QJsonDocument::Compact).toStdString() << std::endl;
}
}