0.0.1 • Published 11 months ago

@sprql/chess.ts v0.0.1

Weekly downloads
-
License
BSD-2-Clause
Repository
github
Last release
11 months ago

chess.ts

chess.ts is a TypeScript chess library used for chess move generation, piece movement, and check/checkmate/stalemate detection.

It is a fork of chess.js. It has been almost entirely rewritten using modern TypeScript approaches and functional programming techniques.

Installation

Run the following command to install the most recent version of chess.js from NPM:

npm install @sprql/chess.ts

Importing

Import (as ESM)

import { Chess } from 'chess.ts'

ECMAScript modules (ESM) can be directly imported in a browser:

<script type="module">
  import { Chess } from 'chess.ts'
</script>

Example Code

The code below plays a random game of chess:

import { Chess } from 'chess.ts'

let game = Chess.create()

while (!Chess.isGameOver(game)) {
  const moves = Chess.getMoves(game)
  const move = moves[Math.floor(Math.random() * moves.length)]
  game = Chess.makeMove(game, move)
}

User Interface

By design, chess.ts is a headless library and does not include user interface elements.

0.0.1

11 months ago