import { decideMonsterAI, Pathfinder, Level, WALL, FLOOR } from '@datamoc/mw_games/roguelike';
const level = new Level(20, 20, [WALL, FLOOR], 1);
const pathfinder = new Pathfinder(level);
const decision = decideMonsterAI(level, pathfinder, { x: 5, y: 5 }, 0.8, { x: 8, y: 5 }, {
sightRadius: 6,
fleeBelow: 0.2,
});
if (decision.step) console.log(decision.state, decision.step); // 'hunt', a step towards the player
One monster's turn: wander when the target is outside its own sight, hunt when it can see the target and is healthy, flee when it can see the target and its own HP has dropped to
fleeBelowor lower. Built entirely fromFieldOfViewandPathfinder- both already shipped - so this is what turns them into an actual decision, rather than a game hand-rolling the same wander/hunt/flee branch on its own.A fresh
FieldOfViewper call is deliberate: a monster's sight is its own, not the player's, and computing a small-radius shadowcast once per monster per turn is cheap at the monster counts a level actually has.mwgdoes not decide what a monster does with the result - a game's own turn loop calls this once per monster and acts on thestep(or doesn't, for wander's "nowhere in particular").