No description
Find a file
2025-12-26 03:33:26 +01:00
.github/workflows Maybe fixed workflow 2025-12-24 14:17:31 +01:00
src Fixed engine notatin issue 2025-12-26 03:33:26 +01:00
tests better tests 2025-08-23 00:51:29 +02:00
.gitignore Updated docs 2025-08-10 17:49:55 +02:00
LICENSE Create LICENSE 2025-08-09 22:48:47 +02:00
nimchess.nimble Fixed engine notatin issue 2025-12-26 03:33:26 +01:00
README.md Fixed engine notatin issue 2025-12-26 03:33:26 +01:00

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.2.5"

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

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

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

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