forked from meemknight/marsMission
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexampleRobot.cpp
More file actions
51 lines (40 loc) · 887 Bytes
/
exampleRobot.cpp
File metadata and controls
51 lines (40 loc) · 887 Bytes
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 <iostream>
#include <fstream>
#include <string>
#include <thread>
using namespace std;
int main()
{
int id = 0;
std::cout << "enter id: ";
std::cin >> id;
int round = 0;
while (true)
{
std::string serverFileName = "game/s" + std::to_string(id) + "_" + std::to_string(round) +
".txt";
std::ifstream input(serverFileName);
if (input)
{
//sleep a little to make sure that the file was written bt the server
std::this_thread::sleep_for(std::chrono::milliseconds(5));
//it is our turn to move
//read the file...
input.close();
//write the response back
std::string ourFileName = "game/c" + std::to_string(id) + "_" + std::to_string(round) +
".txt";
std::ofstream response(ourFileName);
//..
response << "M U\n";
response.close();
//increment the round
round++;
}
else
{
//waiting
}
}
return 0;
}