forked from ieeecity/micromouse2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maze.h
181 lines (158 loc) · 5.2 KB
/
maze.h
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <LinkedList.h>
struct Cell {
bool walls[4]; // Array to represent walls: 0 -> right, 1 -> left, 2 -> up, 3 -> down
int x; // X coordinate of the cell
int y; // Y coordinate of the cell
int weight; // weight of cell
};
Cell maze[8][8] = {
{
// R L U D
{{true, true, false, true}, 0, 0, 0},
{{false, true, true, true}, 1, 0, 0},
{{true, false, false, true}, 2, 0, 0},
{{false, true, false, true}, 3, 0, 0},
{{true, false, true, true}, 4, 0, 0},
{{false, true, false, true}, 5, 0, 0},
{{false, false, true, true}, 6, 0, 0},
{{true, false, false, true}, 7, 0, 0}
},
{
{{true, true, false, false}, 0, 1, 0},
{{true, true, false, true}, 1, 1, 0},
{{true, true, false, false}, 2, 1, 0},
{{false, true, true, false}, 3, 1, 0},
{{false, false, true, true}, 4, 1, 0},
{{true, false, true, false}, 5, 1, 0},
{{true, true, false, true}, 6, 1, 0},
{{true, true, false, false}, 7, 1, 0}
},
{
{{false, true, false, false}, 0, 2, 0},
{{true, false, true, false}, 1, 2, 0},
{{false, true, true, false}, 2, 2, 0},
{{false, false, false, true}, 3, 2, 0},
{{false, false, true, true}, 4, 2, 0},
{{false, false, true, true}, 5, 2, 0},
{{false, false, true, false}, 6, 2, 0},
{{true, false, false, false}, 7, 2, 0}
},
{
{{false, true, false, false}, 0, 3, 0},
{{false, false, true, false}, 1, 3, 0},
{{false, false, false, true}, 2, 3, 0},
{{true, false, false, false}, 3, 3, 0},
{{false, true, true, true}, 4, 3, 0},
{{false, false, true, true}, 5, 3, 0},
{{false, false, true, true}, 6, 3, 0},
{{true, false, false, false}, 7, 3, 0}
},
{
{{true, true, false, false}, 0, 4, 0},
{{false, true, true, true}, 1, 4, 0},
{{true, false, true, false}, 2, 4, 0},
{{true, true, false, false}, 3, 4, 0},
{{true, true, false, true}, 4, 4, 0},
{{false, true, false, true}, 5, 4, 0},
{{false, false, true, true}, 6, 4, 0},
{{true, false, false, false}, 7, 4, 0}
},
{
{{false, true, false, false}, 0, 5, 0},
{{false, false, false, true}, 1, 5, 0},
{{true, false, false, true}, 2, 5, 0},
{{true, true, false, false}, 3, 5, 0},
{{true, true, false, false}, 4, 5, 0},
{{false, true, false, false}, 5, 5, 0},
{{true, false, false, true}, 6, 5, 0},
{{true, true, false, false}, 7, 5, 0}
},
{
{{true, true, false, false}, 0, 6, 0},
{{true, true, false, false}, 1, 6, 0},
{{true, true, false, false}, 2, 6, 0},
{{false, true, true, false}, 3, 6, 0},
{{true, false, false, false}, 4, 6, 0},
{{false, true, true, false}, 5, 6, 0},
{{true, false, true, false}, 6, 6, 0},
{{true, true, false, false}, 7, 6, 0}
},
{
{{false, true, true, false}, 0, 7, 0},
{{true, false, true, false}, 1, 7, 0},
{{false, true, true, false}, 2, 7, 0},
{{true, false, true, true}, 3, 7, 0},
{{false, true, true, false}, 4, 7, 0},
{{false, false, true, true}, 5, 7, 0},
{{false, false, true, true}, 6, 7, 0},
{{true, false, true, false}, 7, 7, 0}
}
};
void printMaze(const struct Cell (&maze)[8][8]) {
for(int y = 7; y >= 0; --y){ // For each ROW
Serial.println("");
for(int x = 0; x < 8; ++x){ // for each col value in said row
if(maze[y][x].walls[1]){ // Left wall
Serial.print("|");
}
Serial.print(maze[y][x].x);
if(maze[y][x].walls[2]){ // Top wall
Serial.print("¯");
} else{
Serial.print(",");
}
if(maze[y][x].walls[3]){ // Bottom wall
Serial.print("_");
} else{
Serial.print(",");
}
Serial.print(maze[y][x].y);
if(maze[y][x].walls[0]){ // Right wall
Serial.print("|");
}
if(!(maze[y][x].x >= 10 || maze[y][x].y >= 10)){
Serial.print(" ");
} else{
Serial.print(" ");
}
}
}
Serial.println(); // Print a newline after printing the entire maze
}
void printMazeWeights(const struct Cell (&maze)[8][8]) {
for(int y = 7; y >= 0; --y){ // For each ROW
Serial.print(y);
Serial.print(" ");
for(int x = 0; x < 8; ++x){ // for each col value in said row
if(maze[y][x].walls[1]){ // Left wall
Serial.print("|");
}
if(maze[y][x].weight < 0){
Serial.print("?");
} else{
Serial.print(maze[y][x].weight);
}
if(maze[y][x].walls[2]){ // Top wall
Serial.print("¯");
} else{
Serial.print(" ");
}
if(maze[y][x].walls[3]){ // Bottom wall
Serial.print("_");
} else{
Serial.print(" ");
}
if(maze[y][x].walls[0]){ // Right wall
Serial.print("|");
}
if(!(maze[y][x].walls[0]) && maze[y][x].weight <10){
Serial.print(" ");
} else if(!(maze[y][x].walls[0])){
Serial.print(" ");
}
}
Serial.println(""); // each row on a new line
}
Serial.println("");
Serial.println(" 0 1 2 3 4 5 6 7 ");
}