quoridor.js
Installation
npm install quoridor
API
createNewGame: () => Game
Generates a new game.
import { createNewGame, getUnicodeRepresentation } from 'quoridor';
const game = createNewGame();
console.log(getUnicodeRepresentation(game));
createGameFromMoves: (moves: Move[]) => Game
Generates a game from an array of moves. Does not verify that the moves are valid.
import { createGameFromMoves, getUnicodeRepresentation } from 'quoridor';
const game = createGameFromMoves(['e2', 'e8', 'd7v']);
console.log(getUnicodeRepresentation(game));
getUnicodeRepresentation: (game: Game) => string
Returns a string representation of the board game state using Unicode box-drawing characters.
import { createNewGame, getUnicodeRepresentation } from 'quoridor';
const unicodeRepresentation = getUnicodeRepresentation(createNewGame())
console.log(unicodeRepresentation);
isMoveValid: (game: Game, move: Move) => boolean
Checks if a move is valid.
import { createGameFromMoves, isMoveValid } from 'quoridor';
const game = createGameFromMoves(['e2', 'e8', 'd7v']);
const move = 'd7';
const moveIsValid = isMoveValid(game, move);
console.log(moveIsValid);
isMove: (maybeMove: string) => boolean
Checks if a string is a move. This can be convenient when using TypeScript since
it can be used as a type guard to safely cast a string to a Move.
import { isMove } from 'quoridor';
const game = createGameFromMoves(['e2', 'e8', 'd7v']);
const move = 'd7';
const moveIsValid = isMove(game, move);
console.log(isMove('a1'));
console.log(isMove('humbug'));
console.log(isMove('i9'))
undo: (game: Game) => Game
Returns a new game with the most recent move undone. If no moves have been made yet, an identical game is returned.
import { createGameFromMoves, undo, getUnicodeRepresentation } from 'quoridor';
const game = createGameFromMoves(['e2', 'e8', 'd7v']);
const gameWithUndoneMove = undo(game);
console.log(getUnicodeRepresentation(game));
console.log(getUnicodeRepresentation(gameWithUndoneMove));
redo: (game: Game) => Game
Returns a new game with the most recently undone move redone. If no moves have been undone yet, an identical game is returned.
import { createGameFromMoves, redo, undo, getUnicodeRepresentation } from 'quoridor';
const game = createGameFromMoves(['e2', 'e8', 'd7v']);
const gameWithUndoneMove = undo(game);
const gameWithUndoneMoveRedone = redo(gameWithUndoneMove);
console.log(getUnicodeRepresentation(game));
console.log(getUnicodeRepresentation(gameWithUndoneMove));
console.log(getUnicodeRepresentation(gameWithUndoneMoveRedone));
Publishing a new version
Check that linting, formatting, build and tests pass
npm run lint
npm run format
npm run build
npm test
Bump version
npm version [major | minor | patch]
Publish to NPM
npm publish