@@ -10,7 +10,7 @@ function AStar(s, e, row, col, inputGrid) {
10
10
const start = s ;
11
11
const end = e ;
12
12
13
- function cell ( ) {
13
+ function Cell ( ) {
14
14
this . cellValue = null ;
15
15
this . parent_i = - 1 ;
16
16
this . parent_j = - 1 ;
@@ -19,7 +19,7 @@ function AStar(s, e, row, col, inputGrid) {
19
19
this . f = Number . MAX_SAFE_INTEGER ;
20
20
}
21
21
22
- function pair ( i , j , f ) {
22
+ function Pair ( i , j , f ) {
23
23
this . i = i ;
24
24
this . j = j ;
25
25
this . f = f ;
@@ -30,15 +30,13 @@ function AStar(s, e, row, col, inputGrid) {
30
30
for ( let i = 0 ; i < Row ; i += 1 ) {
31
31
grid [ i ] = [ ] ;
32
32
for ( let j = 0 ; j < Col ; j += 1 ) {
33
- grid [ i ] [ j ] = new cell ( ) ;
33
+ grid [ i ] [ j ] = new Cell ( ) ;
34
34
grid [ i ] [ j ] . cellValue = inputGrid [ i ] [ j ] ;
35
35
}
36
36
}
37
37
38
38
const isValid = ( i , j ) => i >= 0 && j >= 0 && i < Row && j < Col ;
39
-
40
39
const isDestination = ( i , j ) => end . i === i && end . j === j ;
41
-
42
40
const isBlocked = ( i , j ) => grid [ i ] [ j ] . cellValue === 0 ;
43
41
44
42
const euclideanDistance = ( i , j ) =>
@@ -64,7 +62,7 @@ function AStar(s, e, row, col, inputGrid) {
64
62
}
65
63
path . push ( [ i , j ] ) ;
66
64
67
- for ( let i = 0 ; i < path . length ; i += 1 ) {
65
+ for ( let z = 0 ; z < path . length ; z += 1 ) {
68
66
console . log ( path [ i ] ) ;
69
67
}
70
68
} ;
@@ -101,7 +99,7 @@ function AStar(s, e, row, col, inputGrid) {
101
99
grid [ i ] [ j ] . h = h ;
102
100
grid [ i ] [ j ] . f = g + h ;
103
101
104
- const item = new pair ( i , j , f ) ;
102
+ const item = new Pair ( i , j , f ) ;
105
103
// can be improved by using Min-Heap DataStructure
106
104
if ( ! openList . length ) {
107
105
openList . push ( item ) ;
@@ -123,8 +121,8 @@ function AStar(s, e, row, col, inputGrid) {
123
121
return false ;
124
122
}
125
123
126
- let i = start . i ;
127
- let j = start . j ;
124
+ let { i } = start ;
125
+ let { j } = start ;
128
126
const openList = [ ] ;
129
127
const openListMap = new Map ( ) ;
130
128
const closedListMap = new Map ( ) ;
@@ -135,7 +133,7 @@ function AStar(s, e, row, col, inputGrid) {
135
133
grid [ i ] [ j ] . g = 0 ;
136
134
grid [ i ] [ j ] . f = 0 ;
137
135
138
- openList . push ( new pair ( i , j , 0.0 ) ) ;
136
+ openList . push ( new Pair ( i , j , 0.0 ) ) ;
139
137
140
138
openListMap [ [ i , j ] ] = 0 ;
141
139
0 commit comments