mwg API
    Preparing search index...

    Function subjectsWhere

    • The subjects a filter selects, matching only the attributes the filter names.

      This is how a mind finds "the enemy leader" without re-deriving it from ids, the gap a bare ScoreSubject left: subjectsWhere(world, { side: 'red', can_recruit: true }). can_recruit reads a missing value as false, so { can_recruit: false } selects everyone who is not a leader, and { role: 'courier' } selects a named function.

      Type Parameters

      • T

      Parameters

      Returns ScoreSubject<T>[]

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

      const world = [
      { id: 'hero', side: 'blue', x: 0, y: 0, role: 'leader', can_recruit: true },
      { id: 'grunt', side: 'blue', x: 1, y: 0 },
      ];
      console.log(subjectsWhere(world, { can_recruit: true }).map((subject) => subject.id)); // ['hero']