@@ -35,7 +35,7 @@ World.add(world, walls)
3535const shuffle = ( arr ) => {
3636 let counter = arr . length
3737
38- while ( counter > 0 ) {
38+ while ( counter > 0 ) {
3939 const index = Math . floor ( Math . random ( ) * counter )
4040
4141 counter --
@@ -77,21 +77,29 @@ const stepThroughCell = (row, column) => {
7777
7878 // Assemble randomly-ordered list of neighbors
7979 const neighbors = shuffle ( [
80- [ row - 1 , column ] ,
81- [ row , column + 1 ] ,
82- [ row + 1 , column ] ,
83- [ row , column - 1 ] ,
80+ [ row - 1 , column , 'up' ] ,
81+ [ row , column + 1 , 'right' ] ,
82+ [ row + 1 , column , 'down' ] ,
83+ [ row , column - 1 , 'left' ] ,
8484 ] )
85- console . log ( neighbors ) ;
85+ console . log ( neighbors )
8686
8787 // For each neighbor....
88+ for ( let neighbor of neighbors ) {
89+ const [ nextRow , nextColumn ] = neighbor
8890
89- // See if that neighbor is out of bounds
91+ // See if that neighbor is out of bounds
92+ if ( nextRow < 0 || nextRow >= cells || nextColumn < 0 || nextColumn >= ce ) {
93+ continue
94+ }
9095
91- // If we have visited that neighbor, continue to next neighbor
92-
93- // Remove a wall from either horizontals or verticals
96+ // If we have visited that neighbor, continue to next neighbor
97+ if ( grid [ nextRow ] [ nextColumn ] ) {
98+ continue
99+ }
94100
101+ // Remove a wall from either horizontals or verticals
102+ }
95103 // Visit that next cell
96104}
97105
0 commit comments