-
Notifications
You must be signed in to change notification settings - Fork 0
/
Safari.cpp
64 lines (55 loc) · 1.59 KB
/
Safari.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
63
64
#include<iostream>
#include <string.h>
#include "State.h"
#include "Search.h"
//support the input in the following format: safari.exe -t 200 < a2-orig.data
int main(int argc, char* argv[]) {
std::cout.setf(std::ios_base::unitbuf); //auto flush
State s;
Search sr;
sr.importGame(s);
//check & set time entered
if (argc == 3) {
if (strcmp(argv[1], "-t") == 0) {//compare 'actual' content
int time = stoi(argv[2]); //change sstream to stoi-> faster
sr.setTime(time);
//test:
cout << "[Fixed Time: " << time <<" seconds]"<< endl;
}
else { cout << "[Invalid Entry]" << endl; }
}
//now accept all game puzzles
string CMD;
while (getline(cin, CMD)) {
string problem;
if (CMD[0] == 'P') {//entering board
if (CMD.size() > 3) {
problem = CMD.substr(2, CMD.size()); //ex: J1, E20, etc...
s.setProblem(problem);//for printing output
}
//start getting board from file < a2-orig.data
string temp_board,line;
temp_board = "";
bool complete = false;
for (int i = 0; i < s.SIZE; i++) {
getline(cin, line);
if (line.size() < unsigned(s.SIZE)) {break; }
else {
line = line.substr(0, s.SIZE);
temp_board = temp_board + line;
}
if (i == s.SIZE - 1) { complete = true; break; }
}
if (complete) {
s.setBoard(temp_board);
s.PrintBoard();
sr.IDsearch();//start IDA* with TT
//sr.Play(); //test BFS
}
continue;
}
if (CMD.empty()) { continue; } //skip empty lines between problems
if (CMD[0] == 'q' && CMD.size()==1) { break; }
}
return 0;
}