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

Defines the chess rank type and related utility functions for representing and manipulating chess ranks. More...

#include <chess/macros.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Enumerations

enum  ChessRank : int8_t {
  CHESS_RANK_1 = 0 ,
  CHESS_RANK_2 = 1 ,
  CHESS_RANK_3 = 2 ,
  CHESS_RANK_4 = 3 ,
  CHESS_RANK_5 = 4 ,
  CHESS_RANK_6 = 5 ,
  CHESS_RANK_7 = 6 ,
  CHESS_RANK_8 = 7 ,
  CHESS_RANK_NONE = 8
}
 Represents the ranks (rows) on a chess board, from 1 to 8. More...
 

Functions

void chess_rank_debug (ChessRank rank)
 Prints a debug representation of the given rank.
 
bool chess_rank_is_valid (ChessRank rank)
 Checks if the given rank is valid (1-8).
 
size_t chess_rank_from_algebraic (ChessRank *rank, const char *string)
 Parses a rank from algebraic notation (e.g., "1", "2", ..., "8").
 
size_t chess_rank_to_algebraic (ChessRank rank, char *string, size_t string_size)
 Converts a rank to algebraic notation (e.g., "1", "2", ..., "8").
 

Detailed Description

Defines the chess rank type and related utility functions for representing and manipulating chess ranks.

Author
Tarek Saeed
Date
2025-06-14

Enumeration Type Documentation

◆ ChessRank

enum ChessRank : int8_t

Represents the ranks (rows) on a chess board, from 1 to 8.

Enumerator
CHESS_RANK_1 

Rank 1

CHESS_RANK_2 

Rank 2

CHESS_RANK_3 

Rank 3

CHESS_RANK_4 

Rank 4

CHESS_RANK_5 

Rank 5

CHESS_RANK_6 

Rank 6

CHESS_RANK_7 

Rank 7

CHESS_RANK_8 

Rank 8

CHESS_RANK_NONE 

No rank

Function Documentation

◆ chess_rank_debug()

void chess_rank_debug ( ChessRank  rank)

Prints a debug representation of the given rank.

Parameters
[in]rankThe rank to print.

◆ chess_rank_from_algebraic()

size_t chess_rank_from_algebraic ( ChessRank rank,
const char *  string 
)

Parses a rank from algebraic notation (e.g., "1", "2", ..., "8").

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

◆ chess_rank_is_valid()

bool chess_rank_is_valid ( ChessRank  rank)

Checks if the given rank is valid (1-8).

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

◆ chess_rank_to_algebraic()

size_t chess_rank_to_algebraic ( ChessRank  rank,
char *  string,
size_t  string_size 
)

Converts a rank to algebraic notation (e.g., "1", "2", ..., "8").

Parameters
[in]rankThe rank to convert.
[out]stringThe buffer to store the algebraic notation.
[in]string_sizeThe size of the output buffer.
Returns
The number of characters written.