import { FactionFog } from '@datamoc/mw_games/board';
import { scoreWith, sideScoreView } from '@datamoc/mw_games/ai';
const fog = new FactionFog(10, 10);
const world = [
{ id: 'scout', side: 'blue', x: 1, y: 1 },
{ id: 'guard', side: 'blue', x: 7, y: 7 },
{ id: 'rat', side: 'red', x: 3, y: 1 },
];
const worth = (id: string) => ({ scout: 6, guard: 9, rat: -3 })[id] ?? 0;
// the side reads what its units see: the scout alone would miss the rat at (3, 1)
fog.sync('blue', [{ x: 4, y: 1 }], (source) => [source]);
console.log(sideScoreView('blue', world, worth, fog.sees('blue')).enemies); // -3
fog.sync('blue', [], () => []); // nobody watching, so nothing is read
console.log(sideScoreView('blue', world, worth, fog.sees('blue')).enemies); // 0
console.log(scoreWith(sideScoreView('blue', world, worth, fog.sees('blue')), { own: 0, allies: 1, enemies: -1 }));
The view a whole side has: every unit on it that the side can see, and every enemy it can see.
ownis 0, because a side has no body of its own - its units are whatalliescounts. Hand this the union of a side's sight (FactionFog.sees(side)after syncing every unit of it) and the same arithmetic that reads for one character reads for the player.