@@ -3,6 +3,7 @@ const tileImages = [];
3
3
let grid = [ ] ;
4
4
5
5
const DIM = 25 ;
6
+ const NB_UPDATES_PER_TICK = 5 ;
6
7
7
8
function preload ( ) {
8
9
// const path = 'rail';
@@ -114,39 +115,41 @@ function draw() {
114
115
}
115
116
}
116
117
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);
122
124
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
+ }
136
139
}
137
- }
138
140
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 ] ;
148
150
149
- grid = optimizedNextGrid ( cell ) ;
151
+ grid = optimizedNextGrid ( cell ) ;
152
+ }
150
153
}
151
154
152
155
// propagate options from src to dest. If dest is above src, dir == UP.
0 commit comments