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

Defines the chess move type and related utility functions for representing and manipulating chess moves. More...

#include <chess/castling_rights.h>
#include <chess/piece.h>
#include <chess/piece_type.h>
#include <chess/position.h>
#include <chess/square.h>
#include <stdbool.h>
#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  ChessMove
 Represents a move in a chess game. More...
 

Typedefs

typedef struct ChessMove ChessMove
 

Functions

void chess_move_debug (ChessMove move)
 Prints a debug representation of the given move.
 
bool chess_move_is_valid (ChessMove move)
 Checks if the given move is valid.
 
ChessMove chess_move_new (const ChessPosition *position, ChessSquare from, ChessSquare to, ChessPieceType promotion_type)
 Creates a new move for the given position.
 
size_t chess_move_from_algebraic (const ChessPosition *position, ChessMove *move, const char *string)
 Parses a move from algebraic notation.
 
size_t chess_move_to_algebraic (const ChessPosition *position, ChessMove move, char *string, size_t string_size)
 Converts a move to algebraic notation.
 
bool chess_move_is_legal (const ChessPosition *position, ChessMove move)
 Checks if the given move is legal in the given position.
 
bool chess_move_is_promotion (const ChessPosition *position, ChessMove move)
 Checks if the given move is a promotion.
 
bool chess_move_is_en_passant (const ChessPosition *position, ChessMove move)
 Checks if the given move is an en passant capture.
 
bool chess_move_is_capture (const ChessPosition *position, ChessMove move)
 Checks if the given move is a capture.
 
bool chess_move_is_kingside_castling (const ChessPosition *position, ChessMove move)
 Checks if the given move is kingside castling.
 
bool chess_move_is_queenside_castling (const ChessPosition *position, ChessMove move)
 Checks if the given move is queenside castling.
 
bool chess_move_do (ChessPosition *position, ChessMove move)
 Does the given move on the given position if legal.
 
bool chess_move_undo (ChessPosition *position, ChessMove move)
 Undoes the given move on the given position if legal.
 

Detailed Description

Defines the chess move type and related utility functions for representing and manipulating chess moves.

Author
Tarek Saeed
Date
2025-06-14

Function Documentation

◆ chess_move_debug()

void chess_move_debug ( ChessMove  move)

Prints a debug representation of the given move.

Parameters
[in]moveThe move to print.

◆ chess_move_do()

bool chess_move_do ( ChessPosition position,
ChessMove  move 
)

Does the given move on the given position if legal.

Parameters
[in,out]positionPointer to the position to update.
[in]moveThe move to make.
Returns
true if the move was done, false otherwise.

◆ chess_move_from_algebraic()

size_t chess_move_from_algebraic ( const ChessPosition position,
ChessMove move,
const char *  string 
)

Parses a move from algebraic notation.

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

◆ chess_move_is_capture()

bool chess_move_is_capture ( const ChessPosition position,
ChessMove  move 
)

Checks if the given move is a capture.

Parameters
[in]positionPointer to the position, the move is for.
[in]moveThe move to check.
Returns
true if the move is a capture, false otherwise.

◆ chess_move_is_en_passant()

bool chess_move_is_en_passant ( const ChessPosition position,
ChessMove  move 
)

Checks if the given move is an en passant capture.

Parameters
[in]positionPointer to the position, the move is for.
[in]moveThe move to check.
Returns
true if the move is an en passant capture, false otherwise.

◆ chess_move_is_kingside_castling()

bool chess_move_is_kingside_castling ( const ChessPosition position,
ChessMove  move 
)

Checks if the given move is kingside castling.

Parameters
[in]positionPointer to the position, the move is for.
[in]moveThe move to check.
Returns
true if the move is kingside castling, false otherwise.

◆ chess_move_is_legal()

bool chess_move_is_legal ( const ChessPosition position,
ChessMove  move 
)

Checks if the given move is legal in the given position.

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

◆ chess_move_is_promotion()

bool chess_move_is_promotion ( const ChessPosition position,
ChessMove  move 
)

Checks if the given move is a promotion.

Parameters
[in]positionPointer to the position, the move is for.
[in]moveThe move to check.
Returns
true if the move is a promotion, false otherwise.

◆ chess_move_is_queenside_castling()

bool chess_move_is_queenside_castling ( const ChessPosition position,
ChessMove  move 
)

Checks if the given move is queenside castling.

Parameters
[in]positionPointer to the position, the move is for.
[in]moveThe move to check.
Returns
true if the move is queenside castling, false otherwise.

◆ chess_move_is_valid()

bool chess_move_is_valid ( ChessMove  move)

Checks if the given move is valid.

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

◆ chess_move_new()

ChessMove chess_move_new ( const ChessPosition position,
ChessSquare  from,
ChessSquare  to,
ChessPieceType  promotion_type 
)

Creates a new move for the given position.

Parameters
[in]positionPointer to the position.
[in]fromThe source square.
[in]toThe destination square.
[in]promotion_typeThe type of piece to promote to, or CHESS_PIECE_TYPE_NONE if not a promotion.
Returns
The created move.

◆ chess_move_to_algebraic()

size_t chess_move_to_algebraic ( const ChessPosition position,
ChessMove  move,
char *  string,
size_t  string_size 
)

Converts a move to algebraic notation.

Parameters
[in]positionPointer to the position, the move is for.
[in]moveThe move to convert.
[out]stringThe buffer to store the algebraic notation.
[in]string_sizeThe size of the output buffer.
Returns
The number of characters written.

◆ chess_move_undo()

bool chess_move_undo ( ChessPosition position,
ChessMove  move 
)

Undoes the given move on the given position if legal.

Parameters
[in,out]positionPointer to the position to update.
[in]moveThe move to undo.
Returns
true if the move was undone, false otherwise.