import { startingSkirmish, addSkirmishUnit, skirmishAttack } from '@datamoc/mw_games/board';
import { Random } from '@datamoc/mw_games/core';
const state = startingSkirmish(6, 6, { plain: { moveCost: 1, defense: 0 } });
addSkirmishUnit(state, { id: 'axeman', owner: 'blue', x: 0, y: 0, hp: 10, maxHp: 10, moves: 4, attack: 4, hitChance: 1 });
addSkirmishUnit(state, { id: 'raider', owner: 'red', x: 1, y: 0, hp: 10, maxHp: 10, moves: 4, attack: 3, hitChance: 1 });
const exchange = Random.withSeed(1, () => skirmishAttack(state, 'axeman', 'raider'));
console.log(exchange.strikes.map((strike: { attacker: string }) => strike.attacker)); // ['axeman', 'raider'] - raider survived to retaliate
An attacker's strike against an adjacent enemy, followed by the defender's own retaliation if it survives - both use the same formula:
hitChancereduced by the defender's terrain defence,Random.chancedeciding whether it lands,attackas the flat damage on a hit.