Chess 0.0.1
A library written in c
Loading...
Searching...
No Matches
position.h File Reference

Defines the chess position type and related utility functions for representing and manipulating chess positions. More...

#include <chess/castling_rights.h>
#include <chess/color.h>
#include <chess/piece.h>
#include <chess/position_counter.h>
#include <chess/square.h>
#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  ChessPosition
 Represents the position in a chess game. More...
 

Typedefs

typedef struct ChessPosition ChessPosition
 

Functions

void chess_position_debug (const ChessPosition *position)
 Prints a debug representation of the given position.
 
bool chess_position_is_valid (const ChessPosition *position)
 Checks if the given position is valid.
 
ChessPosition chess_position_new (void)
 Creates a new position initialized to the standard starting position.
 
void chess_position_drop (ChessPosition *position)
 Releases resources held by the given position.
 
ChessPiece chess_position_piece_at_square (const ChessPosition *position, ChessSquare square)
 Gets the piece at the given square in the given position.
 
ChessColor chess_position_side_to_move (const ChessPosition *position)
 Gets the side to move in the given position.
 
size_t chess_position_from_fen (ChessPosition *position, const char *string)
 Parses a position from FEN notation (e.g., "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1").
 
size_t chess_position_to_fen (const ChessPosition *position, char *string, size_t string_size)
 Converts a position to FEN notation (e.g., "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1").
 
bool chess_position_is_check (const ChessPosition *position)
 Checks if the current side to move is in check.
 
bool chess_position_is_checkmate (const ChessPosition *position)
 Checks if the current side to move is in checkmate.
 
bool chess_position_is_stalemate (const ChessPosition *position)
 Checks if the current position is a stalemate.
 
bool chess_position_is_fifty_move_rule (const ChessPosition *position)
 Checks if the fifty-move rule applies to the current position.
 
bool chess_position_is_threefold_repetition (const ChessPosition *position)
 Checks if the current position has occurred three or more times (threefold repetition).
 
bool chess_position_is_insufficient_material (const ChessPosition *position)
 Checks if there is insufficient material to checkmate.
 
uint64_t chess_position_hash (const ChessPosition *position)
 Computes a hash value for the given position.
 

Detailed Description

Defines the chess position type and related utility functions for representing and manipulating chess positions.

Author
Tarek Saeed
Date
2025-06-14

Function Documentation

◆ chess_position_debug()

void chess_position_debug ( const ChessPosition position)

Prints a debug representation of the given position.

Parameters
[in]positionPointer to the position to print.

◆ chess_position_drop()

void chess_position_drop ( ChessPosition position)

Releases resources held by the given position.

Parameters
[in,out]positionPointer to the position to drop.

◆ chess_position_from_fen()

size_t chess_position_from_fen ( ChessPosition position,
const char *  string 
)

Parses a position from FEN notation (e.g., "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1").

Parameters
[out]positionPointer to store the parsed position.
[in]stringThe string containing the FEN notation.
Returns
The number of characters read if successful, 0 otherwise.

◆ chess_position_hash()

uint64_t chess_position_hash ( const ChessPosition position)

Computes a hash value for the given position.

Parameters
[in]positionPointer to the position.
Returns
The hash value of the position.

◆ chess_position_is_check()

bool chess_position_is_check ( const ChessPosition position)

Checks if the current side to move is in check.

Parameters
[in]positionPointer to the position.
Returns
true if the side to move is in check, false otherwise.

◆ chess_position_is_checkmate()

bool chess_position_is_checkmate ( const ChessPosition position)

Checks if the current side to move is in checkmate.

Parameters
[in]positionPointer to the position.
Returns
true if the side to move is in checkmate, false otherwise.

◆ chess_position_is_fifty_move_rule()

bool chess_position_is_fifty_move_rule ( const ChessPosition position)

Checks if the fifty-move rule applies to the current position.

Parameters
[in]positionPointer to the position.
Returns
true if the fifty-move rule applies, false otherwise.

◆ chess_position_is_insufficient_material()

bool chess_position_is_insufficient_material ( const ChessPosition position)

Checks if there is insufficient material to checkmate.

Parameters
[in]positionPointer to the position.
Returns
true if there is insufficient material, false otherwise.

◆ chess_position_is_stalemate()

bool chess_position_is_stalemate ( const ChessPosition position)

Checks if the current position is a stalemate.

Parameters
[in]positionPointer to the position.
Returns
true if the position is a stalemate, false otherwise.

◆ chess_position_is_threefold_repetition()

bool chess_position_is_threefold_repetition ( const ChessPosition position)

Checks if the current position has occurred three or more times (threefold repetition).

Parameters
[in]positionPointer to the position.
Returns
true if the position has occurred three or more times, false otherwise.

◆ chess_position_is_valid()

bool chess_position_is_valid ( const ChessPosition position)

Checks if the given position is valid.

Parameters
[in]positionPointer to the position to check.
Returns
true if the position is valid, false otherwise.

◆ chess_position_new()

ChessPosition chess_position_new ( void  )

Creates a new position initialized to the standard starting position.

Returns
The created position.

◆ chess_position_piece_at_square()

ChessPiece chess_position_piece_at_square ( const ChessPosition position,
ChessSquare  square 
)

Gets the piece at the given square in the given position.

Parameters
[in]positionPointer to the position.
[in]squareThe square.
Returns
The piece at the square.

◆ chess_position_side_to_move()

ChessColor chess_position_side_to_move ( const ChessPosition position)

Gets the side to move in the given position.

Parameters
[in]positionPointer to the position.
Returns
The color of the side to move.

◆ chess_position_to_fen()

size_t chess_position_to_fen ( const ChessPosition position,
char *  string,
size_t  string_size 
)

Converts a position to FEN notation (e.g., "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1").

Parameters
[in]positionPointer to the position to convert.
[out]stringThe buffer to store the FEN notation.
[in]string_sizeThe size of the output buffer.
Returns
The number of characters written.