-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
109 lines (98 loc) · 2.6 KB
/
main.cc
File metadata and controls
109 lines (98 loc) · 2.6 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <cstdint>
#include <string>
#include <fstream>
#include <TFile.h>
#include "Global.h"
#include "Engine2048.h"
int chooseDirection0();
int main(int argc, char* argv[]) {
//////////////////////////////////////////////////////
//// Process Input Parameters
//////////////////////////////////////////////////////
if (argc != 4) {
printf("Usage: ./main game_id mode agent\n\
game_id: id for data set\n\
mode: 0 = new; 1 = load\n\
agent: 0 = human; 1 = NN\n"); return -1;
}
std::string game_id = argv[1];
int mode = atoi(argv[2]);
int agent = atoi(argv[3]);
gcycle_t cycle;
//////////////////////////////////////////////////////
//// Get pwd for File Saving
//////////////////////////////////////////////////////
std::string pwd;
char cwd[1024];
if (getcwd(cwd,sizeof(cwd)) != NULL)
pwd = cwd;
else {
printf("ERROR: Could not find cwd!\n");
return -1;
}
//////////////////////////////////////////////////////
//// Output Text File Setup
//////////////////////////////////////////////////////
std::fstream fout;
std::string pref;
std::string fileName;
pref = pwd + "/raw_player_data/";
fileName = pref + "data_" + std::to_string(agent) + "_" + game_id;
std::string fileNameT = fileName + ".txt";
fout.open (fileNameT, std::fstream::out);
//////////////////////////////////////////////////////
//// Create the 2048 Engine
//////////////////////////////////////////////////////
Engine2048 *engine2048;
engine2048 = new Engine2048();
//////////////////////////////////////////////////////
//// Start the Engine
//////////////////////////////////////////////////////
// Pre-Engine Process
bool game_state=false;
int direction;
bool dir_success=false;
std::string input;
while (!game_state) {
game_state = engine2048->beginningPhase();
engine2048->printBoard();
engine2048->holdBoardState();
if (!game_state) {
dir_success = false;
while (!dir_success) {
direction = chooseDirection0();
dir_success = engine2048->mainPhase(direction);
}
cycle.bstate = engine2048->getHeldBoardState();
cycle.direction = direction;
// Save the data to ROOT
for (int i=0; i<16; i++)
fout << cycle.bstate[i] << ",";
fout << cycle.direction << std::endl;
engine2048->endPhase();
} else {
// Game ends
}
}
delete engine2048;
fout.close();
return 0;
}
int chooseDirection0() {
char direction[1];
std::cin >> direction[0];
switch(direction[0]) {
case 'w':
return UP;
case 's':
return DOWN;
case 'a':
return LEFT;
case 'd':
return RIGHT;
}
return 0;
}