mwg API
    Preparing search index...

    Class NeuralPolicy

    A small shared dense policy, usable inside existing JavaScriptAI behaviours. Model weights are copied on construction. Supply a seeded random callback to sample softmax scores; omit it for the first highest-scoring legal action. All-masked is idle. Async batches return detached results, never mutate game state; callers must discard results whose scene or position changed while awaiting them.

    import { NeuralPolicy, JavaScriptAI } from '@datamoc/mwg/ai';
    const policy = new NeuralPolicy({ version: 1, observationVersion: 'v1', layers: [
    { inputSize: 1, outputSize: 2, weights: [-1, 1], biases: [0, 0] },
    ] });
    console.log(policy.selectAction({ input: [2] })); // 1
    const ai = new JavaScriptAI({ seed: 7 });
    ai.register({ id: 'npc', behaviors: [policy.behavior('neural',
    [{ type: 'left' }, { type: 'right' }], () => ({ input: [2] }))] });
    console.log(ai.decide('npc', { perception: null }).action?.type); // right
    const scores = await policy.predictBatchAsync([[2], [-2]]);
    Index
    • Parameters

      • input: readonly number[]
      • Optionaloutput: Float64Array<ArrayBufferLike>

      Returns Float64Array

    • One cancellable worker batch: at most 65536 observations and one million input or output values.

      Parameters

      • inputs: readonly (readonly number[])[]
      • options: { signal?: AbortSignal; timeout?: number } = {}

      Returns Promise<Float64Array<ArrayBufferLike>[]>