mwg API
    Preparing search index...

    Function decideMonsterAI

    • 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 fleeBelow or lower. Built entirely from FieldOfView and Pathfinder - 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 FieldOfView per 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. mwg does not decide what a monster does with the result - a game's own turn loop calls this once per monster and acts on the step (or doesn't, for wander's "nowhere in particular").

      Parameters

      Returns Roguelike.AIDecision

      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