mwg API
    Preparing search index...

    Class Aspects

    The named tuning knobs of a heuristic AI - Wesnoth's "aspects" - read by whatever stage is scoring candidates. mwg ships no values, because the numbers are game content: a side sets aggression, caution, village_value, keep_away and the rest to whatever its own balance wants, and a difficulty level overrides a few of them.

    Typed readers give a stage a usable number without every caller casting: a missing aspect reads as the fallback (1 for a weight, so an unset aspect is neutral rather than zeroing a score).

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

    const aspects = new Aspects({ aggression: 2, keep_away: 3 });
    console.log(aspects.number('aggression')); // 2
    console.log(aspects.number('caution')); // 0 - the fallback
    Index
    • Parameters

      • name: string
      • fallback: boolean = false

      Returns boolean

    • a list aspect; a bare string reads as a one-entry list, anything else as empty

      Parameters

      • name: string

      Returns readonly string[]

    • a numeric aspect, or fallback when it is missing or not a number

      Parameters

      • name: string
      • fallback: number = 0

      Returns number