-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTile.js
131 lines (106 loc) · 2.34 KB
/
Tile.js
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
class Tile {
constructor(row, col, explored = false, blocked = false, parent = null, h_value = 0, g_value = 0) {
this.row = row;
this.col = col;
this.explored = explored; //whether is is explored or not
this.blocked = blocked; //whether it is blocked or not
this.parent = parent; //pointer to parent tile
this.h_value = null; //estimated cost from tile to goal
this.g_value = null; //path cost from start to tile
this.f_value = null; //h + g, gives estimated cost of the cheapest solution til this tile
this.start = false;
this.goal = false;
this.current = false;
this.solution = false;
}
//Special Colors
setStart(){
this.start = true;
this.goal = false;
// this.explored = true;
}
setGoal(){
if(this.start){
return false;
} else {
this.goal = true;
// this.explored = true;
return true;
}
}
forceGoal(){
this.goal = true;
this.start = false;
}
isGoal(){
return this.goal;
}
setCurrent(){
this.current = true;
}
removeCurrent(){
this.current = false;
}
//Coordinates
getRow(){
return this.row;
}
getCol(){
return this.col;
}
//Exploration
setExplored() {
this.explored = true;
}
setUnexplored() {
this.explored = false;
}
getExplore(){
return this.explored;
}
//Block
setBlocked() {
this.blocked = true;
}
setUnblocked() {
this.blocked = false;
}
getBlock(){
return this.blocked;
}
//Parent
getParent(){
return this.parent;
}
setParent(parent){
this.parent = parent;
}
//h value
getValueH(){
return this.h_value;
}
setValueH(h_value){
this.h_value = h_value;
}
//g value
getValueG(){
return this.g_value;
}
setValueG(g_value){
this.g_value = g_value;
}
//f value
getValueF(){
return this.f_value;
}
setValueF(){
this.f_value = this.g_value + this.h_value;
}
setSolution(){
this.solution = true;
}
removeSolution(){
this.solution = false;
}
}
export default Tile;