Chess 0.0.1
A library written in c
Loading...
Searching...
No Matches
Chess

Build Status GitHub Stars Github License

A portable C library for representing and manipulating chess positions, and generating legal moves. This library provides a clean API for chess engines, GUIs, and tools.

Features

  • Full representation of chess positions, moves, and pieces
  • Move generation and validation
  • FEN parsing and generation
  • Algebraic notation parsing and formatting
  • Castling, en passant, promotion, and all standard chess rules
  • No dependencies required, cmocka is optionally required for testing

Usage

Include the main header in your project:

#include <chess.h>

Example

Creating a new position and generating moves

#include <chess.h>
#include <stdio.h>
int main(void) {
ChessMoves moves = chess_moves_generate(&position);
printf("There is %zu legal moves:\n", moves.count);
for (size_t i = 0; i < moves.count; i++) {
char buffer[16];
chess_move_to_algebraic(&position, moves.moves[i], buffer, sizeof(buffer));
printf("%s\n", buffer);
}
chess_position_drop(&position);
return 0;
}
size_t chess_move_to_algebraic(const ChessPosition *position, ChessMove move, char *string, size_t string_size)
Converts a move to algebraic notation.
void chess_position_drop(ChessPosition *position)
Releases resources held by the given position.
ChessPosition chess_position_new(void)
Creates a new position initialized to the standard starting position.
Definition moves.h:15
Represents the position in a chess game.
Definition position.h:30

Building

This library is written in standard C and should compile with any modern C compiler. It requires at least C11 support. To build using cmake:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build

API Overview

See the include/chess/ headers for full API documentation.

License

MIT License. See LICENSE for details.