-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.cpp
More file actions
192 lines (169 loc) · 4.05 KB
/
Block.cpp
File metadata and controls
192 lines (169 loc) · 4.05 KB
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
/**
* Authors: Alysha Aul, Nandhitha Krishnan, Paul Rodgers, Nouran Sakr, Chun Yang
* Date: November 7, 2023
* Purpose: To initialize a single point in a grid as a location on the map.
*/
#include "Block.h"
using namespace std;
/**
* This method sets the weight of the block.
* @param weight: the amount of energy required to traverse to the block
*/
void Block::setWeight(int blockWeight) {
weight = blockWeight;
}
/**
* This method sets the type of the block.
* @param type: The type of block (classroom, path, wall, etc.)
*/
void Block::setType(int blockType) {
type = blockType;
}
/**
* Sets an adjacent block as a neighbouring block.
* @param n: The adjacent block.
*/
void Block::setNeighbour(Block* n) {
neighbours.push_back(n);
}
/**
* Sets whether the block has been traversed.
* @param visited: true is yes, otherwise false.
*/
void Block::setVisit(bool visited) {
visit = visited;
}
/**
* Sets the block to being in the queue
* @param inQueue: true if block is in queue otherwise false.
*/
void Block::setInQueue(bool inQueue){
this->inQueue = inQueue;
}
/**
* Returns whether the block is in the queue
* @return inQueue: true if in queue otherwise false.
*/
bool Block::isInQueue() {
return inQueue;
}
/**
* Sets the minimum distance between the starting block and this block.
* @param blockDist: the distance from the starting block.
*/
void Block::setMinDistance(int blockDist) {
dist = blockDist;
}
/**
* Returns the weight of the block.
* @return weight: The weight of the block.
*/
int Block::getWeight() {
return weight;
}
/**
* Returns the type of the block.
* @return type: the block's type.
*/
int Block::getType() {
return type;
}
/**
* Returns the position of the block in terms of its row in the grid.
* @return row: the vertical position of the block.
*/
int Block::getRow() {
return row;
}
/**
* Returns the position of the block in terms of its column.
* @return column: the horizontal position of the block.
*/
int Block::getColumn() {
return column;
}
/**
* Returns a vector of the block's adjacent blocks.
* @return neighbours: a vector of adjacent blocks.
*/
vector<Block*> Block::getNeighbour() {
return neighbours;
}
/**
* Returns whether the block has been traversed.
* @return visit: true if yes, otherwise false.
*/
bool Block::visited() {
return visit;
}
/**
* Returns the distance from the starting node.
* @return dist: the distance from the starting node.
*/
int Block::getMinDistance() {
return dist;
}
/**
* Sets the previous block.
* @param block: The previous block.
*/
void Block::setPrevBlock(Block* block) {
prevBlock = block;
}
/**
* Gets the previous block.
* @return prevBlock: the previous block.
*/
Block* Block::getPrevBlock(){
return prevBlock;
}
/**
* method for A star algorithm
* distance from start node
* @param startRow: The start block row.
* @param startCol: The start block column.
* @param parent_node_g_cost: parent node's G cost
* @return true or false: check if the G cost was updated or not
*
*/
bool Block::updateGCost(int startRow, int startCol, int parent_node_g_cost){
if(g_cost > abs(startRow - row) + abs(startCol - column) + parent_node_g_cost){
g_cost = abs(startRow - row) + abs(startCol - column) + parent_node_g_cost;
return true;
}
return false;
}
/**
* method for A star algorithm
* @param cost: The G cost.
*
*/
void Block::setGCost(int cost) {
g_cost = cost;
}
/**
* method for A star algorithm
* distance from end node
* @param targetRow: target node row.
* @param targetCol: target node column.
*
*/
void Block::calculateHCost(int targetRow, int targetCol){
h_cost = abs(targetRow - row) + abs(targetCol - column);
}
/**
* Get the G cost of node
* @return g_cost: G cost of node.
*
*/
int Block::getGCost(){
return g_cost;
}
/**
* Get the H cost of node
* @return h_cost: H cost of node.
*
*/
int Block::getHCost(){
return h_cost;
}