@@ -175,9 +175,12 @@ class GridLayout extends Component {
175
175
document . getElementById ( `node-${ row } -${ col } ` ) . className = 'end' ;
176
176
}
177
177
if ( st ) {
178
- if ( ! node . iswall && ! node . isweight && ! node . strt && ! node . end ) {
178
+ if ( ! node . strt && ! node . end )
179
179
document . getElementById ( `node-${ row } -${ col } ` ) . className = '' ;
180
- }
180
+ if ( node . isweight )
181
+ document . getElementById ( `node-${ row } -${ col } ` ) . className += ' node-weight ' ;
182
+ if ( node . iswall )
183
+ document . getElementById ( `node-${ row } -${ col } ` ) . className += 'node-wall' ;
181
184
} else {
182
185
if ( ! node . iswall && ! node . strt && ! node . end ) {
183
186
document . getElementById ( `node-${ row } -${ col } ` ) . className = '' ;
@@ -187,7 +190,7 @@ class GridLayout extends Component {
187
190
}
188
191
}
189
192
190
- generateNewGridWithPreviousWalls ( ) {
193
+ generateNewGridWithPreviousWalls ( st ) {
191
194
const b = [ ] ;
192
195
for ( let row = 0 ; row < 23 ; row ++ ) {
193
196
const currRow = [ ] ;
@@ -205,8 +208,8 @@ class GridLayout extends Component {
205
208
aDis : 0 ,
206
209
aEndDis : 0 ,
207
210
isVisited : node . iswall ? node . isVisited : false ,
208
- isweight : false ,
209
- cost : 0 ,
211
+ isweight : st ? node . isweight : false ,
212
+ cost : st ? node . cost : 0 ,
210
213
previousNode : null ,
211
214
iswall : node . iswall
212
215
} ;
@@ -267,7 +270,7 @@ class GridLayout extends Component {
267
270
const ran = Math . floor ( Math . random ( ) * 5 + 1 ) ;
268
271
const box = this . state . boxes ;
269
272
270
-
273
+ console . log ( ran ) ;
271
274
const node = box [ row ] [ col ] ;
272
275
273
276
const val = {
@@ -301,14 +304,15 @@ class GridLayout extends Component {
301
304
302
305
if ( num === 1 ) {
303
306
return false
304
- } else {
305
- for ( let i = 2 ; i < this . prime ; i ++ ) {
307
+ } else
308
+ {
309
+ for ( let i = 2 ; i < this . prime ; i ++ ) {
306
310
if ( num % i === 0 ) {
307
- return false
311
+ return false ;
308
312
}
309
313
}
310
314
}
311
- return true
315
+ return true ;
312
316
}
313
317
314
318
even ( num ) {
@@ -339,6 +343,7 @@ class GridLayout extends Component {
339
343
this . setState ( {
340
344
boxes : val
341
345
} )
346
+ console . log ( val + " in random weight" ) ;
342
347
}
343
348
344
349
@@ -372,8 +377,8 @@ class GridLayout extends Component {
372
377
373
378
}
374
379
375
- clearGridForNewAlgo ( ) {
376
- let val = this . generateNewGridWithPreviousWalls ( ) ;
380
+ clearGridForNewAlgo ( st ) {
381
+ let val = this . generateNewGridWithPreviousWalls ( st ) ;
377
382
this . setState ( {
378
383
boxes : val
379
384
} )
@@ -510,7 +515,7 @@ class GridLayout extends Component {
510
515
visualizeDijkstra ( ) {
511
516
if ( this . state . boxes !== [ ] ) {
512
517
this . clearStyles ( true ) ;
513
- this . clearGridForNewAlgo ( ) ;
518
+ this . clearGridForNewAlgo ( true ) ;
514
519
}
515
520
516
521
@@ -600,7 +605,7 @@ class GridLayout extends Component {
600
605
visuaizeGBFS ( ) {
601
606
if ( this . state . boxes !== [ ] ) {
602
607
this . clearStyles ( true ) ;
603
- this . clearGridForNewAlgo ( ) ;
608
+ this . clearGridForNewAlgo ( true ) ;
604
609
}
605
610
console . log ( 'Started gbfs' ) ;
606
611
const { boxes } = this . state ;
@@ -616,7 +621,7 @@ class GridLayout extends Component {
616
621
visualizeaSearch ( ) {
617
622
if ( this . state . boxes !== [ ] ) {
618
623
this . clearStyles ( true ) ;
619
- this . clearGridForNewAlgo ( ) ;
624
+ this . clearGridForNewAlgo ( true ) ;
620
625
}
621
626
622
627
const { boxes } = this . state ;
@@ -786,7 +791,7 @@ class GridLayout extends Component {
786
791
} >
787
792
</ Header >
788
793
789
- < div id = "display" > < / div >
794
+ < div id = "display" >
790
795
791
796
792
797
< div className = "grid-container" > {
@@ -800,7 +805,7 @@ class GridLayout extends Component {
800
805
< GridBlock chng = { { start : this . state . start , func : this . change . bind ( this ) } }
801
806
row = { pos }
802
807
col = { pos2 }
803
- key = { `${ pos } -${ pos2 } ` }
808
+ key = { `${ pos } -${ pos2 } ` } z
804
809
start = { c . strt }
805
810
end = { c . end }
806
811
startnode = { this . state . start }
@@ -810,6 +815,7 @@ class GridLayout extends Component {
810
815
mouseIsPressed = { this . state . isMousePressed }
811
816
iswall = { c . iswall }
812
817
weight = { c . isweight }
818
+ cost = { c . cost }
813
819
814
820
onMouseDown = {
815
821
( row , col ) => this . handleMouseDown ( row , col )
@@ -829,6 +835,7 @@ class GridLayout extends Component {
829
835
) ; } )
830
836
} </ div >
831
837
</ div >
838
+ </ div >
832
839
) }
833
840
}
834
841
0 commit comments