File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change 1- const Queue = require ( 'double-ended-queue' ) ;
21const { InfiniteGrid } = require ( './infinite-grid' ) ;
32
43const ENTRANCE = '@' ;
@@ -213,7 +212,9 @@ class Maze {
213212 path . at_end = true ;
214213 }
215214 const sorted_keys_str = path . keys_collected . split ( '' ) . sort ( ) . join ( '' ) ;
216- const path_id = `${ JSON . stringify ( path . robots_coords ) } ;${ sorted_keys_str } ` ;
215+ const path_id = `${ JSON . stringify (
216+ path . robots_coords
217+ ) } ;${ sorted_keys_str } `;
217218 if ( pruned_paths . has ( path_id ) ) {
218219 // Don't store path if it is longer than current stored path
219220 if ( pruned_paths . get ( path_id , path ) . steps > path . steps ) {
@@ -236,10 +237,11 @@ class Maze {
236237 for ( let iter of [ this . entrances , this . keys ] ) {
237238 for ( let [ , coord ] of iter ) {
238239 const [ x , y ] = coord ;
239- const frontier = new Queue ( ) ;
240+ // Arrays as FIFO queues are slow, but fast enough here for these small(ish) numbers
241+ const frontier = [ ] ;
240242 frontier . push ( [ x , y ] ) ;
241243 const came_from = new Map ( [ [ InfiniteGrid . toId ( x , y ) , null ] ] ) ;
242- while ( ! frontier . isEmpty ( ) ) {
244+ while ( frontier . length ) {
243245 const current_coord = frontier . shift ( ) ;
244246 const neighbor_coords = this . grid
245247 . neighbors ( ...current_coord )
You can’t perform that action at this time.
0 commit comments