libtak
v1.0.0-beta.1
Published
A TypeScript library for representing, parsing, and manipulating Tak game states, moves, and notations
Readme
libtak
A TypeScript library for representing, parsing, and manipulating Tak game states, moves, and notations.
Usage
Run npm i libtak and then import { Game } from "libtak" etc.
Use an IDE with auto-completion for the full API, or browse the tests folder for reference.
Features
Core Models and Types
- Utility functions for board creation and updates, reserve management, etc.
Board,Game,Stone,Turn, and related types are provided for representing game states with strict type-checking.
Game Play Logic
- Full support for Tak rules, including opening rules, move validation, and winning conditions.
play(game: Game, turn: Turn): Game- apply a move or placement to a game state, returning the new state.hasWinner(game: Game): WinState- detects road wins, flat wins, and draws according to Tak rules.
PTN Support (Portable Tak Notation)
parsePTNData(ptn: string): { metadata, turns }- Parse PTN file contents into metadata and turns.createPTNData(turns: Turn[], boardSize, metadata): string- Create PTN file contents from a list of turns.parsePTN(ptn: string): Game- Parse a PTN file and recreate the resultingGamestate.parseTurn(size: number, turn: string): Turn- Parse a single PTN turn notation.
TPS Support (Tak Positional System)
parseTPS(tps: string): Game- Parse a TPS string and return aGameinstance.createTPS(game: Game): string- Serialize aGameinstance to a TPS string.
