-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCell.cpp
250 lines (207 loc) · 3.33 KB
/
Cell.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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#include <iostream>
#include "Cell.h"
/**
*
* Create a new cell object
*
*/
Cell::Cell(Board* pBoard, char Symbol, int Row, int Col)
{
this->pBoard = pBoard;
this->Symbol = Symbol;
this->Row = Row;
this->Col = Col;
this->Visited = false;
// extra
parent = nullptr;
closed = false;
opened = false;
far = 0;
}
/**
*
* Return the symbol associated with this cell
*
*/
char Cell::GetSymbol() const
{
return Symbol;
}
/**
*
* Change the symbol associated with this cell
*
*/
void Cell::SetSymbol(char c)
{
Symbol = c;
}
/**
*
* Returns true if you can pass through that cell
* when walking the albyrinth (e.g. corridor)
* or not (e.g. wall)
*
*/
bool Cell::IsPassable() const
{
return Symbol != '#';
}
/**
*
* Returns true if this cell is a wall.
*
*/
bool Cell::IsCorridor() const
{
return Symbol == ' ';
}
/**
*
* Returns true if this cell is a corridor.
*
*/
bool Cell::IsWall() const
{
return Symbol == '#';
}
/**
*
* Returns true if this cell is the entrance of the labyrinth.
*
*/
bool Cell::IsStart() const
{
return Symbol == '^';
}
/**
*
* Returns true if the cell is the target to find in the labyrinth
*
*/
bool Cell::IsTarget() const
{
return Symbol == '$';
}
/**
*
* Returns the row on which this cell is located on the board.
*
*/
int Cell::GetRow() const
{
return this->Row;
}
/**
*
* Returns the column on which this cell is located on the board.
*
*/
int Cell::GetCol() const
{
return this->Col;
}
/**
*
* Marks the cell as visited when walking the labyrinth
*
*/
void Cell::MarkVisited()
{
Visited = true;
}
/**
*
* Marks the cell as not visited when walking the labyrinth
*
*/
void Cell::MarkNotVisited()
{
Visited = false;
}
/**
*
* Returns true if the cell has been visited when walking the labyrinth
*
*/
bool Cell::IsVisited() const
{
return Visited == true;
}
/**
*
* Returns a pointer to the Board this Cell object is part of
*
*/
const Board* Cell::GetBoard() const
{
return pBoard;
}
/**
*
* Returns the left neighbour of the cell, if such exists.
* Otherwise returns NULL.
*
*/
Cell* Cell::GetLeftNeighbour() const
{
return pBoard->GetCell(this->Row, this->Col - 1);
}
/**
*
* Returns the right neighbour of the cell, if such exists.
* Otherwise returns NULL.
*
*/
Cell* Cell::GetRightNeighbour() const
{
return pBoard->GetCell(this->Row, this->Col + 1);
}
/**
*
* Returns the top neighbour of the cell, if such exists.
* Otherwise returns NULL.
*
*/
Cell* Cell::GetTopNeighbour() const
{
return pBoard->GetCell(this->Row - 1, this->Col);
}
/**
*
* Returns the bottom neighbour of the cell, if such exists.
* Otherwise returns NULL.
*
*/
Cell* Cell::GetBottomNeighbour() const
{
return pBoard->GetCell(this->Row + 1, this->Col);
}
/**
*
* Displays information about the cell to STDOUT
*
*/
void Cell::PrintInfo() const
{
std::cout << "[ (" << Symbol
<< ") r" << Row
<< ", c" << Col
<< ", " << (IsPassable() ? "passable" : "BLOCKED")
<< ", " << (Visited ? "visited" : "NOT visited")
<< "]";
}
/**
*
* Specifies which Board object contains this Cell object
*
*/
void Cell::SetBoard(Board* pBoard)
{
this->pBoard = pBoard;
}
// Function computing the distance from a cell to the end/target cell
void Cell::ComputeScores(Cell* end)
{
far = ( abs(end->GetRow() - GetRow()) + abs(end->GetCol() - GetCol()) );
}