Skip to content

Reinforcement-learning environments

HyperToken provides three TypeScript interfaces under ai/interface:

Interface How play advances
GymEnvironment One policy takes one action; step() returns observation, reward, and done flags.
AECEnvironment Agents take turns. agentSelection() identifies the actor and observe(agent) returns that seat's numeric features.
ParallelEnvironment One action dictionary advances a simultaneous round; step() returns maps keyed by agent.
Environment Interface Episode
Blackjack (BlackjackAEC) AEC One round against the dealer, bankroll-delta reward.
Blackjack (BlackjackEnv) Gym One round with surrender and additional hand features.
Cuttle (CuttleAEC) AEC Two-player card combat; per-state shaping and win/loss rewards.
Hanabi (HanabiAEC) AEC Cooperative card play; each player receives the team score change.
Coup (CoupAEC) AEC Bluffing and challenges; surviving player wins.
Liar's Dice (LiarsDiceAEC) AEC Escalating bids about hidden dice; last player with dice wins.
Poker (PokerAEC) AEC One fresh heads-up Hold'em hand; net chip reward by default, optional shaping.
Prisoner's Dilemma (PrisonersDilemmaParallel) Parallel A fixed number of simultaneous cooperate/defect rounds in TypeScript.

Call await env.reset(seed) before play. For a controlled run, keep policy randomness separate from game randomness and record the environment configuration, reset seed, and sequence of actions. For a turn-based policy, inspect actionMask(agent) on every turn; Cuttle's target action IDs, for example, depend on the current legal choices. AEC last() consumes only that agent's accrued reward, and last(agent) allows terminal reads after agents becomes empty.

import { mulberry32 } from "./core/random.js";
import { HanabiAEC } from "./examples/hanabi/HanabiAEC.js";

const env = new HanabiAEC({ numPlayers: 3 });
const rng = mulberry32(123);
try {
  await env.reset(42);
  for (const agent of env.agentIteration()) {
    const legal = env.actionMask(agent).flatMap((valid, i) => valid ? [i] : []);
    await env.step(legal[Math.floor(rng() * legal.length)]);
  }
  console.log(env.infos());
} finally {
  env.close();
}

To drive the AEC games from Python, see Python bridge. To play with a trained model in TypeScript, see ONNX policy export. The environments and interfaces run without an ONNX runtime unless model inference is requested.