-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathside_testing.cpp
62 lines (52 loc) · 1.43 KB
/
side_testing.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
#include <iostream>
#include <string>
#include <queue>
#include <stringstream>
using namespace std;
static const string EMPTY = "EMPTY";
static const int deltaAdj[4] = {-4,-1,4,1};
int find_other_empty(int empty,string (&board)[20]);
bool add_ten(int& x) { x += 10; return x;}
bool above_ten(int& x) { return 10 < x; }
bool remove_ten(int& x) {x -= 10; return x;}
int main() {
string board[20] =
{
"0","1","2","3",
"4","5","6","7",
"8","9","10","11",
"12",EMPTY,"14","15",
"16","17","18",EMPTY,
};
cout << find_other_empty(19, board) << endl;
int a = 4;
if (add_ten(a) && remove_ten(a) && above_ten(a))
cout << "ADD FIRST YAYY" << endl;
else
cout << "BOOO" << endl;
return 0;
}
int find_other_empty(int empty, string (&board)[20]) {
bool visited[20];
memset(visited, false, sizeof visited);
queue<int> q;
q.push(empty);
visited[empty] = true;
while (!q.empty()) {
int root = q.front();
cerr << root << " ";
for (int i = 0; i < 4; i++) {
int curr = root + deltaAdj[i];
if (not visited[curr] && curr < 20 && curr >= 0) {
if (board[curr] == EMPTY) {
cerr << "\n";
return curr;
}
q.push(curr);
visited[curr] = true;
}
}
q.pop();
}
return -1;
}