Creating games
Guide for adding a new game to gameslib. For API details see Game object and Helpers.
Workflow
- Fork gameslib and work on the
developbranch. - Before first
npm install, runnpm run npm-loginfor GitHub Packages access. - Create
src/games/<uid>.tsextendingGameBase(orGameBaseSimultaneous). - Register in
src/games/index.ts(import, type union, array entry,GameFactorycase). - Add i18n strings to
locales/en/apgames.json(andapresults.jsonif needed). - Flag new games with
experimentalingameinfo. - Test locally — Testing.
- PR against
develop; test on play.dev.abstractplay.com after merge.
Implementation checklist
- [ ]
static readonly gameinfo: APGamesInformation(flagexperimentalmust be set for all new games) - [ ] State interfaces (
IMoveState,I<Name>State) - [ ] Constructor (new + deserialize via
reviver) - [ ]
move,render,state,load,clone,moveState - [ ]
moves()unless usingno-movesflag - [ ]
handleClickfor interactive placement - [ ]
validateMove/checkEOGas needed - [ ] Unit tests under
test/games/ - [ ] Renderer JSON validated against renderer schema
Start from /gameslib/templates/new-game-template.ts and Complica.
Choosing helpers
Most board games use either:
RectGrid— rectangular boards with directions and algebraic coords (Hnefatafl, Go)- Graph classes — hex, snubsquare, sowing, etc. (Helpers overview)
Use the examples by feature index to find games similar to yours.
Renderer
Implement render(opts?) returning APRenderRep for @abstractplay/renderer. Prototype JSON in the renderer playground.