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

Defines the chess piece type and related utility functions for representing and manipulating chess pieces. More...

#include <chess/color.h>
#include <chess/macros.h>
#include <chess/piece_type.h>
#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Enumerations

enum  ChessPiece : uint8_t {
  CHESS_PIECE_WHITE_PAWN = CHESS_COLOR_WHITE << 3U | CHESS_PIECE_TYPE_PAWN ,
  CHESS_PIECE_WHITE_KNIGHT = CHESS_COLOR_WHITE << 3U | CHESS_PIECE_TYPE_KNIGHT ,
  CHESS_PIECE_WHITE_BISHOP = CHESS_COLOR_WHITE << 3U | CHESS_PIECE_TYPE_BISHOP ,
  CHESS_PIECE_WHITE_ROOK = CHESS_COLOR_WHITE << 3U | CHESS_PIECE_TYPE_ROOK ,
  CHESS_PIECE_WHITE_QUEEN = CHESS_COLOR_WHITE << 3U | CHESS_PIECE_TYPE_QUEEN ,
  CHESS_PIECE_WHITE_KING = CHESS_COLOR_WHITE << 3U | CHESS_PIECE_TYPE_KING ,
  CHESS_PIECE_BLACK_PAWN = CHESS_COLOR_BLACK << 3U | CHESS_PIECE_TYPE_PAWN ,
  CHESS_PIECE_BLACK_KNIGHT = CHESS_COLOR_BLACK << 3U | CHESS_PIECE_TYPE_KNIGHT ,
  CHESS_PIECE_BLACK_BISHOP = CHESS_COLOR_BLACK << 3U | CHESS_PIECE_TYPE_BISHOP ,
  CHESS_PIECE_BLACK_ROOK = CHESS_COLOR_BLACK << 3U | CHESS_PIECE_TYPE_ROOK ,
  CHESS_PIECE_BLACK_QUEEN = CHESS_COLOR_BLACK << 3U | CHESS_PIECE_TYPE_QUEEN ,
  CHESS_PIECE_BLACK_KING = CHESS_COLOR_BLACK << 3U | CHESS_PIECE_TYPE_KING ,
  CHESS_PIECE_NONE = CHESS_COLOR_NONE << 3U | CHESS_PIECE_TYPE_NONE
}
 

Functions

void chess_piece_debug (ChessPiece piece)
 Prints a debug representation of the given piece.
 
bool chess_piece_is_valid (ChessPiece piece)
 Checks if the given piece is valid.
 
ChessPiece chess_piece_new (ChessColor color, ChessPieceType type)
 Creates a piece from a color and piece type.
 
ChessColor chess_piece_color (ChessPiece piece)
 Gets the color of the given piece.
 
ChessPieceType chess_piece_type (ChessPiece piece)
 Gets the type of the given piece.
 
size_t chess_piece_from_algebraic (ChessPiece *piece, const char *string)
 Parses a piece from algebraic notation (e.g., "P", "N", ..., "K", "p", "n", ..., "k").
 
size_t chess_piece_to_algebraic (ChessPiece piece, char *string, size_t string_size)
 Converts a piece to algebraic notation (e.g., "P", "N", ..., "K", "p", "n", ..., "k").
 

Detailed Description

Defines the chess piece type and related utility functions for representing and manipulating chess pieces.

Author
Tarek Saeed
Date
2025-06-14

Enumeration Type Documentation

◆ ChessPiece

enum ChessPiece : uint8_t
Enumerator
CHESS_PIECE_WHITE_PAWN 

White pawn piece

CHESS_PIECE_WHITE_KNIGHT 

White knight piece

CHESS_PIECE_WHITE_BISHOP 

White bishop piece

CHESS_PIECE_WHITE_ROOK 

White rook piece

CHESS_PIECE_WHITE_QUEEN 

White queen piece

CHESS_PIECE_WHITE_KING 

White king piece

CHESS_PIECE_BLACK_PAWN 

Black pawn piece

CHESS_PIECE_BLACK_KNIGHT 

Black knight piece

CHESS_PIECE_BLACK_BISHOP 

Black bishop piece

CHESS_PIECE_BLACK_ROOK 

Black rook piece

CHESS_PIECE_BLACK_QUEEN 

Black queen piece

CHESS_PIECE_BLACK_KING 

Black king piece

CHESS_PIECE_NONE 

No piece

Function Documentation

◆ chess_piece_color()

ChessColor chess_piece_color ( ChessPiece  piece)

Gets the color of the given piece.

Parameters
[in]pieceThe piece.
Returns
The color of the piece.

◆ chess_piece_debug()

void chess_piece_debug ( ChessPiece  piece)

Prints a debug representation of the given piece.

Parameters
[in]pieceThe piece to print.

◆ chess_piece_from_algebraic()

size_t chess_piece_from_algebraic ( ChessPiece piece,
const char *  string 
)

Parses a piece from algebraic notation (e.g., "P", "N", ..., "K", "p", "n", ..., "k").

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

◆ chess_piece_is_valid()

bool chess_piece_is_valid ( ChessPiece  piece)

Checks if the given piece is valid.

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

◆ chess_piece_new()

ChessPiece chess_piece_new ( ChessColor  color,
ChessPieceType  type 
)

Creates a piece from a color and piece type.

Parameters
[in]colorThe color of the piece.
[in]typeThe type of the piece.
Returns
The created piece.

◆ chess_piece_to_algebraic()

size_t chess_piece_to_algebraic ( ChessPiece  piece,
char *  string,
size_t  string_size 
)

Converts a piece to algebraic notation (e.g., "P", "N", ..., "K", "p", "n", ..., "k").

Parameters
[in]pieceThe piece 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_piece_type()

ChessPieceType chess_piece_type ( ChessPiece  piece)

Gets the type of the given piece.

Parameters
[in]pieceThe piece.
Returns
The type of the piece.