-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameServer.cpp
More file actions
52 lines (31 loc) · 1.33 KB
/
GameServer.cpp
File metadata and controls
52 lines (31 loc) · 1.33 KB
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
#include "Network/Server.h"
#include "Match/ClientGame.h"
#include <iostream>
#include <thread>
int main() {
auto server = Server(40596);
server.init(10);
std::uint32_t ConfigCounter = 0; //This is used to generate alternating game states, like who begins with which colour
for (auto refConnection : server) {
std::thread([connection = std::move(refConnection.get())] (std::uint32_t config) mutable {
char nameBuffer[15] = {0};
if(connection.receive(nameBuffer, sizeof(nameBuffer) - 1) != NET_RESULT::OK) {
return;
}
auto player = CreateRandomAiAndClientPlayer(ClientPlayer(nameBuffer, std::move(connection)),
config % 2);
try {
for (std::uint32_t ngames = 0; ngames < 2 + (config % 5); ngames++) { //Play a few games
SingleGame(player);
if (ngames % 2) { //Swap players every other game
std::swap(player[0], player[1]);
player[0].setColor(FIELD_STATE::RED);
player[1].setColor(FIELD_STATE::YELLOW);
}
}
}
catch(const PlayerError&) {
}
}, ConfigCounter++).detach();
}
}