@@ -14,24 +14,20 @@ export function RecursiveBacktrackCreation(board, start, end) {
1414 if ( start === undefined || start === null ) { startCell = board [ Math . floor ( Math . random ( ) * board . length ) ] ; }
1515 if ( end === undefined || end === null ) { endCell = board [ Math . floor ( Math . random ( ) * board . length ) ] ; }
1616 startCell . type = START_TYPE ;
17- startCell . visited = true ;
1817 endCell . type = GOAL_TYPE ;
1918 console . log ( 'Start: ' + startCell . id + ' (' + startCell . x + ' | ' + startCell . y + ')' ) ;
2019 console . log ( 'End: ' + endCell . id + ' (' + endCell . x + ' | ' + endCell . y + ')' ) ;
2120
22-
21+ startCell . visited = true ;
2322 carvePath ( board , startCell , false ) ;
2423
25- _SetWalls ( board ) ;
24+ // _SetWalls(board);
2625
2726
2827}
2928
3029
3130function carvePath ( board , cell , found ) {
32- if ( found ) {
33- return ;
34- }
3531 const neighbors = _GetNeighborsCell ( board , cell ) ;
3632 if ( neighbors . length === 0 ) {
3733 console . log ( 'No neighbors found for cell: ' + cell . id + ' (' + cell . x + ' | ' + cell . y + ')' ) ;
@@ -41,12 +37,16 @@ function carvePath(board, cell, found) {
4137 const neighbor = neighbors [ Math . floor ( Math . random ( ) * neighbors . length ) ] ;
4238 if ( ! neighbor . visited ) {
4339 if ( neighbor . type === GOAL_TYPE || found ) {
40+ console . log ( 'Found goal' ) ;
4441 found = true ;
45- return ;
42+ return found ;
4643 }
4744 neighbor . visited = true ;
4845 neighbor . type = FLOOR_TYPE ;
49- return carvePath ( board , neighbor , found ) ;
46+ found = carvePath ( board , neighbor , found ) ;
47+ if ( found ) {
48+ return found ;
49+ }
5050 }
5151 }
5252}
0 commit comments