File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -78,22 +78,23 @@ class Maze {
7878 * get unlocked.
7979 */
8080 countSteps ( from_id , to_coord , keys_collected ) {
81+ const sorted_keys = keys_collected . split ( '' ) . sort ( ) . join ( '' ) ;
8182 let current = to_coord ;
8283 let count = 0 ;
83- if ( ! this . count_cache [ keys_collected ] ) {
84- this . count_cache [ keys_collected ] = { } ;
84+ if ( ! this . count_cache [ sorted_keys ] ) {
85+ this . count_cache [ sorted_keys ] = { } ;
8586 }
8687 const came_from = this . pathfinders . get ( from_id ) ;
8788 const cache_key = `${ InfiniteGrid . toId ( ...current ) } /${ from_id } ` ;
88- if ( this . count_cache [ keys_collected ] [ cache_key ] === undefined ) {
89+ if ( this . count_cache [ sorted_keys ] [ cache_key ] === undefined ) {
8990 while ( InfiniteGrid . toId ( ...current ) !== from_id ) {
9091 count ++ ;
9192 current = came_from . get ( InfiniteGrid . toId ( ...current ) ) ;
9293 }
93- this . count_cache [ keys_collected ] [ cache_key ] = count ;
94+ this . count_cache [ sorted_keys ] [ cache_key ] = count ;
9495 }
9596
96- return this . count_cache [ keys_collected ] [ cache_key ] ;
97+ return this . count_cache [ sorted_keys ] [ cache_key ] ;
9798 }
9899
99100 getReachableKeys ( from_id , keys_collected ) {
You can’t perform that action at this time.
0 commit comments