nimchess

A chess library for Nim

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version 0.10.0
License LGPL-3.0-linking-exception
CI Status Failing
Downloads 0
Last Indexed 2026-07-21 05:27

Authors

  • Jost Triller

Installation

nimble install nimchess
choosenim install nimchess
git clone https://github.com/tsoj/nimchess

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
nimchess - - - - - - -

Dependencies

Package Version Optional
nim >= 2.2.4 No

Source

Repository https://github.com/tsoj/nimchess
Homepage https://github.com/tsoj/nimchess
Registry Source nimble_official

README

nimchess

A fast and efficient chess library for Nim, with move generation and support for common chess formats.

Docs

Installation

Add nimchess to your .nimble file:

requires "nimchess >= 0.3.1"

Or install directly:

nimble install nimchess

Features

  • Fast move generation using bitboards
  • FEN parsing and generation
  • PGN reading and writing with SAN notation support
  • Chess960 (Fischer Random) support
  • UCI chess engine communication and analysis (client)
  • UCI protocol server for implementing chess engines

Quick Examples

Creating Positions

import nimchess

# Starting position
let startPos = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1".toPosition

# From Chess960 FEN string
let frcPos = "rnbqkbrn/p1pp1pp1/4p3/7p/2p4P/2P5/PP1PPPP1/R1BQKBRN w QGqg - 0 9".toPosition

Working with Moves

# Create move from UCI or SAN notation
let move = "Nf3".toMove(position)

# Check if move is legal and make a move
if position.isLegal(move):
  let newPos = position.doMove(move)

# Get all legal moves of a position
for move in position.legalMoves:
  echo move

PGN Support

let game = readPgnFile("game.pgn")[0]
echo game.headers["White"]
echo game.headers["Black"]
echo game.result

Engine Communication (Client)

# Communicate with UCI engines like Stockfish
var engine = newUciEngineProcess("stockfish")
let result = engine.play(startPos, Limit(depth: 10))
echo "Best move: ", result.move.toSAN(startPos)

Engine Communication (Server)

# Implement a UCI chess engine
type MyEngine = ref object of Engine

method onGo(engine: MyEngine, params: GoParams): Move =
  let position = params.game.currentPosition
  # ... perform search, checking params.stopFlag[] periodically ...
  return bestMove

var server = newUciServer(
  name = "MyEngine 1.0",
  author = "Me",
  engine = MyEngine(),
)

server.uciLoop()

Requirements

  • Requires Nim >= 2.2.4
  • Ideally compile with -d:danger --panics:on --cc:clang --passC:"-flto" --passL:"-flto" for optimal performance

License

LGPL-3.0 with linking exception

Author

Jost Triller