void57-chess
v1.0.2
Published
TypeScript chess library for standard chess and Chess960 (Fischer Random Chess) - move generation, validation, and game management.
Maintainers
Readme
Chess Library
A TypeScript chess library for standard chess and Chess960 (Fischer Random Chess) with complete move generation, validation, and game management.
Features
- Full support for standard chess
- Complete Chess960 (Fischer Random Chess) support with all 960 starting positions
- Move generation and validation
- Proper Chess960 castling rules
- PGN import/export with Chess960 notation
- Position number mapping (Scharnagl numbering 0-959)
- Check, checkmate, and stalemate detection
- Draw conditions (50-move rule, threefold repetition, insufficient material)
- FEN/X-FEN position handling
- Extensively tested in Node.js and modern browsers
- TypeScript with full type definitions
Installation
npm install void57-chessQuick Start
Random Chess960 Game
import { Chess960 } from 'void57-chess'
// Create a random Chess960 position
const chess = new Chess960()
console.log('Starting position:')
console.log(chess.ascii())
// Play a random game
while (!chess.isGameOver()) {
const moves = chess.moves()
const move = moves[Math.floor(Math.random() * moves.length)]
chess.move(move)
}
if (chess.isCheckmate()) {
console.log(`Checkmate! ${chess.turn() === 'w' ? 'Black' : 'White'} wins!`)
} else if (chess.isDraw()) {
console.log('Draw!')
}
console.log(chess.pgn())Standard Chess
import { Chess } from 'void57-chess'
const chess = new Chess()
chess.move('e4')
chess.move('e5')
console.log(chess.ascii())Specific Chess960 Position
import { Chess960 } from 'void57-chess'
// Create position 518 (standard chess starting position)
const standardChess = new Chess960(518)
// Create a specific Chess960 position
const position = new Chess960(42)
// Or load from X-FEN
const fromFen = new Chess960(
'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w HAha - 0 1',
)API Overview
Creating a Standard Chess Game
import { Chess } from 'void57-chess'
const chess = new Chess()
// Start from a specific position
const chess = new Chess(
'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1',
)Creating a Chess960 Game
import { Chess960 } from 'void57-chess'
// Random position (0-959)
const chess = new Chess960()
// Specific position number
const chess = new Chess960(518) // Standard chess is position 518
// From X-FEN string
const chess = new Chess960(
'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1',
)Making Moves
// Move in various notations
chess.move('e4') // Standard algebraic notation
chess.move('Nf3') // Piece moves
chess.move('O-O') // Castling
chess.move({ from: 'e2', to: 'e4' }) // Object notation
// Get legal moves
const moves = chess.moves() // All moves in SAN
const verboseMoves = chess.moves({ verbose: true }) // Detailed move objects
const pieceMoves = chess.moves({ square: 'e2' }) // Moves for specific squareGame State
chess.inCheck() // Is current player in check?
chess.isCheckmate() // Is it checkmate?
chess.isStalemate() // Is it stalemate?
chess.isDraw() // Is it a draw?
chess.isGameOver() // Is game over?
chess.isThreefoldRepetition() // Threefold repetition?
chess.isInsufficientMaterial() // Insufficient material?Position Management
chess.fen() // Get current position in FEN
chess.ascii() // ASCII board representation
chess.board() // 2D array representation
chess.turn() // Current player ('w' or 'b')
chess.history() // Move history
chess.undo() // Undo last move
chess.reset() // Reset to starting positionPGN Support
// Export to PGN
const pgn = chess.pgn()
// Load from PGN
const chess = new Chess960()
chess.loadPgn(pgn)Static Methods
// Generate Chess960 position from number
const fen = Chess960.generatePositionFen(518)
// Validate FEN
import { validateFen } from 'void57-chess'
const result = validateFen(fenString)Development
# Install dependencies
npm install
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Build the library
npm run build
# Format code
npm run format
# Lint code
npm run lint
# Run all checks
npm run checkLicense
MIT License - Copyright (c) 2026 void-57 (Aniruddha)
Contributing
Contributions are welcome! Please read CONTRIBUTING.md for details on how to contribute to this project.
If you have any questions, suggestions, or find any bugs please open an issue. PRs are very welcome too, please read the Contributing Guide first to help make it a smooth process.
