@@ -3,6 +3,7 @@ const tileImages = [];
33let grid = [ ] ;
44
55const DIM = 25 ;
6+ const NB_UPDATES_PER_TICK = 5 ;
67
78function preload ( ) {
89 // const path = 'rail';
@@ -114,39 +115,41 @@ function draw() {
114115 }
115116 }
116117
117- // Pick cell with least entropy
118- let gridCopy = grid . slice ( ) ;
119- gridCopy = gridCopy . filter ( ( a ) => ! a . collapsed ) ;
120- // console.table(grid);
121- // console.table(gridCopy);
118+ for ( let idxUpdate = 0 ; idxUpdate < NB_UPDATES_PER_TICK ; idxUpdate ++ ) {
119+ // Pick cell with least entropy
120+ let gridCopy = grid . slice ( ) ;
121+ gridCopy = gridCopy . filter ( ( a ) => ! a . collapsed ) ;
122+ // console.table(grid);
123+ // console.table(gridCopy);
122124
123- if ( gridCopy . length == 0 ) {
124- return ;
125- }
126- gridCopy . sort ( ( a , b ) => {
127- return a . options . length - b . options . length ;
128- } ) ;
129-
130- let len = gridCopy [ 0 ] . options . length ;
131- let stopIndex = 0 ;
132- for ( let i = 1 ; i < gridCopy . length ; i ++ ) {
133- if ( gridCopy [ i ] . options . length > len ) {
134- stopIndex = i ;
135- break ;
125+ if ( gridCopy . length == 0 ) {
126+ return ;
127+ }
128+ gridCopy . sort ( ( a , b ) => {
129+ return a . options . length - b . options . length ;
130+ } ) ;
131+
132+ let len = gridCopy [ 0 ] . options . length ;
133+ let stopIndex = 0 ;
134+ for ( let i = 1 ; i < gridCopy . length ; i ++ ) {
135+ if ( gridCopy [ i ] . options . length > len ) {
136+ stopIndex = i ;
137+ break ;
138+ }
136139 }
137- }
138140
139- if ( stopIndex > 0 ) gridCopy . splice ( stopIndex ) ;
140- const cell = random ( gridCopy ) ;
141- cell . collapsed = true ;
142- const pick = random ( cell . options ) ;
143- if ( pick === undefined ) {
144- startOver ( ) ;
145- return ;
146- }
147- cell . options = [ pick ] ;
141+ if ( stopIndex > 0 ) gridCopy . splice ( stopIndex ) ;
142+ const cell = random ( gridCopy ) ;
143+ cell . collapsed = true ;
144+ const pick = random ( cell . options ) ;
145+ if ( pick === undefined ) {
146+ startOver ( ) ;
147+ return ;
148+ }
149+ cell . options = [ pick ] ;
148150
149- grid = optimizedNextGrid ( cell ) ;
151+ grid = optimizedNextGrid ( cell ) ;
152+ }
150153}
151154
152155// propagate options from src to dest. If dest is above src, dir == UP.
0 commit comments