victris-arena-sim 0.90.0 → 0.92.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.90.0. Each release of the ladder plays on the simulator of the same
21
+ This is release 0.92.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
@@ -1202,9 +1202,10 @@ var ArenaSim = (function(exports) {
1202
1202
  turns: /* @__PURE__ */ new Map()
1203
1203
  };
1204
1204
  phase1Validate(ctx, input);
1205
+ takePadsUnderfoot(ctx);
1205
1206
  phase2Dashes(ctx);
1206
1207
  phase3Movement(ctx);
1207
- phase4Pickups(ctx);
1208
+ takePadsUnderfoot(ctx);
1208
1209
  phase5Attacks(ctx);
1209
1210
  phase6Zone(ctx);
1210
1211
  phase7Deaths(ctx);
@@ -1308,6 +1309,7 @@ var ArenaSim = (function(exports) {
1308
1309
  f.invulnerable = true;
1309
1310
  f.cooldowns.dash = state.rules.dash.cooldown;
1310
1311
  }
1312
+ const claims = [];
1311
1313
  for (let i = 0; i < state.rules.dash.distance && active.size > 0; i++) {
1312
1314
  const movers = [];
1313
1315
  for (const f of dashers) {
@@ -1324,8 +1326,22 @@ var ArenaSim = (function(exports) {
1324
1326
  });
1325
1327
  }
1326
1328
  const ok = resolveSimultaneous(movers, occupancy(state));
1327
- for (const m of movers) if (!ok.has(m.id)) active.delete(m.id);
1328
- else state.fighters.find((f) => f.id === m.id).pos = m.to;
1329
+ for (const m of movers) {
1330
+ if (!ok.has(m.id)) {
1331
+ active.delete(m.id);
1332
+ continue;
1333
+ }
1334
+ const f = state.fighters.find((x) => x.id === m.id);
1335
+ f.pos = m.to;
1336
+ const pad = stockedPad(state, m.to);
1337
+ if (pad) {
1338
+ pad.available = false;
1339
+ claims.push({
1340
+ pad,
1341
+ f
1342
+ });
1343
+ }
1344
+ }
1329
1345
  }
1330
1346
  for (const f of dashers) {
1331
1347
  const from = start.get(f.id);
@@ -1336,6 +1352,7 @@ var ArenaSim = (function(exports) {
1336
1352
  to: [f.pos[0], f.pos[1]]
1337
1353
  });
1338
1354
  }
1355
+ for (const { pad, f } of claims) takePickup(ctx, pad, f);
1339
1356
  }
1340
1357
  function moveCooldown(state) {
1341
1358
  return state.rules.stats.move_cooldown;
@@ -1375,31 +1392,53 @@ var ArenaSim = (function(exports) {
1375
1392
  f.pos = m.to;
1376
1393
  }
1377
1394
  }
1378
- /** Anyone standing on a stocked pad after movement takes it. Only one fighter fits a tile. */
1379
- function phase4Pickups(ctx) {
1395
+ /**
1396
+ * Anyone standing on a stocked pad takes it: once as the tick begins, for pads that restocked
1397
+ * under a fighter, and again after movement (phase 4). Only one fighter fits a tile. Pads a
1398
+ * dash enters go in phase 2, and pads a repulsor push crosses in phase 5.
1399
+ */
1400
+ function takePadsUnderfoot(ctx) {
1380
1401
  const { state } = ctx;
1381
- const rules = state.rules.pickups;
1382
- if (!rules) return;
1402
+ if (!state.rules.pickups) return;
1383
1403
  for (const pad of state.pickups) {
1384
1404
  if (!pad.available) continue;
1385
1405
  const f = alive(state).find((x) => eq(x.pos, pad.pos));
1386
- if (!f) continue;
1387
- pad.available = false;
1388
- const kind = pad.kind;
1389
- pad.respawn_tick = ctx.tick + rules[kind].respawn;
1390
- ctx.events.push({
1391
- kind: "pickup",
1392
- fighter: f.id,
1393
- pad: pad.id,
1394
- pickup: pad.kind,
1395
- pos: [pad.pos[0], pad.pos[1]]
1396
- });
1397
- if (kind === "health") f.hp = Math.min(state.rules.stats.max_hp, f.hp + rules.health.amount);
1398
- else {
1399
- const buff = rules[kind];
1400
- f.buffs[kind] = Math.max(f.buffs[kind] ?? -1, ctx.tick + buff.duration - 1);
1401
- }
1406
+ if (f) takePickup(ctx, pad, f);
1407
+ }
1408
+ }
1409
+ /** The stocked pad on `pos`, if pickups are on and there is one. */
1410
+ function stockedPad(state, pos) {
1411
+ if (!state.rules.pickups) return void 0;
1412
+ return state.pickups.find((p) => p.available && eq(p.pos, pos));
1413
+ }
1414
+ /**
1415
+ * `f` takes `pad`. A buff taken while repulsors resolve is granted through `later`, once every
1416
+ * repulsor has landed: they land in fighter-id order, so granting it at once would let a
1417
+ * fighter pushed onto power by a lower id boost its own repulsor that tick, and never the reverse.
1418
+ */
1419
+ function takePickup(ctx, pad, f, later) {
1420
+ const { state } = ctx;
1421
+ const rules = state.rules.pickups;
1422
+ pad.available = false;
1423
+ const kind = pad.kind;
1424
+ pad.respawn_tick = ctx.tick + rules[kind].respawn;
1425
+ ctx.events.push({
1426
+ kind: "pickup",
1427
+ fighter: f.id,
1428
+ pad: pad.id,
1429
+ pickup: pad.kind,
1430
+ pos: [pad.pos[0], pad.pos[1]]
1431
+ });
1432
+ if (kind === "health") {
1433
+ f.hp = Math.min(state.rules.stats.max_hp, f.hp + rules.health.amount);
1434
+ return;
1402
1435
  }
1436
+ const buff = rules[kind];
1437
+ const grant = () => {
1438
+ f.buffs[kind] = Math.max(f.buffs[kind] ?? -1, ctx.tick + buff.duration - 1);
1439
+ };
1440
+ if (later) later.push(grant);
1441
+ else grant();
1403
1442
  }
1404
1443
  /**
1405
1444
  * Attacks fire the tick they are sent, after movement. Repulsors resolve first, from
@@ -1443,6 +1482,7 @@ var ArenaSim = (function(exports) {
1443
1482
  ...r,
1444
1483
  hits: repulsorHits(ctx, r.f, r.name)
1445
1484
  }));
1485
+ const later = [];
1446
1486
  for (const r of repulses) {
1447
1487
  const atk = rules.attacks[r.name];
1448
1488
  if (atk.kind !== "burst") continue;
@@ -1452,9 +1492,10 @@ var ArenaSim = (function(exports) {
1452
1492
  attack: r.name,
1453
1493
  damage: atk.damage
1454
1494
  }, t);
1455
- push(ctx, r.f, t, octant(r.f.pos, t.pos), atk.push);
1495
+ push(ctx, r.f, t, octant(r.f.pos, t.pos), atk.push, later);
1456
1496
  }
1457
1497
  }
1498
+ for (const grant of later) grant();
1458
1499
  for (const { f, name, target, direction } of fired) {
1459
1500
  const atk = rules.attacks[name];
1460
1501
  if (atk.kind === "area") {
@@ -1594,11 +1635,11 @@ var ArenaSim = (function(exports) {
1594
1635
  return ctx.state.fighters.filter((t) => t.alive && !t.invulnerable && weaponCanAffect(ctx.state, f.id, t) && tiles.some((p) => eq(p, t.pos)));
1595
1636
  }
1596
1637
  /**
1597
- * Shoves `t` up to `tiles` steps in `dir`, one at a time. A wall (or a corner it
1598
- * can't cut past) stops it with a slam: damage and a stun. Another fighter stops it
1599
- * with a collision that hurts both.
1638
+ * Shoves `t` up to `tiles` steps in `dir`, one at a time, taking each stocked pad it lands on.
1639
+ * A wall (or a corner it can't cut past) stops it with a slam: damage and a stun. Another
1640
+ * fighter stops it with a collision that hurts both.
1600
1641
  */
1601
- function push(ctx, attacker, t, dir, tiles) {
1642
+ function push(ctx, attacker, t, dir, tiles, later) {
1602
1643
  const { state } = ctx;
1603
1644
  const kb = state.rules.knockback;
1604
1645
  const from = [t.pos[0], t.pos[1]];
@@ -1636,6 +1677,8 @@ var ArenaSim = (function(exports) {
1636
1677
  break;
1637
1678
  }
1638
1679
  t.pos = next;
1680
+ const pad = stockedPad(state, t.pos);
1681
+ if (pad && t.hp > 0) takePickup(ctx, pad, t, later);
1639
1682
  }
1640
1683
  if (!eq(from, t.pos)) ctx.events.push({
1641
1684
  kind: "knockback",
@@ -1727,7 +1770,7 @@ var ArenaSim = (function(exports) {
1727
1770
  state.tick += 1;
1728
1771
  }
1729
1772
  // packages/engine/src/replay.ts
1730
- var ENGINE_VERSION = "0.23.0";
1773
+ var ENGINE_VERSION = "0.24.0";
1731
1774
  function makeHeader(rules, map, seed, bots) {
1732
1775
  return {
1733
1776
  type: "header",
@@ -1770,7 +1813,7 @@ var ArenaSim = (function(exports) {
1770
1813
  }
1771
1814
  function checkCompatible(header) {
1772
1815
  if (header.replay_format !== void 0 && header.replay_format !== 1) throw new Error(`replay: unsupported format ${header.replay_format}`);
1773
- if (header.engine !== "0.23.0") throw new Error(`replay: recorded with engine ${header.engine}, this is ${ENGINE_VERSION}`);
1816
+ if (header.engine !== "0.24.0") throw new Error(`replay: recorded with engine ${header.engine}, this is ${ENGINE_VERSION}`);
1774
1817
  const rules = loadRules(header.rules);
1775
1818
  if (rulesHash(rules) !== header.rules_hash) throw new Error("replay: rules hash mismatch");
1776
1819
  return {
@@ -1930,7 +1973,10 @@ var ArenaSim = (function(exports) {
1930
1973
  }
1931
1974
  const events = step(state, turns);
1932
1975
  stats.ticks += 1;
1976
+ const hp = new Map([...before].map(([id, b]) => [id, b.hp]));
1933
1977
  const hurt = (target, source, n, attacker) => {
1978
+ const now = hp.get(target);
1979
+ if (now !== void 0) hp.set(target, Math.max(0, now - n));
1934
1980
  const t = fighter(target);
1935
1981
  if (t) t.damage_taken += n, bump(t.taken_by_source, source, n);
1936
1982
  const a = attacker === void 0 || attacker === target ? void 0 : fighter(attacker);
@@ -1965,9 +2011,13 @@ var ArenaSim = (function(exports) {
1965
2011
  const f = fighter(e.fighter);
1966
2012
  if (!f) break;
1967
2013
  bump(f.pickups, e.pickup);
1968
- const b = before.get(e.fighter);
2014
+ const was = hp.get(e.fighter);
1969
2015
  const amount = state.rules.pickups?.health?.amount ?? 0;
1970
- if (e.pickup === "health" && b) f.healed += Math.min(state.rules.stats.max_hp, b.hp + amount) - b.hp;
2016
+ if (e.pickup === "health" && was !== void 0) {
2017
+ const now = Math.min(state.rules.stats.max_hp, was + amount);
2018
+ f.healed += now - was;
2019
+ hp.set(e.fighter, now);
2020
+ }
1971
2021
  break;
1972
2022
  }
1973
2023
  case "wall_slam": {
@@ -10171,7 +10221,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
10171
10221
  * that doesn't match). The downloadable simulator and the Python package carry it, so a player
10172
10222
  * can tell whether their copy is the one the ladder runs (GET /api versions.release).
10173
10223
  */
10174
- var RELEASE = "0.90.0";
10224
+ var RELEASE = "0.92.0";
10175
10225
  // packages/sim/src/match.ts
10176
10226
  /** No usable reply before the deadline. */
10177
10227
  function timeoutOutcome() {