health items
This commit is contained in:
parent
cb3513bd99
commit
62b2b9feca
17 changed files with 611 additions and 141 deletions
|
|
@ -55,6 +55,24 @@ test('bots play the copy-rule variants without breaking a rule', () => {
|
|||
}
|
||||
});
|
||||
|
||||
test('bots play with the health rule off (one-roll combats) without breaking a rule', () => {
|
||||
const rules = withRule(DEFAULT_RULES, 'health.on=false');
|
||||
for (let seed = 1; seed <= 25; seed++) {
|
||||
assert.ok(playGame({ pool, bots: [randomBot, randomBot], seed, rules, check: true }).over);
|
||||
assert.ok(playGame({ pool, bots: [() => greedyBot(), () => greedyBot()], seed, rules, check: true }).over);
|
||||
}
|
||||
});
|
||||
|
||||
test('bots play the health rule without recall, and with Health 8, without breaking a rule', () => {
|
||||
for (const spec of ['health.recall=false', 'health.override=8']) {
|
||||
const rules = withRule(DEFAULT_RULES, spec);
|
||||
for (let seed = 1; seed <= 15; seed++) {
|
||||
assert.ok(playGame({ pool, bots: [randomBot, randomBot], seed, rules, check: true }).over);
|
||||
assert.ok(playGame({ pool, bots: [() => greedyBot(), () => greedyBot()], seed, rules, check: true }).over);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('bots play the command rule without breaking a rule', () => {
|
||||
const rules = withRule(DEFAULT_RULES, 'commands.on=true');
|
||||
for (let seed = 1; seed <= 25; seed++) {
|
||||
|
|
|
|||
182
sim/test/health.test.ts
Normal file
182
sim/test/health.test.ts
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
/** The health rule (rules v0.9): the loser of the roll takes damage; destruction at 0 Health; recall. */
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { healthLeft, healthOf } from '../src/query.ts';
|
||||
import { withRule } from '../src/rules.ts';
|
||||
import { FOREVER } from '../src/types.ts';
|
||||
import { Table } from './table.ts';
|
||||
|
||||
/** Ends steps until player `p` is in their Deploy step. */
|
||||
function turnOf(t: Table, p: 0 | 1): Table {
|
||||
for (let i = 0; i < 12 && !(t.decider === p && t.s.step === 'deploy'); i++) t.end();
|
||||
assert.equal(t.decider, p);
|
||||
assert.equal(t.s.step, 'deploy');
|
||||
return t;
|
||||
}
|
||||
|
||||
/** South's Avatar 1 (Broken Bits, 4 Cores, 9 Health) on B1 facing North's Avatar 1 on C1. */
|
||||
function standoff(o: { northMain?: string[] } = {}): Table {
|
||||
const t = new Table({ health: true, north: { main: o.northMain } });
|
||||
t.own(0, 'B1');
|
||||
t.own(1, 'C1');
|
||||
t.place(0, 1, 'B1');
|
||||
t.place(1, 1, 'C1');
|
||||
return t;
|
||||
}
|
||||
|
||||
test('health: printed Health, and the override rule', () => {
|
||||
const t = standoff();
|
||||
assert.equal(healthOf(t.s, { player: 0, slot: 1 }), 9, 'Broken Bits: 4 Cores, 9 Health');
|
||||
assert.equal(healthOf(t.s, { player: 0, slot: 2 }), 10, 'Pixelated Picture: 3 Cores, 10 Health');
|
||||
t.s.rules = withRule(t.s.rules, 'health.override=8');
|
||||
assert.equal(healthOf(t.s, { player: 0, slot: 1 }), 8);
|
||||
});
|
||||
|
||||
test('health: the loser takes the margin as damage, and nobody moves', () => {
|
||||
const t = standoff();
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(6, 6, 6, 6, 5, 5, 5, 4); // 24 to 19
|
||||
t.end();
|
||||
assert.equal(t.s.locations.C1.owner, 1, 'C1 holds');
|
||||
assert.equal(t.avatar(0, 1).at, 'B1', 'the attacker stays where it attacked from');
|
||||
assert.equal(t.avatar(1, 1).at, 'C1');
|
||||
assert.equal(t.avatar(1, 1).damage, 5);
|
||||
assert.equal(healthLeft(t.s, { player: 1, slot: 1 }), 4);
|
||||
assert.equal(t.s.stats.attacksWon[0], 1);
|
||||
assert.equal(t.s.stats.damageDealt[0], 5);
|
||||
assert.equal(t.s.stats.capturesInCombat[0], 0);
|
||||
assert.equal(t.s.combat, null);
|
||||
});
|
||||
|
||||
test('health: damage adds up; the Avatar is destroyed at 0 Health, loses its Hardware, and the location falls', () => {
|
||||
const t = standoff({ northMain: ['Additional Core'] });
|
||||
const hw = t.hardware(1, 1, 'Additional Core');
|
||||
t.avatar(1, 1).damage = 6;
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(6, 6, 6, 6, 3, 3, 3, 3, 3); // 24 to 15: 9 damage, 3 was enough
|
||||
t.end();
|
||||
assert.equal(t.avatar(1, 1).at, null, 'destroyed: back in its slot');
|
||||
assert.equal(t.avatar(1, 1).damage, 0, 'a destroyed Avatar comes back at full Health');
|
||||
assert.deepEqual(t.avatar(1, 1).hardware, []);
|
||||
assert.ok(t.s.players[1].discard.includes(hw));
|
||||
assert.equal(t.s.locations.C1.owner, 0);
|
||||
assert.equal(t.avatar(0, 1).at, 'C1');
|
||||
assert.equal(t.s.stats.capturesInCombat[0], 1);
|
||||
assert.equal(t.s.stats.avatarsDestroyed[1], 1);
|
||||
assert.equal(t.s.stats.damageDealt[0], 9, 'the whole margin counts as dealt');
|
||||
});
|
||||
|
||||
test('health: a losing attacker takes damage and stays put, or is destroyed by a big enough loss', () => {
|
||||
const t = standoff();
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(3, 3, 3, 3, 4, 4, 4, 4); // 12 to 16
|
||||
t.end();
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
assert.equal(t.avatar(0, 1).damage, 4);
|
||||
assert.equal(t.avatar(1, 1).damage, 0, 'the winner takes no damage');
|
||||
assert.equal(t.s.stats.damageDealt[1], 4);
|
||||
|
||||
const u = standoff();
|
||||
u.avatar(0, 1).damage = 5;
|
||||
u.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
u.rig(1, 1, 1, 1, 2, 2, 2, 2); // 4 to 8: 4 damage, 4 left
|
||||
u.end();
|
||||
assert.equal(u.avatar(0, 1).at, null, 'destroyed');
|
||||
assert.equal(u.avatar(0, 1).damage, 0);
|
||||
assert.equal(u.s.locations.B1.owner, 0, 'losing an attack never loses the origin');
|
||||
});
|
||||
|
||||
test('health: a tie is a stalemate, with no reroll and no damage', () => {
|
||||
const t = standoff();
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(3, 3, 3, 3, 4, 4, 2, 2);
|
||||
t.end();
|
||||
assert.equal(t.avatar(0, 1).damage, 0);
|
||||
assert.equal(t.avatar(1, 1).damage, 0);
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
assert.equal(t.avatar(1, 1).at, 'C1');
|
||||
assert.deepEqual(t.s.rigged, [], 'no dice were rerolled');
|
||||
assert.match(t.logText(), /stalemate/);
|
||||
assert.equal(t.s.stats.combatsTied[0], 1);
|
||||
assert.equal(t.s.stats.attacksWon[0], 0);
|
||||
});
|
||||
|
||||
test('health: recall heals fully, keeps Hardware, counts as the placement, and leaves the location undefended', () => {
|
||||
const t = standoff({ northMain: ['Additional Core'] });
|
||||
const hw = t.hardware(1, 1, 'Additional Core');
|
||||
t.avatar(1, 1).damage = 7;
|
||||
t.avatar(1, 1).infection = 2;
|
||||
turnOf(t, 1); // South's turn passes without acting
|
||||
assert.ok(t.can({ type: 'recall', slot: 1 }));
|
||||
assert.ok(!t.can({ type: 'recall', slot: 2 }), 'only Avatars in play can be recalled');
|
||||
t.go({ type: 'recall', slot: 1 });
|
||||
const av = t.avatar(1, 1);
|
||||
assert.equal(av.at, null);
|
||||
assert.equal(av.damage, 0);
|
||||
assert.equal(av.infection, 0, 'leaving play removes counters');
|
||||
assert.deepEqual(av.hardware, [hw], 'Hardware stays on it');
|
||||
assert.ok(av.placed, 'the recall was its placement');
|
||||
assert.ok(!t.can({ type: 'place', slot: 1, to: 'C1' }), "it can't come back this turn");
|
||||
assert.equal(t.s.stats.recalls[1], 1);
|
||||
assert.equal(t.s.locations.C1.owner, 1, 'C1 is still North\'s, just undefended');
|
||||
// South can now walk in.
|
||||
turnOf(t, 0);
|
||||
assert.ok(t.can({ type: 'advance', slot: 1, to: 'C1' }));
|
||||
});
|
||||
|
||||
test('health: a rooted Avatar can\'t be recalled, and the rule can be switched off', () => {
|
||||
const t = standoff();
|
||||
t.avatar(0, 1).rootedUntil = FOREVER;
|
||||
assert.ok(!t.can({ type: 'recall', slot: 1 }), 'Packet Flood: no retreat');
|
||||
t.avatar(0, 1).rootedUntil = 0;
|
||||
assert.ok(t.can({ type: 'recall', slot: 1 }));
|
||||
t.s.rules = withRule(t.s.rules, 'health.recall=false');
|
||||
assert.ok(!t.can({ type: 'recall', slot: 1 }));
|
||||
});
|
||||
|
||||
test('health: Redundant Power Supply still saves the Hardware of a destroyed Avatar', () => {
|
||||
const t = standoff({ northMain: ['Redundant Power Supply', 'Additional Core'] });
|
||||
const rps = t.hardware(1, 1, 'Redundant Power Supply');
|
||||
const core = t.hardware(1, 1, 'Additional Core');
|
||||
t.avatar(1, 1).damage = 8;
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(6, 6, 6, 6, 1, 1, 1, 1, 1); // 24 to 5
|
||||
t.end();
|
||||
assert.equal(t.avatar(1, 1).at, null);
|
||||
assert.deepEqual([...t.avatar(1, 1).hardware].sort(), [rps, core].sort());
|
||||
assert.equal(t.s.locations.C1.owner, 0);
|
||||
});
|
||||
|
||||
test('health: with two defenders the damage destroys the weakest first, and the location falls only when both are gone', () => {
|
||||
const t = new Table({ health: true, north: { servers: ['Cluster Server'] } });
|
||||
t.own(0, 'B1');
|
||||
t.own(1, 'C1', 'Cluster Server');
|
||||
t.place(0, 1, 'B1');
|
||||
t.place(1, 1, 'C1'); // Broken Bits, 4 Cores, 9 Health
|
||||
t.place(1, 2, 'C1'); // Pixelated Picture, 3 Cores, 10 Health
|
||||
t.avatar(1, 2).damage = 7; // 3 left
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(6, 6, 6, 6, 1, 1, 1, 1, 5, 5, 5); // 24 to 4 + 15 = 19: 5 damage
|
||||
t.end();
|
||||
assert.equal(t.avatar(1, 2).at, null, 'the weak one is destroyed with 3 of the damage');
|
||||
assert.equal(t.avatar(1, 1).damage, 2, 'the other 2 land on the survivor');
|
||||
assert.equal(t.s.locations.C1.owner, 1, 'C1 holds with a defender left');
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
|
||||
// Enough damage for both takes the location.
|
||||
const u = new Table({ health: true, north: { servers: ['Cluster Server'] } });
|
||||
u.own(0, 'B1');
|
||||
u.own(1, 'C1', 'Cluster Server');
|
||||
u.place(0, 1, 'B1');
|
||||
u.place(1, 1, 'C1');
|
||||
u.place(1, 2, 'C1');
|
||||
u.avatar(1, 1).damage = 8;
|
||||
u.avatar(1, 2).damage = 8;
|
||||
u.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
u.rig(6, 6, 6, 6, 1, 1, 1, 1, 1, 1, 1); // 24 to 7: 17 damage for 1 + 2 left
|
||||
u.end();
|
||||
assert.equal(u.avatar(1, 1).at, null);
|
||||
assert.equal(u.avatar(1, 2).at, null);
|
||||
assert.equal(u.s.locations.C1.owner, 0);
|
||||
assert.equal(u.avatar(0, 1).at, 'C1');
|
||||
});
|
||||
|
|
@ -29,18 +29,20 @@ export interface Side {
|
|||
export class Table {
|
||||
s: GameState;
|
||||
|
||||
constructor(o: { south?: Side; north?: Side; first?: PlayerId; seed?: number } = {}) {
|
||||
constructor(o: { south?: Side; north?: Side; first?: PlayerId; seed?: number; health?: boolean } = {}) {
|
||||
const side = (x: Side = {}) => ({
|
||||
avatars: x.avatars ?? DEFAULT_AVATARS,
|
||||
servers: [...(x.servers ?? []), ...Array(12).fill(PLAIN_SERVER)],
|
||||
main: [...(x.main ?? []), ...Array(12).fill(FILLER)],
|
||||
});
|
||||
const decks = [side(o.south), side(o.north)] as const;
|
||||
// Classic turns (one turn each, every Avatar acts), which the card tests are written for. The
|
||||
// command rule has its own tests in engine.test.ts.
|
||||
// Classic turns (one turn each, every Avatar acts) and one-roll combats, which the card tests
|
||||
// are written for. The command rule has its own tests in engine.test.ts, the health rule in
|
||||
// health.test.ts (`health: true`).
|
||||
const rules: RulesConfig = {
|
||||
...DEFAULT_RULES,
|
||||
commands: { ...DEFAULT_RULES.commands, on: false },
|
||||
health: { ...DEFAULT_RULES.health, on: o.health ?? false },
|
||||
openingHand: 0,
|
||||
deck: { avatars: 4, servers: decks[0].servers.length, main: decks[0].main.length, maxCopies: 99 },
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue