11/*
22 * Quick selection test
33 */
4- import { FLOOR_TYPE , FLOOR_COLOR , WALL_TYPE , WALL_COLOR ,
4+ import {
5+ FLOOR_TYPE , FLOOR_COLOR , WALL_TYPE , WALL_COLOR ,
56 getColor , GOAL_TYPE , START_TYPE , SELECTED_COLOR ,
67 BURN_COLOR , PATH_TYPE , PATH_COLOR , DEFAULT_COLOR ,
7- DEFAULT_TYPE } from '../../../Utility/Colors' ;
8- import { directions } from './Directions' ;
8+ DEFAULT_TYPE ,
9+ } from '../../../Utility/Colors' ;
10+ import { directions } from './Directions' ;
911
1012
1113
@@ -41,6 +43,7 @@ export function _FindCell(board, x, y) {
4143 return null ;
4244} ;
4345
46+
4447export function _GetNeighborsUnvisited ( board , cell ) {
4548 let neighbors = [ ] ;
4649 for ( let i = 0 ; i < directions . length ; i ++ ) {
@@ -56,8 +59,8 @@ export function _GetNeighborsUnvisited(board, cell) {
5659export function _GetNeighbors ( board , x , y ) {
5760 let neighbors = [ ] ;
5861 for ( let i = 0 ; i < 4 ; i ++ ) {
59- let xcoord = x + directions [ i ] . x ;
60- let ycoord = y + directions [ i ] . y ;
62+ let xcoord = x + directions [ i ] . x ;
63+ let ycoord = y + directions [ i ] . y ;
6164 let neighbor = _FindCell ( board , xcoord , ycoord ) ;
6265 if ( neighbor ) {
6366 if ( neighbor . type !== WALL_TYPE ) {
@@ -68,39 +71,47 @@ export function _GetNeighbors(board, x, y) {
6871 return neighbors ;
6972}
7073
74+
7175export function _GetNeighborsCell ( board , cell ) {
7276 let neighbors = [ ] ;
7377 for ( let i = 0 ; i < 4 ; i ++ ) {
74- let xcoord = cell . x + directions [ i ] . x ;
75- let ycoord = cell . y + directions [ i ] . y ;
78+ let xcoord = cell . x + directions [ i ] . x ;
79+ let ycoord = cell . y + directions [ i ] . y ;
7680 let neighbor = _FindCell ( board , xcoord , ycoord ) ;
7781 if ( neighbor ) {
78- neighbors . push ( neighbor ) ;
82+ neighbors . push ( neighbor ) ;
7983
8084 }
8185 }
8286 return neighbors ;
8387}
8488
8589
90+ export function shuffle ( array ) {
91+ array . sort ( ( ) => Math . random ( ) - 0.5 ) ;
92+ }
93+
94+
8695export function _BoardReset ( board ) {
8796 for ( let i = 0 ; i < board . length ; i ++ ) {
8897 board [ i ] . visited = false ;
89- board [ i ] . type = DEFAULT_TYPE ;
98+ board [ i ] . type = DEFAULT_TYPE ;
9099 }
91100}
92101
102+
93103/*
94104 * Walled board reset with the intent of creating a maze
95105 * through the use of the recursive backtracking algorithm.
96106 */
97107export function _BoardResetWalled ( board ) {
98108 for ( let i = 0 ; i < board . length ; i ++ ) {
99109 board [ i ] . visited = false ;
100- board [ i ] . type = WALL_TYPE ;
110+ board [ i ] . type = WALL_TYPE ;
101111 }
102112}
103113
114+
104115export function _VisitReset ( board ) {
105116 for ( let i = 0 ; i < board . length ; i ++ ) {
106117 board [ i ] . visited = false ;
0 commit comments