@@ -3,6 +3,7 @@ const tileImages = [];
3
3
let grid = [ ] ;
4
4
5
5
const DIM = 25 ;
6
+ const NB_UPDATES_PER_TICK = 1 ;
6
7
7
8
function preload ( ) {
8
9
// Load tile images
@@ -95,37 +96,39 @@ function draw() {
95
96
}
96
97
}
97
98
98
- // Pick cell with least entropy
99
- let gridCopy = grid . slice ( ) ;
100
- gridCopy = gridCopy . filter ( ( a ) => ! a . collapsed ) ;
99
+ for ( let idxUpdate = 0 ; idxUpdate < NB_UPDATES_PER_TICK ; idxUpdate ++ ) {
100
+ // Pick cell with least entropy
101
+ let gridCopy = grid . slice ( ) ;
102
+ gridCopy = gridCopy . filter ( ( a ) => ! a . collapsed ) ;
101
103
102
- if ( gridCopy . length == 0 ) {
103
- return ;
104
- }
105
- gridCopy . sort ( ( a , b ) => {
106
- return a . options . length - b . options . length ;
107
- } ) ;
108
-
109
- let len = gridCopy [ 0 ] . options . length ;
110
- let stopIndex = 0 ;
111
- for ( let i = 1 ; i < gridCopy . length ; i ++ ) {
112
- if ( gridCopy [ i ] . options . length > len ) {
113
- stopIndex = i ;
114
- break ;
104
+ if ( gridCopy . length == 0 ) {
105
+ return ;
106
+ }
107
+ gridCopy . sort ( ( a , b ) => {
108
+ return a . options . length - b . options . length ;
109
+ } ) ;
110
+
111
+ let len = gridCopy [ 0 ] . options . length ;
112
+ let stopIndex = 0 ;
113
+ for ( let i = 1 ; i < gridCopy . length ; i ++ ) {
114
+ if ( gridCopy [ i ] . options . length > len ) {
115
+ stopIndex = i ;
116
+ break ;
117
+ }
115
118
}
116
- }
117
119
118
- if ( stopIndex > 0 ) gridCopy . splice ( stopIndex ) ;
119
- const cell = random ( gridCopy ) ;
120
- cell . collapsed = true ;
121
- const pick = random ( cell . options ) ;
122
- if ( pick === undefined ) {
123
- startOver ( ) ;
124
- return ;
125
- }
126
- cell . options = [ pick ] ;
120
+ if ( stopIndex > 0 ) gridCopy . splice ( stopIndex ) ;
121
+ const cell = random ( gridCopy ) ;
122
+ cell . collapsed = true ;
123
+ const pick = random ( cell . options ) ;
124
+ if ( pick === undefined ) {
125
+ startOver ( ) ;
126
+ return ;
127
+ }
128
+ cell . options = [ pick ] ;
127
129
128
- grid = optimizedNextGrid ( cell ) ;
130
+ grid = nextGrid ( cell ) ;
131
+ }
129
132
}
130
133
131
134
// propagate options from src to dest. If dest is above src, dir == UP.
@@ -135,7 +138,7 @@ function propagate(src, dest, dir) {
135
138
return oldLen != dest . options . length ;
136
139
}
137
140
138
- function optimizedNextGrid ( pick ) {
141
+ function nextGrid ( pick ) {
139
142
let touched = [ posIdx ( pick . i , pick . j ) ] ;
140
143
141
144
while ( touched . length > 0 ) {
0 commit comments