-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
62 lines (57 loc) · 2.06 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
51
52
53
54
55
56
57
58
59
60
61
62
// HTTP credits: http://lcs.ios.ac.cn/~maxt/SPelton/reports/report-9aa0d3.html
// JSON credits: https://github.com/nlohmann/json
#include "./http_stuff.h"
using namespace std;
#include "./json.hpp"
#include "logic.cpp"
#include <iostream>
// using namespace nlohmann;
int main(void) {
bool activateServer = true;
if (activateServer) {
httplib::Server svr;
svr.Get("/", [](const auto &, auto &res) {
string head = "default"; // TODO: Change head
string tail = "default"; // TODO: Change tail
string author = ""; // TODO: Change your battlesnake username
string color = "#FF0000"; // TODO: Change a hex color
res.set_content(
"{\"apiversion\":\"1\", \"head\":\"" + head +
"\", \"tail\":\"" + tail + "\", \"color\":\"" + color +
"\", " + "\"author\":\"" + author + "\"}",
"application/json");
});
svr.Post("/end", [](const auto &, auto &res) {
res.set_content("ok", "text/plain");
});
svr.Post("/start", [](const auto &, auto &res) {
res.set_content("ok", "text/plain");
});
svr.Post("/move", [](auto &req, auto &res) {
const json data = json::parse(req.body);
//(cout << data;
// cout << "\n\n";
// vARIABLES NUEVAS
// AQUI--------------------------------------------------
int maxDepth = 50;
MonteCarloSearchTree tree = MonteCarloSearchTree(data, maxDepth);
//-----------------------------------------------------------
// You can get the "you" property like this:
// data["you"];
// Almost alike python dictionary parsing, but with a semicolon at
// the end of each line. You might need to make some structs to
// store some data in a variable Example: you_struct you =
// data["you"];
string moves[4] = {"up", "down", "left", "right"};
// ESCRIBIR CÓDIGO NUEVO AQUÍ -------------------------------
// tree.debugJSON();
string newMove = "";
newMove = tree.nextMove();
//-----------------------------------------------------------
res.set_content("{\"move\": \"" + newMove + "\"}", "text/plain");
});
svr.listen("0.0.0.0", 8080);
cout << "Server started";
}
return 0;
}