Game object

Every game is a class extending GameBase (or GameBaseSimultaneous for simultaneous moves).

Required abstract methods

Method Purpose
move(m, opts?) Apply a move string; return updated game
render(opts?) Return APRenderRep (or array) for the renderer
state(opts?) Return IAPGameState snapshot
load(idx) Load stack position (default: latest)
clone() Deep copy
moveState() Snapshot for pushing onto stack (protected)

State shape (IAPGameState)

{
  game: string;        // uid
  numplayers: number;
  variants: string[];
  gameover: boolean;
  winner: number[];
  stack: IIndividualState[];
}

You typically don't need to alter IAPGameState, but if there is game-wide information you need to store (information that doesn't change move to move), this is the most efficient place to store it.

Each IIndividualState requires _version, _results, _timestamp. The rest is up to the game itself. It's really up to the developer how they want to structure things. As long as the game code will correctly hydrate a saved state, you're good.

Provided by GameBase

Serialization: serialize(), undo(), resign(), timeout(), draw(), abandoned().

UI: handleClick(), moves(), validateMove(), sidebarStatuses(), getButtons() (when flagged).

History: moveHistory(), resultsHistory(), chatLog(), chat(), genRecord().

IRenderOpts

Optional render() arguments: perspective, altDisplay, hideLayer. Games with stacking-expanding pass click coordinates through render options.

IClickResult

Returned by handleClick: valid, message, move, optional complete and canrender.

Example games