victris-arena-sim 0.92.0 → 0.93.0

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.
package/README.md CHANGED
@@ -18,7 +18,7 @@ It has no dependencies and uses no Node APIs, so it runs in Node 18+ and in brow
18
18
  `victris-arena-sim/script` is the same code as a plain script that sets a global `ArenaSim`, for
19
19
  engines that don't load modules.
20
20
 
21
- This is release 0.92.0. Each release of the ladder plays on the simulator of the same
21
+ This is release 0.93.0. Each release of the ladder plays on the simulator of the same
22
22
  version, so keep it current: a policy trained on another release may see other rules.
23
23
 
24
24
  - [Simulator guide](https://victrisarena.com/guide/simulator): playing games, your own bots and encoders, replays
package/arena-sim.js CHANGED
@@ -8185,7 +8185,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
8185
8185
  /** Bumped whenever a bot-facing message changes shape. 0.2 introduced the `turn` message; 0.3 made
8186
8186
  * `queue` just a version and removed availability and challenges; 0.4 added `shout`;
8187
8187
  * 0.5 added the ladder's `server_draining` notice; 0.6 added optional ladder IDs; 0.7 added `quota_exceeded`'s quota fields. */
8188
- var PROTOCOL_VERSION = "0.7";
8188
+ var PROTOCOL_VERSION = "0.8";
8189
8189
  var Dir = _enum([
8190
8190
  "N",
8191
8191
  "NE",
@@ -8277,7 +8277,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
8277
8277
  });
8278
8278
  object({
8279
8279
  type: literal("hello"),
8280
- protocol_version: literal("0.7"),
8280
+ protocol_version: literal("0.8"),
8281
8281
  match_id: string(),
8282
8282
  bot_id: number().int(),
8283
8283
  opponent: object({
@@ -8294,6 +8294,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
8294
8294
  kind: string()
8295
8295
  })),
8296
8296
  seed_public: number().int(),
8297
+ /**
8298
+ * the engine version this match runs (also GET /api versions.engine). It can change while
8299
+ * rules.version stays the same, so a bot that copies the engine checks this one
8300
+ */
8301
+ engine_version: string(),
8297
8302
  deadlines: object({
8298
8303
  startup_ms: number(),
8299
8304
  tick_ms: number(),
@@ -10221,7 +10226,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
10221
10226
  * that doesn't match). The downloadable simulator and the Python package carry it, so a player
10222
10227
  * can tell whether their copy is the one the ladder runs (GET /api versions.release).
10223
10228
  */
10224
- var RELEASE = "0.92.0";
10229
+ var RELEASE = "0.93.0";
10225
10230
  // packages/sim/src/match.ts
10226
10231
  /** No usable reply before the deadline. */
10227
10232
  function timeoutOutcome() {
@@ -10337,7 +10342,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
10337
10342
  const { limits } = this.opts;
10338
10343
  return {
10339
10344
  type: "hello",
10340
- protocol_version: "0.7",
10345
+ protocol_version: "0.8",
10341
10346
  match_id: this.opts.matchId,
10342
10347
  bot_id: fighterId,
10343
10348
  opponent: {
@@ -10349,6 +10354,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
10349
10354
  map_name: this.opts.map.name,
10350
10355
  pickups: pickupPads(this.opts.map),
10351
10356
  seed_public: this.opts.seed,
10357
+ engine_version: ENGINE_VERSION,
10352
10358
  deadlines: {
10353
10359
  startup_ms: limits.startup_ms,
10354
10360
  tick_ms: limits.tick_ms,
@@ -11206,6 +11212,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
11206
11212
  this.parsed.clear();
11207
11213
  if (!this.over) this.ask();
11208
11214
  }
11215
+ /**
11216
+ * A copy of the whole match state as it stands, fog and all: what `forward` steps. For
11217
+ * training and testing a search with the truth; on the ladder a bot only has its observations.
11218
+ */
11219
+ state() {
11220
+ return cloneState(this.core.state);
11221
+ }
11209
11222
  /** The finished match: result, replay and stats. */
11210
11223
  summary() {
11211
11224
  return this.core.summary();
@@ -11466,6 +11479,168 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
11466
11479
  mismatches
11467
11480
  };
11468
11481
  }
11482
+ // packages/sim/src/forward.ts
11483
+ /** The forward model's contract version. It changes when a function's arguments or results do. */
11484
+ var FORWARD_API_VERSION = 1;
11485
+ /** The hello's map as the engine's map: the shipped map of that name, or `map` for one of your own. */
11486
+ function helloMap(hello, map) {
11487
+ const m = map ?? SHIPPED_MAPS.find((x) => x.name === hello.map_name);
11488
+ if (!m) throw new Error(`forward: map '${hello.map_name}' isn't one this simulator ships; pass the map object as well`);
11489
+ if (m.tiles.length !== hello.map.length || m.tiles.some((row, y) => row !== hello.map[y])) throw new Error(`forward: the hello's map differs from this simulator's '${m.name}' (a newer release?); pass the map object as well`);
11490
+ return m;
11491
+ }
11492
+ function helloRules(hello) {
11493
+ const engine = hello.engine_version;
11494
+ if (engine !== void 0 && engine !== "0.24.0") throw new Error(`forward: this match runs engine ${engine}, but this simulator has engine ${ENGINE_VERSION}; its steps would not be the ladder's. Install the ladder's simulator (GET /api → simulator)`);
11495
+ return loadRules(hello.rules);
11496
+ }
11497
+ /**
11498
+ * The match's state on its first tick, exactly as the ladder starts it. The hello names the map
11499
+ * and carries the seed, which decides the spawns, so nothing about the start is hidden.
11500
+ */
11501
+ function start(hello, map) {
11502
+ return createMatch(helloRules(hello), helloMap(hello, map), hello.seed_public);
11503
+ }
11504
+ function projectileState(rules, p) {
11505
+ const d = [p.target[0] - p.origin[0], p.target[1] - p.origin[1]];
11506
+ const axis = Math.abs(d[0]) >= Math.abs(d[1]) ? 0 : 1;
11507
+ const traveled = Math.abs(p.exact_pos[axis] - p.origin[axis] * SUB);
11508
+ const range = rules.attacks[p.attack]?.range;
11509
+ return {
11510
+ id: p.id,
11511
+ owner: p.owner,
11512
+ attack: p.attack,
11513
+ origin: [p.origin[0], p.origin[1]],
11514
+ target: [p.target[0], p.target[1]],
11515
+ traveled,
11516
+ max_travel: range === void 0 ? UNLIMITED_TRAVEL : range * SUB,
11517
+ pos: [p.pos[0], p.pos[1]],
11518
+ exact_pos: [p.exact_pos[0], p.exact_pos[1]],
11519
+ speed: p.speed,
11520
+ damage: p.damage,
11521
+ bounces_left: p.bounces_left
11522
+ };
11523
+ }
11524
+ function areaState(rules, tick, a) {
11525
+ const explodes = tick + a.ticks_left - 1;
11526
+ const atk = rules.attacks[a.attack];
11527
+ const fuse = atk?.kind === "area" ? atk.fuse : 0;
11528
+ return {
11529
+ id: a.id,
11530
+ owner: a.owner,
11531
+ attack: a.attack,
11532
+ pos: [a.pos[0], a.pos[1]],
11533
+ origin: [a.pos[0], a.pos[1]],
11534
+ launched_tick: explodes - fuse,
11535
+ explodes_tick: explodes,
11536
+ radius: a.radius,
11537
+ damage: a.damage,
11538
+ slow: a.slow
11539
+ };
11540
+ }
11541
+ var untilTick = (tick, left) => Object.fromEntries(Object.entries(left).map(([k, n]) => [k, tick + n - 1]));
11542
+ /**
11543
+ * A state that agrees with everything `obs` shows, for fighter `hello.bot_id` on this tick. What
11544
+ * it doesn't show comes from `assume`, otherwise from a cautious default: an enemy in sight has
11545
+ * every attack ready (only its dash is shown), a pad out of sight is stocked, nothing is flying out
11546
+ * of sight. An enemy out of sight needs `assume.enemy.pos`: where you think it is, which is the
11547
+ * guess that matters most.
11548
+ */
11549
+ function fromObservation(hello, obs, assume = {}, map) {
11550
+ const rules = helloRules(hello);
11551
+ const state = createMatch(rules, helloMap(hello, map), hello.seed_public);
11552
+ const tick = obs.tick;
11553
+ state.tick = tick;
11554
+ state.zone = {
11555
+ center: [obs.zone.center[0], obs.zone.center[1]],
11556
+ radius: obs.zone.radius
11557
+ };
11558
+ const me = state.fighters.find((f) => f.id === hello.bot_id);
11559
+ const enemy = state.fighters.find((f) => f.id !== hello.bot_id);
11560
+ if (!me || !enemy) throw new Error(`forward: no fighter ${hello.bot_id} in this match`);
11561
+ const s = obs.self;
11562
+ Object.assign(me, {
11563
+ pos: [s.pos[0], s.pos[1]],
11564
+ hp: s.hp,
11565
+ state: s.state,
11566
+ state_end: s.state_ticks_left > 0 ? tick + s.state_ticks_left - 1 : 0,
11567
+ cooldowns: {
11568
+ ...me.cooldowns,
11569
+ ...s.cooldowns
11570
+ },
11571
+ buffs: untilTick(tick, s.buffs),
11572
+ ticks_outside: assume.self?.ticks_outside ?? 0,
11573
+ damage_dealt: assume.self?.damage_dealt ?? 0,
11574
+ alive: s.hp > 0
11575
+ });
11576
+ const seen = obs.enemies.find((e) => e.id === enemy.id);
11577
+ const guess = assume.enemy ?? {};
11578
+ const pos = seen?.pos ?? guess.pos;
11579
+ if (!pos) throw new Error("forward: the enemy is out of sight; pass assume.enemy.pos (where you believe it is)");
11580
+ const stateName = seen?.state ?? guess.state ?? "idle";
11581
+ const ticksLeft = seen?.state_ticks_left ?? guess.state_ticks_left ?? 0;
11582
+ Object.assign(enemy, {
11583
+ pos: [pos[0], pos[1]],
11584
+ hp: seen?.hp ?? guess.hp ?? rules.stats.max_hp,
11585
+ state: stateName,
11586
+ state_end: ticksLeft > 0 ? tick + ticksLeft - 1 : 0,
11587
+ cooldowns: {
11588
+ ...Object.fromEntries(Object.keys(enemy.cooldowns).map((k) => [k, 0])),
11589
+ ...guess.cooldowns,
11590
+ ...seen ? { dash: seen.dash_cooldown } : {}
11591
+ },
11592
+ buffs: untilTick(tick, seen?.buffs ?? guess.buffs ?? {}),
11593
+ ticks_outside: guess.ticks_outside ?? 0,
11594
+ damage_dealt: guess.damage_dealt ?? 0
11595
+ });
11596
+ const shown = new Map(obs.pickups.map((p) => [p.id, p.ready_in]));
11597
+ const stocked = rules.pickups ? rules.pickups.first_spawn : 0;
11598
+ for (const pad of state.pickups) {
11599
+ const readyIn = shown.get(pad.id) ?? assume.pickups?.[pad.id]?.ready_in ?? Math.max(0, stocked - tick);
11600
+ pad.available = readyIn <= 0;
11601
+ pad.respawn_tick = readyIn <= 0 ? pad.respawn_tick : tick + readyIn;
11602
+ }
11603
+ const shots = /* @__PURE__ */ new Map();
11604
+ for (const p of [...assume.projectiles ?? [], ...obs.projectiles]) shots.set(p.id, p);
11605
+ state.projectiles = [...shots.values()].sort((a, b) => a.id - b.id).map((p) => projectileState(rules, p));
11606
+ const areas = /* @__PURE__ */ new Map();
11607
+ for (const a of [...assume.areas ?? [], ...obs.areas]) areas.set(a.id, a);
11608
+ state.areas = [...areas.values()].sort((a, b) => a.id - b.id).map((a) => areaState(rules, tick, a));
11609
+ state.next_projectile_id = Math.max(0, ...state.projectiles.map((p) => p.id), ...state.areas.map((a) => a.id)) + 1;
11610
+ return state;
11611
+ }
11612
+ /** The forward model. Every function takes and returns plain data; only `step` changes its argument. */
11613
+ var forward = {
11614
+ api: 1,
11615
+ start,
11616
+ fromObservation,
11617
+ /** A copy to step without touching the original (the rules and map are shared, never changed). */
11618
+ clone: cloneState,
11619
+ /**
11620
+ * Resolves one tick in place with each fighter's turn and returns its events. Each turn is
11621
+ * validated as the ladder does: an illegal part is dropped (and reported as a `rejected` event),
11622
+ * the rest is played. Throws once the match is over (`state.result` is set).
11623
+ */
11624
+ step(state, turns) {
11625
+ return step(state, turns);
11626
+ },
11627
+ /** What fighter `id` is told on this tick: the observation it would receive, without the server's budget and events. */
11628
+ observe,
11629
+ /** The steps and dashes fighter `id` could start now (the observation's `moves` and `dashes`). */
11630
+ options(state, id) {
11631
+ const f = state.fighters.find((x) => x.id === id);
11632
+ if (!f) throw new Error(`forward: no fighter ${id}`);
11633
+ return moveOptions(state, f);
11634
+ },
11635
+ /** How the engine would take fighter `id`'s turn now: the parts it plays and those it refuses. */
11636
+ validate(state, id, turn) {
11637
+ const f = state.fighters.find((x) => x.id === id);
11638
+ if (!f) throw new Error(`forward: no fighter ${id}`);
11639
+ return validateTurn(state, f, turn);
11640
+ },
11641
+ /** The ladder's hash of the whole state, as recorded with every replay tick. */
11642
+ hash: stateHash
11643
+ };
11469
11644
  // packages/sim/src/trajectories.ts
11470
11645
  /**
11471
11646
  * Each fighter's trajectory in a recorded match, by fighter id. Exact but for what a replay
@@ -12011,6 +12186,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12011
12186
  exports.Batch = Batch;
12012
12187
  exports.ENGINE_VERSION = ENGINE_VERSION;
12013
12188
  exports.EXTERNAL = EXTERNAL;
12189
+ exports.FORWARD_API_VERSION = FORWARD_API_VERSION;
12014
12190
  exports.Game = Game;
12015
12191
  exports.HOUSE_BOTS = HOUSE_BOTS;
12016
12192
  exports.MatchCore = MatchCore;
@@ -12029,6 +12205,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12029
12205
  exports.cleanShout = cleanShout;
12030
12206
  exports.decodeBasicGrid = decodeBasicGrid;
12031
12207
  exports.encodeReplay = encodeReplay;
12208
+ exports.forward = forward;
12032
12209
  exports.frameOf = frameOf;
12033
12210
  exports.frameOutcome = frameOutcome;
12034
12211
  exports.gridLength = gridLength;