@woosh/meep-engine 2.138.13 → 2.138.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -1
  2. package/package.json +1 -1
  3. package/samples/terrain/from_image_2.js +2 -10
  4. package/src/engine/asset/loaders/image/ImageDecoderWorker.js +1 -1
  5. package/src/engine/asset/loaders/image/ImageRGBADataLoader.d.ts.map +1 -1
  6. package/src/engine/asset/loaders/image/ImageRGBADataLoader.js +6 -1
  7. package/src/engine/asset/loaders/image/png/PNGReader.d.ts +1 -99
  8. package/src/engine/asset/loaders/image/png/PNGReader.d.ts.map +1 -1
  9. package/src/engine/asset/loaders/image/png/PNGReader.js +31 -420
  10. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.d.ts +12 -0
  11. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.d.ts.map +1 -0
  12. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.js +53 -0
  13. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.d.ts +10 -0
  14. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.d.ts.map +1 -0
  15. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.js +42 -0
  16. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterAverage.d.ts +18 -0
  17. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterAverage.d.ts.map +1 -0
  18. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterAverage.js +59 -0
  19. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.d.ts +17 -0
  20. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.d.ts.map +1 -0
  21. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.js +55 -0
  22. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterPaeth.d.ts +17 -0
  23. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterPaeth.d.ts.map +1 -0
  24. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterPaeth.js +74 -0
  25. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.d.ts +15 -0
  26. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.d.ts.map +1 -0
  27. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.js +34 -0
  28. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.d.ts +16 -0
  29. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.d.ts.map +1 -0
  30. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.js +46 -0
  31. package/src/engine/asset/loaders/image/png/inflate.d.ts +7 -0
  32. package/src/engine/asset/loaders/image/png/inflate.d.ts.map +1 -0
  33. package/src/engine/asset/loaders/image/png/inflate.js +20 -0
  34. package/src/engine/ecs/terrain/ecs/Terrain.js +1 -1
  35. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.d.ts.map +1 -1
  36. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.js +32 -9
  37. package/src/engine/graphics/impostors/octahedral/prototypeBaker.js +202 -8
  38. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.d.ts +10 -0
  39. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.d.ts.map +1 -0
  40. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.js +418 -0
  41. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.d.ts +14 -0
  42. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.d.ts.map +1 -0
  43. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.js +757 -0
  44. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.d.ts +13 -0
  45. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.d.ts.map +1 -0
  46. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.js +380 -0
  47. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderPerPixelV0.d.ts +6 -0
  48. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderPerPixelV0.d.ts.map +1 -0
  49. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderPerPixelV0.js +406 -0
  50. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.d.ts.map +1 -1
  51. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.js +8 -1
  52. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.d.ts +14 -0
  53. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.d.ts.map +1 -0
  54. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.js +356 -0
  55. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderWireframeV0.d.ts.map +1 -1
  56. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderWireframeV0.js +4 -1
  57. package/src/engine/graphics/shaders/TerrainShader.js +2 -2
  58. package/src/engine/intelligence/mcts/MonteCarlo.d.ts +35 -4
  59. package/src/engine/intelligence/mcts/MonteCarlo.d.ts.map +1 -1
  60. package/src/engine/intelligence/mcts/MonteCarlo.js +101 -31
  61. package/src/engine/intelligence/mcts/StateNode.d.ts +47 -24
  62. package/src/engine/intelligence/mcts/StateNode.d.ts.map +1 -1
  63. package/src/engine/intelligence/mcts/StateNode.js +364 -316
@@ -1,316 +1,364 @@
1
- import { assert } from "../../../core/assert.js";
2
- import { MoveEdge } from "./MoveEdge.js";
3
-
4
- /**
5
- *
6
- * @enum {number}
7
- */
8
- export const StateType = {
9
- Undecided: 0,
10
- Win: 1,
11
- Loss: 2,
12
- Tie: 3,
13
- DepthCapped: 4,
14
- NoMoves: 5
15
- };
16
-
17
- /**
18
- *
19
- * @param {MoveEdge} move
20
- * @param {number} totalPlayouts
21
- * @param {number} totalUncertainPlayouts
22
- * @returns {number}
23
- */
24
- function computeScore(move, totalPlayouts, totalUncertainPlayouts) {
25
- /**
26
- *
27
- * @type {StateNode}
28
- */
29
- const stateNode = move.target;
30
-
31
- const playouts = stateNode.playouts;
32
-
33
- if (playouts === 0) {
34
- return 0;
35
- }
36
-
37
- let score = 0;
38
-
39
- const wins = stateNode.wins;
40
-
41
- if (wins !== 0) {
42
-
43
- score += wins / playouts;
44
- } else {
45
- // TODO consider if the heuristic can bias the outcome in undesirable ways
46
- // use heuristic instead of actual score
47
- score = stateNode.heuristicValue;
48
- }
49
-
50
- return score;
51
- }
52
-
53
-
54
- let stack_pointer = 0;
55
-
56
- /**
57
- *
58
- * @type {StateNode[]}
59
- */
60
- const stack = [];
61
-
62
-
63
- /**
64
- * @template State, Action
65
- * @author Alex Goldring
66
- * @copyright Company Named Limited (c) 2025
67
- */
68
- export class StateNode {
69
-
70
- /**
71
- * How deep is the node in the tree
72
- * @type {number}
73
- */
74
- depth = 0;
75
-
76
- /**
77
- *
78
- * @type {number}
79
- */
80
- wins = 0;
81
-
82
- /**
83
- * Number of leses in the subtree of this state
84
- * @type {number}
85
- */
86
- losses = 0;
87
-
88
-
89
- /**
90
- * total number of explored playouts
91
- * @type {number}
92
- */
93
- playouts = 0;
94
-
95
- /**
96
- *
97
- * @type {number}
98
- */
99
- heuristicValue = 0;
100
-
101
- /**
102
- * parent node, previous state
103
- * @type {null|StateNode}
104
- */
105
- parent = null;
106
-
107
- /**
108
- *
109
- * @type {null|MoveEdge[]}
110
- */
111
- moves = null;
112
-
113
- /**
114
- *
115
- * @type {StateType}
116
- */
117
- type = StateType.Undecided;
118
-
119
-
120
- bubbleUpHeuristicScore() {
121
- let r = this.parent;
122
-
123
- while (r !== null) {
124
- r.aggregateHeuristicScore();
125
-
126
- r = r.parent;
127
- }
128
-
129
- }
130
-
131
- /**
132
- * Aggregate heuristic score from children
133
- */
134
- aggregateHeuristicScore() {
135
- const moves = this.moves;
136
-
137
- if (moves === null) {
138
- //do nothing
139
- return;
140
- }
141
-
142
- const n = moves.length;
143
-
144
- let score = this.heuristicValue
145
-
146
- for (let i = 0; i < n; i++) {
147
- /**
148
- *
149
- * @type {MoveEdge}
150
- */
151
- const move = moves[i];
152
-
153
- if (!move.isTargetMaterialized()) {
154
- continue;
155
- }
156
-
157
- /**
158
- *
159
- * @type {StateNode}
160
- */
161
- const target = move.target;
162
-
163
- const childScore = target.heuristicValue;
164
-
165
- // take the lowest score as a heuristic
166
- if (childScore < score) {
167
- score = childScore;
168
- }
169
-
170
- }
171
-
172
- this.heuristicValue = score;
173
- }
174
-
175
- /**
176
- * @param state
177
- * @param {function(State, source:StateNode):MoveEdge[]} computeValidMoves
178
- * @param computeTerminalFlag
179
- * @returns {number} number of children
180
- */
181
- expand(state, computeValidMoves, computeTerminalFlag) {
182
- /**
183
- *
184
- * @type {MoveEdge[]}
185
- */
186
- const moves = computeValidMoves(state, this);
187
-
188
- assert.notNull(moves, 'moves');
189
- assert.defined(moves, 'moves');
190
- assert.isArray(moves, 'moves');
191
-
192
- const numMoves = moves.length;
193
-
194
- this.moves = moves;
195
-
196
- if (numMoves === 0) {
197
-
198
- //mark node as terminal
199
- this.type = StateType.NoMoves;
200
-
201
- }
202
-
203
- return numMoves;
204
- }
205
-
206
-
207
- /**
208
- *
209
- * @param {number} playouts
210
- * @param {number} wins
211
- * @param {number} losses
212
- */
213
- addPlayouts(playouts, wins, losses) {
214
- let node = this;
215
-
216
- do {
217
-
218
- node.playouts += playouts;
219
- node.wins += wins;
220
- node.losses += losses;
221
-
222
- node = node.parent;
223
-
224
- } while (node !== null);
225
- }
226
-
227
-
228
- /**
229
- * Whenever this is a terminal state or not (win/loss)
230
- * @returns {boolean}
231
- */
232
- isTerminal() {
233
- return this.type !== 0;
234
- }
235
-
236
- /**
237
- *
238
- * @returns {boolean}
239
- */
240
- isExpanded() {
241
- return this.moves !== null;
242
- }
243
-
244
- /**
245
- *
246
- * @returns {MoveEdge[]}
247
- */
248
- pickBestMoves() {
249
- const totalPlayouts = this.playouts;
250
- const totalUncertainPlayouts = totalPlayouts - (this.wins + this.losses);
251
-
252
- const moves = this.moves;
253
- const numMoves = moves.length;
254
-
255
-
256
- if (numMoves === 0) {
257
- //no moves
258
- return [];
259
- }
260
-
261
- const firstMove = moves[0];
262
-
263
- let result = [firstMove];
264
- let bestScore = computeScore(firstMove, totalPlayouts, totalUncertainPlayouts);
265
-
266
- for (let i = 1; i < numMoves; i++) {
267
-
268
- const move = moves[i];
269
-
270
- const score = computeScore(move, totalPlayouts, totalUncertainPlayouts);
271
-
272
- if (score > bestScore) {
273
- bestScore = score;
274
- result = [move];
275
- } else if (score === bestScore) {
276
- result.push(move);
277
- }
278
- }
279
-
280
- return result;
281
- }
282
-
283
- /**
284
- *
285
- * @param {function(StateNode)} visitor
286
- */
287
- traverse(visitor) {
288
- const stackOffset = stack_pointer;
289
-
290
- stack[stack_pointer++] = this;
291
-
292
- let n;
293
-
294
- while (stack_pointer-- > stackOffset) {
295
-
296
- n = stack[stack_pointer];
297
-
298
- visitor(n);
299
-
300
- if (n.isExpanded()) {
301
-
302
- const moves = n.moves;
303
- const numMoves = moves.length;
304
-
305
- for (let i = 0; i < numMoves; i++) {
306
- const moveEdge = moves[i];
307
-
308
- if (moveEdge.isTargetMaterialized()) {
309
- stack[stack_pointer++] = moveEdge.target;
310
- }
311
- }
312
- }
313
- }
314
-
315
- }
316
- }
1
+ import { assert } from "../../../core/assert.js";
2
+ import { MoveEdge } from "./MoveEdge.js";
3
+
4
+ /**
5
+ * Coarse classification of a node's terminal status, independent of payoff.
6
+ * The actual per-player payoff lives in {@link StateNode#outcome}.
7
+ * @enum {number}
8
+ */
9
+ export const StateType = {
10
+ /** Game can still continue from this state. */
11
+ Undecided: 0,
12
+ /** Game ended at this state per the game's rules. Payoff in `outcome`. */
13
+ Terminal: 1,
14
+ /** Search hit `maxExplorationDepth` here; heuristic stands in for payoff. */
15
+ DepthCapped: 2,
16
+ /** Expansion produced no legal moves. Treated as terminal; payoff in `outcome`. */
17
+ NoMoves: 3
18
+ };
19
+
20
+ /**
21
+ * Average outcome for `player` across all playouts that visited this child node.
22
+ * Falls back to heuristic when the node has not been rolled out yet.
23
+ * @param {MoveEdge} move
24
+ * @param {number} player
25
+ * @returns {number}
26
+ */
27
+ function pickBestScore(move, player) {
28
+ assert.isNonNegativeInteger(player, 'player');
29
+
30
+ const node = move.target;
31
+
32
+ if (node.playouts === 0) {
33
+ return node.heuristicValue[player];
34
+ }
35
+
36
+ return node.totalScore[player] / node.playouts;
37
+ }
38
+
39
+
40
+ let stack_pointer = 0;
41
+
42
+ /**
43
+ *
44
+ * @type {StateNode[]}
45
+ */
46
+ const stack = [];
47
+
48
+
49
+ /**
50
+ * @template State, Action
51
+ * @author Alex Goldring
52
+ * @copyright Company Named Limited (c) 2025
53
+ */
54
+ export class StateNode {
55
+
56
+ /**
57
+ * How deep is the node in the tree
58
+ * @type {number}
59
+ */
60
+ depth = 0;
61
+
62
+ /**
63
+ * Total number of explored playouts through this node.
64
+ * @type {number}
65
+ */
66
+ playouts = 0;
67
+
68
+ /**
69
+ * Per-player heuristic estimate of the value of this state.
70
+ * For terminal nodes this mirrors {@link StateNode#outcome}.
71
+ * For internal nodes this is refined by maxN backup as children materialize.
72
+ * Index = player ID.
73
+ * @type {Float64Array | null}
74
+ */
75
+ heuristicValue = null;
76
+
77
+ /**
78
+ * Per-player cumulative payoff aggregated by backpropagation.
79
+ * Average value for player `p` is `totalScore[p] / playouts` once `playouts > 0`.
80
+ * @type {Float64Array | null}
81
+ */
82
+ totalScore = null;
83
+
84
+ /**
85
+ * Per-player payoff at this terminal node, cached at materialization.
86
+ * `null` for non-terminal nodes (uses {@link StateNode#heuristicValue} as a stand-in).
87
+ * @type {Float64Array | null}
88
+ */
89
+ outcome = null;
90
+
91
+ /**
92
+ * Player ID of whoever chooses the next move from this state.
93
+ * `-1` for terminal nodes (no decision to make).
94
+ * @type {number}
95
+ */
96
+ activePlayer = -1;
97
+
98
+ /**
99
+ * @type {null|StateNode}
100
+ */
101
+ parent = null;
102
+
103
+ /**
104
+ *
105
+ * @type {null|MoveEdge[]}
106
+ */
107
+ moves = null;
108
+
109
+ /**
110
+ *
111
+ * @type {StateType}
112
+ */
113
+ type = StateType.Undecided;
114
+
115
+ /**
116
+ * Allocate the per-player buffers. Must be called before any backprop or selection.
117
+ * @param {number} numPlayers
118
+ */
119
+ allocate(numPlayers) {
120
+ assert.isNonNegativeInteger(numPlayers, 'numPlayers');
121
+
122
+ this.heuristicValue = new Float64Array(numPlayers);
123
+ this.totalScore = new Float64Array(numPlayers);
124
+ }
125
+
126
+ bubbleUpHeuristicScore() {
127
+ let r = this.parent;
128
+
129
+ while (r !== null) {
130
+ r.aggregateHeuristicScore();
131
+
132
+ r = r.parent;
133
+ }
134
+ }
135
+
136
+ /**
137
+ * maxN backup: the active player picks the child that maximizes their own
138
+ * component; the chosen child's entire heuristic vector is copied here.
139
+ *
140
+ * This generalizes minimax across N players and asymmetric turn orders: the
141
+ * non-active components ride along, representing "what would happen to player Y
142
+ * if X plays the way X wants from this state".
143
+ */
144
+ aggregateHeuristicScore() {
145
+ const moves = this.moves;
146
+
147
+ if (moves === null) {
148
+ return;
149
+ }
150
+
151
+ const p = this.activePlayer;
152
+
153
+ if (p < 0) {
154
+ // terminal node — no decision to make, heuristicValue already reflects outcome
155
+ return;
156
+ }
157
+
158
+ const own = this.heuristicValue;
159
+ let bestVec = own;
160
+ let bestVal = own[p];
161
+
162
+ const n = moves.length;
163
+
164
+ for (let i = 0; i < n; i++) {
165
+ /**
166
+ * @type {MoveEdge}
167
+ */
168
+ const move = moves[i];
169
+
170
+ if (!move.isTargetMaterialized()) {
171
+ continue;
172
+ }
173
+
174
+ const childVec = move.target.heuristicValue;
175
+ const val = childVec[p];
176
+
177
+ if (val > bestVal) {
178
+ bestVal = val;
179
+ bestVec = childVec;
180
+ }
181
+ }
182
+
183
+ if (bestVec !== own) {
184
+ own.set(bestVec);
185
+ }
186
+ }
187
+
188
+ /**
189
+ * @param state
190
+ * @param {function(State, source:StateNode):MoveEdge[]} computeValidMoves
191
+ * @param {function(State):number} computeActivePlayer
192
+ * @param {function(State):Float64Array} computeOutcome called when expansion produces no moves
193
+ * @returns {number} number of children
194
+ */
195
+ expand(state, computeValidMoves, computeActivePlayer, computeOutcome) {
196
+ assert.defined(state, 'state');
197
+ assert.isFunction(computeValidMoves, 'computeValidMoves');
198
+ assert.isFunction(computeActivePlayer, 'computeActivePlayer');
199
+ assert.isFunction(computeOutcome, 'computeOutcome');
200
+
201
+
202
+ /**
203
+ *
204
+ * @type {MoveEdge[]}
205
+ */
206
+ const moves = computeValidMoves(state, this);
207
+
208
+ assert.notNull(moves, 'moves');
209
+ assert.defined(moves, 'moves');
210
+ assert.isArray(moves, 'moves');
211
+
212
+ const numMoves = moves.length;
213
+
214
+ this.moves = moves;
215
+
216
+ if (numMoves === 0) {
217
+ // No legal moves → terminal by exhaustion. Cache outcome so subsequent
218
+ // visits don't recompute, and seed heuristicValue with it.
219
+ // Copy into our own buffer so the user is free to reuse the source;
220
+ // outcome and heuristicValue share storage within the node (safe since
221
+ // terminal nodes are skipped by aggregateHeuristicScore).
222
+ this.type = StateType.NoMoves;
223
+ this.activePlayer = -1;
224
+
225
+ const out = computeOutcome(state);
226
+
227
+ assert.defined(out, 'out');
228
+ assert.isArrayLike(out, 'out');
229
+
230
+ this.heuristicValue.set(out);
231
+ this.outcome = this.heuristicValue;
232
+ } else {
233
+
234
+ this.activePlayer = computeActivePlayer(state);
235
+
236
+ assert.isNumber(this.activePlayer, 'activePlayer');
237
+ }
238
+
239
+ return numMoves;
240
+ }
241
+
242
+
243
+ /**
244
+ * Walk up from this node to the root, adding the per-player outcome to each
245
+ * ancestor's cumulative score and incrementing their visit count.
246
+ * @param {Float64Array} outcomeVector indexed by player ID
247
+ */
248
+ backpropagate(outcomeVector) {
249
+ assert.defined(outcomeVector, 'outcomeVector');
250
+ assert.isArrayLike(outcomeVector, 'outcomeVector');
251
+ assert(outcomeVector.length > 0, 'outcomeVector must not be empty');
252
+
253
+ const len = outcomeVector.length;
254
+ let node = this;
255
+
256
+ do {
257
+ node.playouts += 1;
258
+
259
+ const score = node.totalScore;
260
+ for (let p = 0; p < len; p++) {
261
+ score[p] += outcomeVector[p];
262
+ }
263
+
264
+ node = node.parent;
265
+
266
+ } while (node !== null);
267
+ }
268
+
269
+
270
+ /**
271
+ * Whenever this is a terminal state or not (win/loss/tie/no-moves/depth-cap)
272
+ * @returns {boolean}
273
+ */
274
+ isTerminal() {
275
+ return this.type !== StateType.Undecided;
276
+ }
277
+
278
+ /**
279
+ *
280
+ * @returns {boolean}
281
+ */
282
+ isExpanded() {
283
+ return this.moves !== null;
284
+ }
285
+
286
+ /**
287
+ * Pick the best moves from this node's perspective — i.e. for whichever
288
+ * player owns the decision here.
289
+ * @returns {MoveEdge[]}
290
+ */
291
+ pickBestMoves() {
292
+ const moves = this.moves;
293
+
294
+ if (moves === null) {
295
+ return [];
296
+ }
297
+
298
+ const numMoves = moves.length;
299
+
300
+ if (numMoves === 0) {
301
+ return [];
302
+ }
303
+
304
+ // For a decision node, score by the active player's component.
305
+ // For a terminal node (no active player), fall back to player 0 — caller
306
+ // shouldn't normally ask for best moves on a terminal but we don't crash.
307
+ const player = this.activePlayer >= 0 ? this.activePlayer : 0;
308
+
309
+ const firstMove = moves[0];
310
+
311
+ let result = [firstMove];
312
+ let bestScore = pickBestScore(firstMove, player);
313
+
314
+ for (let i = 1; i < numMoves; i++) {
315
+
316
+ const move = moves[i];
317
+
318
+ const score = pickBestScore(move, player);
319
+
320
+ if (score > bestScore) {
321
+ bestScore = score;
322
+ result = [move];
323
+ } else if (score === bestScore) {
324
+ result.push(move);
325
+ }
326
+ }
327
+
328
+ return result;
329
+ }
330
+
331
+ /**
332
+ *
333
+ * @param {function(StateNode)} visitor
334
+ */
335
+ traverse(visitor) {
336
+ const stackOffset = stack_pointer;
337
+
338
+ stack[stack_pointer++] = this;
339
+
340
+ let n;
341
+
342
+ while (stack_pointer-- > stackOffset) {
343
+
344
+ n = stack[stack_pointer];
345
+
346
+ visitor(n);
347
+
348
+ if (n.isExpanded()) {
349
+
350
+ const moves = n.moves;
351
+ const numMoves = moves.length;
352
+
353
+ for (let i = 0; i < numMoves; i++) {
354
+ const moveEdge = moves[i];
355
+
356
+ if (moveEdge.isTargetMaterialized()) {
357
+ stack[stack_pointer++] = moveEdge.target;
358
+ }
359
+ }
360
+ }
361
+ }
362
+
363
+ }
364
+ }