mwg API
    Preparing search index...

    Class HeuristicAI<A>

    The candidate-action pipeline at the heart of a Wesnoth-style AI: stages run in order, the first one whose when passes scores every candidate with its weigh, and the highest score wins (the earlier candidate on a tie, so a decision is stable across equal scores).

    The default weigh is the aspect-weighted sum of each candidate's factors, which is what makes the aspects worth having: a game sets aggression: 2 once and every candidate naming aggression is worth twice as much. keep_away is honoured through a candidate's distance factor. A stage that needs more - goal priorities, terrain, this turn's state - brings its own weigh, and mwg stays out of the rules.

    import { Aspects, HeuristicAI } from '@datamoc/mw_games/ai';

    const ai = new HeuristicAI<{ kind: string }>({ stages: [{ id: 'best' }] });
    const decision = ai.decide(
    [
    { id: 'wait', action: { kind: 'wait' }, factors: { caution: 2 } },
    { id: 'charge', action: { kind: 'attack' }, factors: { aggression: 3 } },
    ],
    { aspects: new Aspects({ aggression: 1, caution: 1 }) },
    );
    console.log(decision?.candidate.id); // 'charge'

    Type Parameters

    • A = unknown
    Index