Chess 0.0.1
A library written in c
|
Defines the chess square type and related utility functions for representing and manipulating chess squares. More...
#include <chess/color.h>
#include <chess/file.h>
#include <chess/macros.h>
#include <chess/rank.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
Typedefs | |
typedef struct ChessPosition | ChessPosition |
Forward declaration of ChessPosition. | |
Enumerations | |
enum | ChessSquare : uint8_t { CHESS_SQUARE_A1 = CHESS_FILE_A | CHESS_RANK_1 << 4U , CHESS_SQUARE_B1 = CHESS_FILE_B | CHESS_RANK_1 << 4U , CHESS_SQUARE_C1 = CHESS_FILE_C | CHESS_RANK_1 << 4U , CHESS_SQUARE_D1 = CHESS_FILE_D | CHESS_RANK_1 << 4U , CHESS_SQUARE_E1 = CHESS_FILE_E | CHESS_RANK_1 << 4U , CHESS_SQUARE_F1 = CHESS_FILE_F | CHESS_RANK_1 << 4U , CHESS_SQUARE_G1 = CHESS_FILE_G | CHESS_RANK_1 << 4U , CHESS_SQUARE_H1 = CHESS_FILE_H | CHESS_RANK_1 << 4U , CHESS_SQUARE_A2 = CHESS_FILE_A | CHESS_RANK_2 << 4U , CHESS_SQUARE_B2 = CHESS_FILE_B | CHESS_RANK_2 << 4U , CHESS_SQUARE_C2 = CHESS_FILE_C | CHESS_RANK_2 << 4U , CHESS_SQUARE_D2 = CHESS_FILE_D | CHESS_RANK_2 << 4U , CHESS_SQUARE_E2 = CHESS_FILE_E | CHESS_RANK_2 << 4U , CHESS_SQUARE_F2 = CHESS_FILE_F | CHESS_RANK_2 << 4U , CHESS_SQUARE_G2 = CHESS_FILE_G | CHESS_RANK_2 << 4U , CHESS_SQUARE_H2 = CHESS_FILE_H | CHESS_RANK_2 << 4U , CHESS_SQUARE_A3 = CHESS_FILE_A | CHESS_RANK_3 << 4U , CHESS_SQUARE_B3 = CHESS_FILE_B | CHESS_RANK_3 << 4U , CHESS_SQUARE_C3 = CHESS_FILE_C | CHESS_RANK_3 << 4U , CHESS_SQUARE_D3 = CHESS_FILE_D | CHESS_RANK_3 << 4U , CHESS_SQUARE_E3 = CHESS_FILE_E | CHESS_RANK_3 << 4U , CHESS_SQUARE_F3 = CHESS_FILE_F | CHESS_RANK_3 << 4U , CHESS_SQUARE_G3 = CHESS_FILE_G | CHESS_RANK_3 << 4U , CHESS_SQUARE_H3 = CHESS_FILE_H | CHESS_RANK_3 << 4U , CHESS_SQUARE_A4 = CHESS_FILE_A | CHESS_RANK_4 << 4U , CHESS_SQUARE_B4 = CHESS_FILE_B | CHESS_RANK_4 << 4U , CHESS_SQUARE_C4 = CHESS_FILE_C | CHESS_RANK_4 << 4U , CHESS_SQUARE_D4 = CHESS_FILE_D | CHESS_RANK_4 << 4U , CHESS_SQUARE_E4 = CHESS_FILE_E | CHESS_RANK_4 << 4U , CHESS_SQUARE_F4 = CHESS_FILE_F | CHESS_RANK_4 << 4U , CHESS_SQUARE_G4 = CHESS_FILE_G | CHESS_RANK_4 << 4U , CHESS_SQUARE_H4 = CHESS_FILE_H | CHESS_RANK_4 << 4U , CHESS_SQUARE_A5 = CHESS_FILE_A | CHESS_RANK_5 << 4U , CHESS_SQUARE_B5 = CHESS_FILE_B | CHESS_RANK_5 << 4U , CHESS_SQUARE_C5 = CHESS_FILE_C | CHESS_RANK_5 << 4U , CHESS_SQUARE_D5 = CHESS_FILE_D | CHESS_RANK_5 << 4U , CHESS_SQUARE_E5 = CHESS_FILE_E | CHESS_RANK_5 << 4U , CHESS_SQUARE_F5 = CHESS_FILE_F | CHESS_RANK_5 << 4U , CHESS_SQUARE_G5 = CHESS_FILE_G | CHESS_RANK_5 << 4U , CHESS_SQUARE_H5 = CHESS_FILE_H | CHESS_RANK_5 << 4U , CHESS_SQUARE_A6 = CHESS_FILE_A | CHESS_RANK_6 << 4U , CHESS_SQUARE_B6 = CHESS_FILE_B | CHESS_RANK_6 << 4U , CHESS_SQUARE_C6 = CHESS_FILE_C | CHESS_RANK_6 << 4U , CHESS_SQUARE_D6 = CHESS_FILE_D | CHESS_RANK_6 << 4U , CHESS_SQUARE_E6 = CHESS_FILE_E | CHESS_RANK_6 << 4U , CHESS_SQUARE_F6 = CHESS_FILE_F | CHESS_RANK_6 << 4U , CHESS_SQUARE_G6 = CHESS_FILE_G | CHESS_RANK_6 << 4U , CHESS_SQUARE_H6 = CHESS_FILE_H | CHESS_RANK_6 << 4U , CHESS_SQUARE_A7 = CHESS_FILE_A | CHESS_RANK_7 << 4U , CHESS_SQUARE_B7 = CHESS_FILE_B | CHESS_RANK_7 << 4U , CHESS_SQUARE_C7 = CHESS_FILE_C | CHESS_RANK_7 << 4U , CHESS_SQUARE_D7 = CHESS_FILE_D | CHESS_RANK_7 << 4U , CHESS_SQUARE_E7 = CHESS_FILE_E | CHESS_RANK_7 << 4U , CHESS_SQUARE_F7 = CHESS_FILE_F | CHESS_RANK_7 << 4U , CHESS_SQUARE_G7 = CHESS_FILE_G | CHESS_RANK_7 << 4U , CHESS_SQUARE_H7 = CHESS_FILE_H | CHESS_RANK_7 << 4U , CHESS_SQUARE_A8 = CHESS_FILE_A | CHESS_RANK_8 << 4U , CHESS_SQUARE_B8 = CHESS_FILE_B | CHESS_RANK_8 << 4U , CHESS_SQUARE_C8 = CHESS_FILE_C | CHESS_RANK_8 << 4U , CHESS_SQUARE_D8 = CHESS_FILE_D | CHESS_RANK_8 << 4U , CHESS_SQUARE_E8 = CHESS_FILE_E | CHESS_RANK_8 << 4U , CHESS_SQUARE_F8 = CHESS_FILE_F | CHESS_RANK_8 << 4U , CHESS_SQUARE_G8 = CHESS_FILE_G | CHESS_RANK_8 << 4U , CHESS_SQUARE_H8 = CHESS_FILE_H | CHESS_RANK_8 << 4U , CHESS_SQUARE_NONE = CHESS_FILE_NONE | CHESS_RANK_NONE << 4U } |
Represents the squares on a chess board, from A1 to H8. More... | |
Functions | |
void | chess_square_debug (ChessSquare square) |
Prints a debug representation of the given square. | |
bool | chess_square_is_valid (ChessSquare square) |
Checks if the given square is valid (A1-H8). | |
ChessSquare | chess_square_new (ChessFile file, ChessRank rank) |
Creates a new square from a file and rank. | |
ChessFile | chess_square_file (ChessSquare square) |
Gets the file of the given square. | |
ChessRank | chess_square_rank (ChessSquare square) |
Gets the rank of the given square. | |
ChessColor | chess_square_color (ChessSquare square) |
Gets the color of the given square. | |
size_t | chess_square_from_algebraic (ChessSquare *square, const char *string) |
Parses a square from algebraic notation (e.g., "a1", "b1", ..., "h8"). | |
size_t | chess_square_to_algebraic (ChessSquare square, char *string, size_t string_size) |
Converts a square to algebraic notation (e.g., "a1", "b1", ..., "h8"). | |
bool | chess_square_is_attacked (const ChessPosition *position, ChessSquare square, ChessColor color) |
Checks if the given square is attacked by a given color in a position. | |
Defines the chess square type and related utility functions for representing and manipulating chess squares.
enum ChessSquare : uint8_t |
Represents the squares on a chess board, from A1 to H8.
ChessColor chess_square_color | ( | ChessSquare | square | ) |
Gets the color of the given square.
square | The square. |
void chess_square_debug | ( | ChessSquare | square | ) |
Prints a debug representation of the given square.
[in] | square | The square to print. |
ChessFile chess_square_file | ( | ChessSquare | square | ) |
Gets the file of the given square.
square | The square. |
size_t chess_square_from_algebraic | ( | ChessSquare * | square, |
const char * | string | ||
) |
Parses a square from algebraic notation (e.g., "a1", "b1", ..., "h8").
[out] | square | Pointer to store the parsed square. |
[in] | string | The string containing the algebraic notation. |
bool chess_square_is_attacked | ( | const ChessPosition * | position, |
ChessSquare | square, | ||
ChessColor | color | ||
) |
Checks if the given square is attacked by a given color in a position.
[in] | position | The chess position. |
[in] | square | The square to check. |
[in] | color | The color to check for attacks. |
bool chess_square_is_valid | ( | ChessSquare | square | ) |
Checks if the given square is valid (A1-H8).
[in] | square | The square to check. |
ChessSquare chess_square_new | ( | ChessFile | file, |
ChessRank | rank | ||
) |
Creates a new square from a file and rank.
[in] | file | The file of the square. |
[in] | rank | The rank of the square. |
ChessRank chess_square_rank | ( | ChessSquare | square | ) |
Gets the rank of the given square.
square | The square. |
size_t chess_square_to_algebraic | ( | ChessSquare | square, |
char * | string, | ||
size_t | string_size | ||
) |
Converts a square to algebraic notation (e.g., "a1", "b1", ..., "h8").
[in] | square | The square to convert. |
[out] | string | The buffer to store the algebraic notation. |
[in] | string_size | The size of the output buffer. |