@woosh/meep-engine 2.138.15 → 2.138.17

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 (61) hide show
  1. package/editor/Editor.d.ts.map +1 -1
  2. package/editor/SelectionVisualizer.d.ts.map +1 -1
  3. package/editor/actions/concrete/ComponentAddAction.d.ts.map +1 -1
  4. package/editor/actions/concrete/EntityCreateAction.d.ts.map +1 -1
  5. package/editor/actions/concrete/SelectionAddAction.d.ts.map +1 -1
  6. package/editor/enableEditor.d.ts.map +1 -1
  7. package/package.json +1 -1
  8. package/src/engine/ecs/grid/HeightMap2AOMap.d.ts +25 -0
  9. package/src/engine/ecs/grid/HeightMap2AOMap.d.ts.map +1 -0
  10. package/src/engine/ecs/grid/HeightMap2AOMap.js +95 -0
  11. package/src/engine/ecs/terrain/ecs/BuildLightTexture.d.ts +15 -7
  12. package/src/engine/ecs/terrain/ecs/BuildLightTexture.d.ts.map +1 -1
  13. package/src/engine/ecs/terrain/ecs/BuildLightTexture.js +44 -99
  14. package/src/engine/ecs/terrain/ecs/Terrain.d.ts.map +1 -1
  15. package/src/engine/ecs/terrain/ecs/Terrain.js +36 -0
  16. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.d.ts +1 -1
  17. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.d.ts.map +1 -1
  18. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.js +3 -1
  19. package/src/engine/ecs/terrain/tiles/TerrainTileManager.d.ts +12 -1
  20. package/src/engine/ecs/terrain/tiles/TerrainTileManager.d.ts.map +1 -1
  21. package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +21 -0
  22. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.d.ts.map +1 -1
  23. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.js +23 -12
  24. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.d.ts.map +1 -1
  25. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.js +1 -7
  26. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.d.ts.map +1 -1
  27. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.js +1 -6
  28. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.d.ts.map +1 -1
  29. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.js +1 -6
  30. package/src/engine/graphics/material/TerrainDepthMaterial.d.ts +36 -0
  31. package/src/engine/graphics/material/TerrainDepthMaterial.d.ts.map +1 -0
  32. package/src/engine/graphics/material/TerrainDepthMaterial.js +65 -0
  33. package/src/engine/graphics/shaders/AmbientOcclusionShader.d.ts +69 -12
  34. package/src/engine/graphics/shaders/AmbientOcclusionShader.d.ts.map +1 -1
  35. package/src/engine/graphics/shaders/AmbientOcclusionShader.js +371 -128
  36. package/src/engine/graphics/shaders/TerrainShader.js +2 -2
  37. package/src/engine/graphics/util/build_max_height_pyramid.d.ts +25 -0
  38. package/src/engine/graphics/util/build_max_height_pyramid.d.ts.map +1 -0
  39. package/src/engine/graphics/util/build_max_height_pyramid.js +100 -0
  40. package/src/engine/intelligence/mcts/MonteCarlo.d.ts +35 -4
  41. package/src/engine/intelligence/mcts/MonteCarlo.d.ts.map +1 -1
  42. package/src/engine/intelligence/mcts/MonteCarlo.js +101 -31
  43. package/src/engine/intelligence/mcts/StateNode.d.ts +47 -24
  44. package/src/engine/intelligence/mcts/StateNode.d.ts.map +1 -1
  45. package/src/engine/intelligence/mcts/StateNode.js +364 -316
  46. package/editor/ecs/component/FieldDescriptor.d.ts +0 -27
  47. package/editor/ecs/component/FieldDescriptor.d.ts.map +0 -1
  48. package/editor/ecs/component/FieldValueAdapter.d.ts +0 -7
  49. package/editor/ecs/component/FieldValueAdapter.d.ts.map +0 -1
  50. package/editor/ecs/component/createFieldEditor.d.ts +0 -9
  51. package/editor/ecs/component/createFieldEditor.d.ts.map +0 -1
  52. package/editor/ecs/component/createObjectEditor.d.ts +0 -14
  53. package/editor/ecs/component/createObjectEditor.d.ts.map +0 -1
  54. package/editor/ecs/component/findNearestRegisteredType.d.ts +0 -8
  55. package/editor/ecs/component/findNearestRegisteredType.d.ts.map +0 -1
  56. package/src/engine/ecs/grid/HeightMap2NormalMap.d.ts +0 -10
  57. package/src/engine/ecs/grid/HeightMap2NormalMap.d.ts.map +0 -1
  58. package/src/engine/ecs/grid/HeightMap2NormalMap.js +0 -72
  59. package/src/engine/ecs/grid/NormalMap2AOMap.d.ts +0 -15
  60. package/src/engine/ecs/grid/NormalMap2AOMap.d.ts.map +0 -1
  61. package/src/engine/ecs/grid/NormalMap2AOMap.js +0 -82
@@ -14,6 +14,12 @@ export class MonteCarloTreeSearch<S> {
14
14
  * @type {StateNode|null}
15
15
  */
16
16
  root: StateNode<any, any> | null;
17
+ /**
18
+ * Number of distinct players whose payoffs we track. Set in {@link initialize}.
19
+ * Sizes the per-node `heuristicValue` and `totalScore` buffers.
20
+ * @type {number}
21
+ */
22
+ numPlayers: number;
17
23
  /**
18
24
  *
19
25
  * @type {function(state:S, source:StateNode):MoveEdge[]}
@@ -24,6 +30,30 @@ export class MonteCarloTreeSearch<S> {
24
30
  * @type {function(state:S):StateType}
25
31
  */
26
32
  computeTerminalFlag: (arg0: state) => S;
33
+ /**
34
+ * Returns the player ID (0-based) who chooses the next move from a given state.
35
+ * Called when a non-terminal node is expanded. Players don't need to alternate
36
+ * or follow any fixed pattern — the framework just asks the game.
37
+ * @type {function(state:S):number}
38
+ */
39
+ computeActivePlayer: (arg0: state) => S;
40
+ /**
41
+ * Returns the per-player payoff vector for a terminal state.
42
+ * Indexed by player ID. The game decides the zero-sum/cooperative shape.
43
+ * @type {function(state:S):Float64Array}
44
+ */
45
+ computeOutcome: (arg0: state) => S;
46
+ /**
47
+ *
48
+ * @type {function(S):S}
49
+ */
50
+ cloneState: (arg0: S) => S;
51
+ /**
52
+ * Heuristic estimate of a non-terminal state's per-player value.
53
+ * Optional — if `null`, new nodes start with zero-valued heuristic vectors.
54
+ * @type {null|function(node:StateNode, state:S):Float64Array}
55
+ */
56
+ heuristic: null | ((arg0: node) => StateNode<any, any>);
27
57
  /**
28
58
  * Depth to which plays will be explored
29
59
  * @type {number}
@@ -36,14 +66,15 @@ export class MonteCarloTreeSearch<S> {
36
66
  random: Function;
37
67
  /**
38
68
  * @param {S} rootState
69
+ * @param {number} numPlayers Total number of players whose payoffs are tracked. Use 1 for solitaire / planning.
39
70
  * @param {function(state:S, source:StateNode):MoveEdge[]} computeValidMoves
40
71
  * @param {function(state:S):StateType} computeTerminalFlag
72
+ * @param {function(state:S):number} computeActivePlayer
73
+ * @param {function(state:S):Float64Array} computeOutcome called on terminal states; must return a vector of length `numPlayers`
41
74
  * @param {function(S):S} cloneState
42
- * @param {function(StateNode, S):number} heuristic Estimation function for evaluation of intermediate stated, guides exploration
75
+ * @param {null|function(node:StateNode, state:S):Float64Array} [heuristic] optional per-player estimator for intermediate states
43
76
  */
44
- initialize({ rootState, computeValidMoves, computeTerminalFlag, cloneState, heuristic }: S): void;
45
- cloneState: any;
46
- heuristic: any;
77
+ initialize({ rootState, numPlayers, computeValidMoves, computeTerminalFlag, computeActivePlayer, computeOutcome, cloneState, heuristic }: S): void;
47
78
  /**
48
79
  *
49
80
  * @param {StateNode} node
@@ -1 +1 @@
1
- {"version":3,"file":"MonteCarlo.d.ts","sourceRoot":"","sources":["../../../../../src/engine/intelligence/mcts/MonteCarlo.js"],"names":[],"mappings":"AAsCA;;;;GAIG;AACH;IAEI;;;OAGG;IACH,WAFU,CAAC,CAEM;IAEjB;;;OAGG;IACH,MAFU,sBAAU,IAAI,CAEZ;IAEZ;;;OAGG;IACH,oCAFyB,CAAC,CAED;IAEzB;;;OAGG;IACH,sCAFyB,CAAC,CAEC;IAE3B;;;OAGG;IACH,qBAFU,MAAM,CAEW;IAE3B;;;OAGG;IACH,iBAAyB;IAEzB;;;;;;OAMG;IACH,yFANW,CAAC,QA2BX;IANG,gBAA4B;IAC5B,eAA0B;IAO9B;;;;;OAKG;IACH,+CAHW,CAAC,uBAsEX;IAED;;;OAGG;IACH,WAFa,CAAC,CA+Cb;CACJ;0BAvOoC,gBAAgB"}
1
+ {"version":3,"file":"MonteCarlo.d.ts","sourceRoot":"","sources":["../../../../../src/engine/intelligence/mcts/MonteCarlo.js"],"names":[],"mappings":"AA0CA;;;;GAIG;AACH;IAEI;;;OAGG;IACH,WAFU,CAAC,CAEM;IAEjB;;;OAGG;IACH,MAFU,sBAAU,IAAI,CAEZ;IAEZ;;;;OAIG;IACH,YAFU,MAAM,CAED;IAEf;;;OAGG;IACH,oCAFyB,CAAC,CAED;IAEzB;;;OAGG;IACH,sCAFyB,CAAC,CAEC;IAE3B;;;;;OAKG;IACH,sCAFyB,CAAC,CAEC;IAE3B;;;;OAIG;IACH,iCAFyB,CAAC,CAEJ;IAEtB;;;OAGG;IACH,mBAFmB,CAAC,KAAE,CAAC,CAEL;IAElB;;;;OAIG;IACH,WAFU,IAAI,wCAAwB,CAErB;IAEjB;;;OAGG;IACH,qBAFU,MAAM,CAEW;IAE3B;;;OAGG;IACH,iBAAyB;IAEzB;;;;;;;;;OASG;IACH,0IATW,CAAC,QA0CX;IAED;;;;;OAKG;IACH,+CAHW,CAAC,uBAsEX;IAED;;;OAGG;IACH,WAFa,CAAC,CAgDb;CACJ;0BA/RoC,gBAAgB"}
@@ -1,5 +1,4 @@
1
1
  import { assert } from "../../../core/assert.js";
2
- import { returnZero } from "../../../core/function/returnZero.js";
3
2
  import { mix } from "../../../core/math/mix.js";
4
3
  import { seededRandom } from "../../../core/math/random/seededRandom.js";
5
4
  import { MoveEdge } from "./MoveEdge.js";
@@ -13,6 +12,9 @@ import { StateNode, StateType } from "./StateNode.js";
13
12
  const C_ks = 1 / Math.sqrt(2);
14
13
 
15
14
  /**
15
+ * UCB1-style score for the parent choosing among its children. The exploitation
16
+ * term is read from whichever component the parent's active player cares about —
17
+ * each decision-maker maximizes their own outcome (maxN selection).
16
18
  *
17
19
  * @param {StateNode} parent
18
20
  * @param {StateNode} child
@@ -26,8 +28,10 @@ function computeNodeSelectionScore(parent, child) {
26
28
  return 0;
27
29
  }
28
30
 
31
+ const player = parent.activePlayer;
32
+
29
33
  // Exploitation heuristic
30
- const Q = mix((child.wins + 1) / playouts, child.heuristicValue, 0.65);
34
+ const Q = mix(child.totalScore[player] / playouts, child.heuristicValue[player], 0.65);
31
35
 
32
36
  // Based on UCB1
33
37
  // exploration heuristic
@@ -55,6 +59,13 @@ export class MonteCarloTreeSearch {
55
59
  */
56
60
  root = null;
57
61
 
62
+ /**
63
+ * Number of distinct players whose payoffs we track. Set in {@link initialize}.
64
+ * Sizes the per-node `heuristicValue` and `totalScore` buffers.
65
+ * @type {number}
66
+ */
67
+ numPlayers = 0;
68
+
58
69
  /**
59
70
  *
60
71
  * @type {function(state:S, source:StateNode):MoveEdge[]}
@@ -67,6 +78,34 @@ export class MonteCarloTreeSearch {
67
78
  */
68
79
  computeTerminalFlag = null;
69
80
 
81
+ /**
82
+ * Returns the player ID (0-based) who chooses the next move from a given state.
83
+ * Called when a non-terminal node is expanded. Players don't need to alternate
84
+ * or follow any fixed pattern — the framework just asks the game.
85
+ * @type {function(state:S):number}
86
+ */
87
+ computeActivePlayer = null;
88
+
89
+ /**
90
+ * Returns the per-player payoff vector for a terminal state.
91
+ * Indexed by player ID. The game decides the zero-sum/cooperative shape.
92
+ * @type {function(state:S):Float64Array}
93
+ */
94
+ computeOutcome = null;
95
+
96
+ /**
97
+ *
98
+ * @type {function(S):S}
99
+ */
100
+ cloneState = null;
101
+
102
+ /**
103
+ * Heuristic estimate of a non-terminal state's per-player value.
104
+ * Optional — if `null`, new nodes start with zero-valued heuristic vectors.
105
+ * @type {null|function(node:StateNode, state:S):Float64Array}
106
+ */
107
+ heuristic = null;
108
+
70
109
  /**
71
110
  * Depth to which plays will be explored
72
111
  * @type {number}
@@ -81,32 +120,47 @@ export class MonteCarloTreeSearch {
81
120
 
82
121
  /**
83
122
  * @param {S} rootState
123
+ * @param {number} numPlayers Total number of players whose payoffs are tracked. Use 1 for solitaire / planning.
84
124
  * @param {function(state:S, source:StateNode):MoveEdge[]} computeValidMoves
85
125
  * @param {function(state:S):StateType} computeTerminalFlag
126
+ * @param {function(state:S):number} computeActivePlayer
127
+ * @param {function(state:S):Float64Array} computeOutcome called on terminal states; must return a vector of length `numPlayers`
86
128
  * @param {function(S):S} cloneState
87
- * @param {function(StateNode, S):number} heuristic Estimation function for evaluation of intermediate stated, guides exploration
129
+ * @param {null|function(node:StateNode, state:S):Float64Array} [heuristic] optional per-player estimator for intermediate states
88
130
  */
89
131
  initialize(
90
132
  {
91
133
  rootState,
134
+ numPlayers,
92
135
  computeValidMoves,
93
136
  computeTerminalFlag,
137
+ computeActivePlayer,
138
+ computeOutcome,
94
139
  cloneState,
95
- heuristic = returnZero
140
+ heuristic = null
96
141
  }
97
142
  ) {
143
+ assert.isInteger(numPlayers, `numPlayers`);
144
+ assert.greaterThanOrEqual(numPlayers, 1, `numPlayers`);
145
+
98
146
  assert.isFunction(computeValidMoves, `computeValidMoves`);
99
147
  assert.isFunction(computeTerminalFlag, `computeTerminalFlag`);
148
+ assert.isFunction(computeActivePlayer, `computeActivePlayer`);
149
+ assert.isFunction(computeOutcome, `computeOutcome`);
100
150
  assert.isFunction(cloneState, `cloneState`);
101
151
 
152
+ this.numPlayers = numPlayers;
102
153
  this.computeValidMoves = computeValidMoves;
103
154
  this.computeTerminalFlag = computeTerminalFlag;
155
+ this.computeActivePlayer = computeActivePlayer;
156
+ this.computeOutcome = computeOutcome;
104
157
  this.cloneState = cloneState;
105
158
  this.heuristic = heuristic;
106
159
 
107
160
  this.rootState = rootState;
108
161
 
109
162
  this.root = new StateNode();
163
+ this.root.allocate(numPlayers);
110
164
  }
111
165
 
112
166
  /**
@@ -170,7 +224,7 @@ export class MonteCarloTreeSearch {
170
224
 
171
225
  if (!bestMove.isTargetMaterialized()) {
172
226
  //materialize the target state
173
- materializedEdgeTarget(state, node, bestMove, this.computeTerminalFlag, this.heuristic);
227
+ materializeEdgeTarget(state, node, bestMove, this);
174
228
 
175
229
  } else {
176
230
  //just follow the edge
@@ -190,8 +244,8 @@ export class MonteCarloTreeSearch {
190
244
  */
191
245
  playout() {
192
246
  const computeValidMoves = this.computeValidMoves;
193
-
194
- const computeTerminalFlag = this.computeTerminalFlag;
247
+ const computeActivePlayer = this.computeActivePlayer;
248
+ const computeOutcome = this.computeOutcome;
195
249
 
196
250
  const state = this.cloneState(this.rootState);
197
251
 
@@ -202,35 +256,36 @@ export class MonteCarloTreeSearch {
202
256
  while (!node.isTerminal() && node.depth < this.maxExplorationDepth) {
203
257
 
204
258
  if (!node.isExpanded()) {
205
- node.expand(state, computeValidMoves, computeTerminalFlag);
259
+ node.expand(state, computeValidMoves, computeActivePlayer, computeOutcome);
206
260
  }
207
261
 
208
262
  const child = this.selectRandom(node, state);
209
263
 
210
264
  if (child === node) {
211
265
  // prevent infinite recursion
212
- // this should not happen?
266
+ // can happen e.g. when expand produced no moves (NoMoves terminal)
213
267
  break;
214
268
  }
215
269
 
216
270
  node = child;
217
271
  }
218
272
 
273
+ let outcome;
274
+
219
275
  if (!node.isTerminal() && node.depth >= this.maxExplorationDepth) {
220
- //cap the state by depth, propagate heuristic score
276
+ // cap the state by depth, propagate heuristic score as payoff stand-in
221
277
  node.type = StateType.DepthCapped;
278
+ outcome = node.heuristicValue;
279
+ } else if (node.outcome !== null) {
280
+ // terminal node with cached payoff
281
+ outcome = node.outcome;
282
+ } else {
283
+ // Defensive: shouldn't reach here under normal control flow, but if
284
+ // a node became terminal without a cached outcome, fall back to heuristic.
285
+ outcome = node.heuristicValue;
222
286
  }
223
287
 
224
- // record play-through
225
- const terminalFlag = node.type;
226
-
227
- if (terminalFlag === StateType.Win) {
228
- node.addPlayouts(1, 1, 0);
229
- } else if (terminalFlag === StateType.Loss) {
230
- node.addPlayouts(1, 0, 1);
231
- } else if (terminalFlag === StateType.Tie || terminalFlag === StateType.DepthCapped) {
232
- node.addPlayouts(1, 0, 0);
233
- }
288
+ node.backpropagate(outcome);
234
289
 
235
290
  return state;
236
291
  }
@@ -241,18 +296,18 @@ export class MonteCarloTreeSearch {
241
296
  * @param {S} state
242
297
  * @param {StateNode} source
243
298
  * @param {MoveEdge} edge
244
- * @param {function(S):StateType} computeTerminalFlag
245
- * @param {function(StateNode, S)} heuristic
299
+ * @param {MonteCarloTreeSearch} search
246
300
  */
247
- function materializedEdgeTarget(state, source, edge, computeTerminalFlag, heuristic) {
301
+ function materializeEdgeTarget(state, source, edge, search) {
248
302
 
249
303
  const child = new StateNode();
304
+ child.allocate(search.numPlayers);
250
305
  child.parent = source;
251
306
  child.depth = source.depth + 1;
252
307
 
253
308
  const computedState = edge.move(state);
254
309
 
255
- const terminalFlag = computeTerminalFlag(computedState);
310
+ const terminalFlag = search.computeTerminalFlag(computedState);
256
311
 
257
312
  assert.enum(terminalFlag, StateType, 'terminalFlag');
258
313
 
@@ -260,16 +315,31 @@ function materializedEdgeTarget(state, source, edge, computeTerminalFlag, heuris
260
315
 
261
316
  edge.target = child;
262
317
 
263
- const childHeuristicScore = heuristic(child, computedState);
264
-
265
- assert.notNaN(childHeuristicScore, 'childHeuristicScore');
318
+ if (terminalFlag === StateType.Undecided) {
319
+ // active player will be set when this node is expanded (we don't know
320
+ // yet whether it has any legal moves)
321
+ if (search.heuristic !== null) {
322
+ const h = search.heuristic(child, computedState);
266
323
 
267
- child.heuristicValue = childHeuristicScore;
324
+ assert.notNull(h, 'heuristic returned null');
268
325
 
326
+ child.heuristicValue.set(h);
327
+ }
328
+ } else {
329
+ // terminal — game decides per-player payoff, cache and mirror into heuristicValue.
330
+ // Copy into the node's own buffer so the user is free to reuse one across calls;
331
+ // outcome and heuristicValue share storage within the node (safe since bubble-up
332
+ // skips terminals — see StateNode.aggregateHeuristicScore).
333
+ const out = search.computeOutcome(computedState);
334
+
335
+ child.heuristicValue.set(out);
336
+ child.outcome = child.heuristicValue;
337
+ }
269
338
 
270
- // bubble the heuristic score up the tree
271
- // child.bubbleUpHeuristicScore(); // heuristic value changes sign depending on the team making the move, so aggregation becomes tricky
339
+ // Propagate the new node's value up the tree via maxN backup. This refines
340
+ // ancestors' heuristicValue with information from the freshly-materialized
341
+ // leaf — useful guidance for subsequent UCB selections at those ancestors.
342
+ child.bubbleUpHeuristicScore();
272
343
 
273
344
  return computedState;
274
345
  }
275
-
@@ -1,9 +1,11 @@
1
+ /**
2
+ * Coarse classification of a node's terminal status, independent of payoff.
3
+ * The actual per-player payoff lives in {@link StateNodeoutcome }.
4
+ */
1
5
  export type StateType = number;
2
6
  export namespace StateType {
3
7
  let Undecided: number;
4
- let Win: number;
5
- let Loss: number;
6
- let Tie: number;
8
+ let Terminal: number;
7
9
  let DepthCapped: number;
8
10
  let NoMoves: number;
9
11
  }
@@ -19,27 +21,37 @@ export class StateNode<State, Action> {
19
21
  */
20
22
  depth: number;
21
23
  /**
22
- *
24
+ * Total number of explored playouts through this node.
23
25
  * @type {number}
24
26
  */
25
- wins: number;
27
+ playouts: number;
26
28
  /**
27
- * Number of leses in the subtree of this state
28
- * @type {number}
29
+ * Per-player heuristic estimate of the value of this state.
30
+ * For terminal nodes this mirrors {@link StateNode#outcome}.
31
+ * For internal nodes this is refined by maxN backup as children materialize.
32
+ * Index = player ID.
33
+ * @type {Float64Array | null}
29
34
  */
30
- losses: number;
35
+ heuristicValue: Float64Array | null;
31
36
  /**
32
- * total number of explored playouts
33
- * @type {number}
37
+ * Per-player cumulative payoff aggregated by backpropagation.
38
+ * Average value for player `p` is `totalScore[p] / playouts` once `playouts > 0`.
39
+ * @type {Float64Array | null}
34
40
  */
35
- playouts: number;
41
+ totalScore: Float64Array | null;
36
42
  /**
37
- *
43
+ * Per-player payoff at this terminal node, cached at materialization.
44
+ * `null` for non-terminal nodes (uses {@link StateNode#heuristicValue} as a stand-in).
45
+ * @type {Float64Array | null}
46
+ */
47
+ outcome: Float64Array | null;
48
+ /**
49
+ * Player ID of whoever chooses the next move from this state.
50
+ * `-1` for terminal nodes (no decision to make).
38
51
  * @type {number}
39
52
  */
40
- heuristicValue: number;
53
+ activePlayer: number;
41
54
  /**
42
- * parent node, previous state
43
55
  * @type {null|StateNode}
44
56
  */
45
57
  parent: null | StateNode<any, any>;
@@ -53,27 +65,37 @@ export class StateNode<State, Action> {
53
65
  * @type {StateType}
54
66
  */
55
67
  type: StateType;
68
+ /**
69
+ * Allocate the per-player buffers. Must be called before any backprop or selection.
70
+ * @param {number} numPlayers
71
+ */
72
+ allocate(numPlayers: number): void;
56
73
  bubbleUpHeuristicScore(): void;
57
74
  /**
58
- * Aggregate heuristic score from children
75
+ * maxN backup: the active player picks the child that maximizes their own
76
+ * component; the chosen child's entire heuristic vector is copied here.
77
+ *
78
+ * This generalizes minimax across N players and asymmetric turn orders: the
79
+ * non-active components ride along, representing "what would happen to player Y
80
+ * if X plays the way X wants from this state".
59
81
  */
60
82
  aggregateHeuristicScore(): void;
61
83
  /**
62
84
  * @param state
63
85
  * @param {function(State, source:StateNode):MoveEdge[]} computeValidMoves
64
- * @param computeTerminalFlag
86
+ * @param {function(State):number} computeActivePlayer
87
+ * @param {function(State):Float64Array} computeOutcome called when expansion produces no moves
65
88
  * @returns {number} number of children
66
89
  */
67
- expand(state: any, computeValidMoves: any, computeTerminalFlag: any): number;
90
+ expand(state: any, computeValidMoves: any, computeActivePlayer: (arg0: State) => number, computeOutcome: (arg0: State) => Float64Array): number;
68
91
  /**
69
- *
70
- * @param {number} playouts
71
- * @param {number} wins
72
- * @param {number} losses
92
+ * Walk up from this node to the root, adding the per-player outcome to each
93
+ * ancestor's cumulative score and incrementing their visit count.
94
+ * @param {Float64Array} outcomeVector indexed by player ID
73
95
  */
74
- addPlayouts(playouts: number, wins: number, losses: number): void;
96
+ backpropagate(outcomeVector: Float64Array): void;
75
97
  /**
76
- * Whenever this is a terminal state or not (win/loss)
98
+ * Whenever this is a terminal state or not (win/loss/tie/no-moves/depth-cap)
77
99
  * @returns {boolean}
78
100
  */
79
101
  isTerminal(): boolean;
@@ -83,7 +105,8 @@ export class StateNode<State, Action> {
83
105
  */
84
106
  isExpanded(): boolean;
85
107
  /**
86
- *
108
+ * Pick the best moves from this node's perspective — i.e. for whichever
109
+ * player owns the decision here.
87
110
  * @returns {MoveEdge[]}
88
111
  */
89
112
  pickBestMoves(): MoveEdge<any>[];
@@ -1 +1 @@
1
- {"version":3,"file":"StateNode.d.ts","sourceRoot":"","sources":["../../../../../src/engine/intelligence/mcts/StateNode.js"],"names":[],"mappings":"wBAKU,MAAM;;;;;;;;;AAyDhB;;;;GAIG;AACH;IAEI;;;OAGG;IACH,OAFU,MAAM,CAEN;IAEV;;;OAGG;IACH,MAFU,MAAM,CAEP;IAET;;;OAGG;IACH,QAFU,MAAM,CAEL;IAGX;;;OAGG;IACH,UAFU,MAAM,CAEH;IAEb;;;OAGG;IACH,gBAFU,MAAM,CAEG;IAEnB;;;OAGG;IACH,QAFU,IAAI,sBAAU,CAEV;IAEd;;;OAGG;IACH,OAFU,IAAI,GAAC,eAAU,CAEZ;IAEb;;;OAGG;IACH,MAFU,SAAS,CAEQ;IAG3B,+BASC;IAED;;OAEG;IACH,gCAuCC;IAED;;;;;OAKG;IACH,sEAFa,MAAM,CAyBlB;IAGD;;;;;OAKG;IACH,sBAJW,MAAM,QACN,MAAM,UACN,MAAM,QAchB;IAGD;;;OAGG;IACH,cAFa,OAAO,CAInB;IAED;;;OAGG;IACH,cAFa,OAAO,CAInB;IAED;;;OAGG;IACH,iBAFa,eAAU,CAmCtB;IAED;;;OAGG;IACH,4DA4BC;CACJ;yBA1TwB,eAAe"}
1
+ {"version":3,"file":"StateNode.d.ts","sourceRoot":"","sources":["../../../../../src/engine/intelligence/mcts/StateNode.js"],"names":[],"mappings":";;;;wBAMU,MAAM;;;;;;;AA0ChB;;;;GAIG;AACH;IAEI;;;OAGG;IACH,OAFU,MAAM,CAEN;IAEV;;;OAGG;IACH,UAFU,MAAM,CAEH;IAEb;;;;;;OAMG;IACH,gBAFU,YAAY,GAAG,IAAI,CAEP;IAEtB;;;;OAIG;IACH,YAFU,YAAY,GAAG,IAAI,CAEX;IAElB;;;;OAIG;IACH,SAFU,YAAY,GAAG,IAAI,CAEd;IAEf;;;;OAIG;IACH,cAFU,MAAM,CAEE;IAElB;;OAEG;IACH,QAFU,IAAI,sBAAU,CAEV;IAEd;;;OAGG;IACH,OAFU,IAAI,GAAC,eAAU,CAEZ;IAEb;;;OAGG;IACH,MAFU,SAAS,CAEQ;IAE3B;;;OAGG;IACH,qBAFW,MAAM,QAOhB;IAED,+BAQC;IAED;;;;;;;OAOG;IACH,gCA0CC;IAED;;;;;;OAMG;IACH,uEAJoB,KAAK,KAAE,MAAM,yBACb,KAAK,KAAE,YAAY,GAC1B,MAAM,CA+ClB;IAGD;;;;OAIG;IACH,6BAFW,YAAY,QAqBtB;IAGD;;;OAGG;IACH,cAFa,OAAO,CAInB;IAED;;;OAGG;IACH,cAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,iBAFa,eAAU,CAwCtB;IAED;;;OAGG;IACH,4DA4BC;CACJ;yBA1WwB,eAAe"}