-
Notifications
You must be signed in to change notification settings - Fork 0
/
player_infinite.cpp
executable file
·59 lines (53 loc) · 1.42 KB
/
player_infinite.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
#include <iostream>
#include <fstream>
#include <array>
#include <vector>
#include <cstdlib>
#include <ctime>
struct Point {
int x, y;
};
int player;
const int SIZE = 8;
std::array<std::array<int, SIZE>, SIZE> board;
std::vector<Point> next_valid_spots;
void read_board(std::ifstream& fin) {
fin >> player;
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
fin >> board[i][j];
}
}
}
void read_valid_spots(std::ifstream& fin) {
int n_valid_spots;
fin >> n_valid_spots;
int x, y;
for (int i = 0; i < n_valid_spots; i++) {
fin >> x >> y;
next_valid_spots.push_back({x, y});
}
}
void write_valid_spot(std::ofstream& fout) {
int n_valid_spots = next_valid_spots.size();
srand(time(NULL));
// Keep updating the output until getting killed.
while (true) {
// Choose random spot. (Not random uniform here)
int index = (rand() % n_valid_spots);
Point p = next_valid_spots[index];
// Remember to flush the output to ensure the last action is written to file.
fout << p.x << " " << p.y << std::endl;
fout.flush();
}
}
int main(int, char** argv) {
std::ifstream fin(argv[1]);
std::ofstream fout(argv[2]);
read_board(fin);
read_valid_spots(fin);
write_valid_spot(fout);
fin.close();
fout.close();
return 0;
}