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 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
int main()
{
int c ,r;
ifstream in("maze.txt");
char str1[100], str2[100], str3[100];
in.getline(str1, 100);
in.getline(str2, 100);
in.getline(str3, 100);
int line = 1, cell = 1;
while (!in.eof())
{
cell = 1;
cout << "line " << line << endl;
int i = 0;
bool top, down, right, left;
top = down = right = left = false;
int j = 0, k = 1;
cout << "strlen = " << strlen(str1) << endl;
while (i < strlen(str1) - 1)
{
top = down = right = left = false;
if (str1[i] == '+') i++; //new cell
if (str1[i] == '-')top = true;
else if (str1[i] == ' ')top = false;
i = i + 3; //wall above
if (str2[j] == '|') left = true;
else if (str2[j] == ' ')left = false;
j = j + 4; //left wall
if (str2[j] == '|') right = true;
else if (str2[j] == ' ')right = false; //right wall
if (str3[k] == ' ') down = false;
else if (str3[k] == '-') down = true;
k = k + 4; //wall below
cout << "cell = " << cell << endl;
cell++; c++; //cols
cout << "Top : " << top << "\t";
cout << "down : " << down << endl;
cout << "right : " << right << "\t";
cout << "left : " << left << endl;
cout << endl << endl;
}
strcpy(str1, str3);
cout << str1 << endl;
in.getline(str2, 100);
in.getline(str3, 100);
cout << str2 << endl;
cout << str3 << endl;
line++; r++; //rows
}
Maze m(r, c);
r = c = 0;
while (!in.eof())
{
cell = 1;
cout << "line " << line << endl;
int i = 0;
bool top, down, right, left;
top = down = right = left = false;
int j = 0, k = 1;
cout << "strlen = " << strlen(str1) << endl;
while (i < strlen(str1) - 1)
{
top = down = right = left = false;
if (str1[i] == '+') i++; //new cell
if (str1[i] == '-')
{
top = true;
m.getcell(r,c).setUp(top);
}
else if (str1[i] == ' ') {
top = false;
m.getcell(r,c).setUp(top);
}
i = i + 3; //wall above
if (str2[j] == '|')
{
left = true;
m.getcell(r,c).setLeft(left);
}
else if (str2[j] == ' ') { left = false;
m.getcell(r,c).setLeft(left);
}
j = j + 4; //left wall
if (str2[j] == '|') { right = true;
m.getcell(r,c).setRight(right);
}
else if (str2[j] == ' '){right = false; //right wall
m.getcell(r,c).setRight(right);
}
if (str3[k] == ' ') { down = false; m.getcell(r,c).setDown(down); }
else if (str3[k] == '-') { down = true;
m.getcell(r,c).setDown(down);
}
k = k + 4; //wall below
cout << "cell = " << cell << endl;
cell++; c++; //cols
cout << "Top : " << top << "\t";
cout << "down : " << down << endl;
cout << "right : " << right << "\t";
cout << "left : " << left << endl;
cout << endl << endl;
}
strcpy(str1, str3);
cout << str1 << endl;
in.getline(str2, 100);
in.getline(str3, 100);
cout << str2 << endl;
cout << str3 << endl;
line++; r++; //rows
}
if(m.DFS(m))
cout<<" FOUND TARGET! "<<endl;
else
cout<<" DID NOT FIND TARGET! "<<endl;
system("pause");
}
| |