File tree Expand file tree Collapse file tree
animations/backtracking-maze/js Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,7 +16,6 @@ class Sketch extends Engine {
1616 this . _solution_color = Color . fromHEX ( "#218380" ) ;
1717 this . _visited_color = Color . fromHEX ( "#ffbc42" ) ;
1818 this . _start = [ 1 , 1 ] ;
19- this . _end = [ this . _cols - 2 , this . _cols - 2 ] ;
2019
2120 this . _single_frame_generation = false ;
2221 this . _single_frame_solution = false ;
@@ -38,6 +37,7 @@ class Sketch extends Engine {
3837 this . _xor128 = new XOR128 ( this . _seed ) ;
3938 this . _cols = this . _xor128 . random_int ( 80 , 120 ) ;
4039 if ( this . _cols % 2 === 0 ) this . _cols ++ ; // Ensure cols is odd for maze generation
40+ this . _end = [ this . _cols - 2 , this . _cols - 2 ] ;
4141
4242 this . _generation_first_step = true ;
4343 this . _solution_first_step = true ;
@@ -126,8 +126,10 @@ class Sketch extends Engine {
126126 }
127127
128128 _solutionNextStep ( ) {
129+ if ( this . _solution_stack . length === 0 ) return true ;
129130 // find the node with the lowest f score
130131 const current = this . _lowestFScore ( ) ;
132+ if ( current == null ) return true ;
131133 const [ cx , cy ] = this . _i_to_xy ( current ) ;
132134 // add the current node to the visited set for visualization
133135 this . _solution_visited [ current ] = true ;
You can’t perform that action at this time.
0 commit comments