diff --git a/src/engine/board.c b/src/engine/board.c index 81b50bf..b21a94e 100644 --- a/src/engine/board.c +++ b/src/engine/board.c @@ -7,6 +7,20 @@ #define QUEEN_MAXMOVES 27 #define KING_MAXMOVES 10 // Castling has to be taken into account +#define WHITE_PAWN "\u2659" +#define WHITE_KNIGHT "\u2658" +#define WHITE_BISHOP "\u2657" +#define WHITE_ROOK "\u2656" +#define WHITE_QUEEN "\u2655" +#define WHITE_KING "\u2654" + +#define BLACK_PAWN "\u265F" +#define BLACK_KNIGHT "\u265E" +#define BLACK_BISHOP "\u265D" +#define BLACK_ROOK "\u265C" +#define BLACK_QUEEN "\u265B" +#define BLACK_KING "\u265A" + PieceColors piece_getColor(const Pieces piece) { return Black & piece; } Piece piece_getColorlessPiece(const Pieces piece) { return piece_getColor(piece) ^ piece; @@ -165,3 +179,44 @@ bool board_movePiece(Board board, const Coordinates from, b[from_index].piece = -1; return true; } + +void board_print(const Board board) { + printf("┌───┬───┬───┬───┬───┬───┬───┬───┐\n"); + uint i = 0; + while (i < 64) { + PieceColors piece_color = piece_getColor(board.squares[i].piece); + Pieces bare_piece = piece_getColorlessPiece(board.squares[i].piece); + char *unicode; + switch (bare_piece) { + case Pawn: + unicode = piece_color == White ? WHITE_PAWN : BLACK_PAWN; + break; + case Knight: + unicode = piece_color == White ? WHITE_KNIGHT : BLACK_KNIGHT; + break; + case Bishop: + unicode = piece_color == White ? WHITE_BISHOP : BLACK_BISHOP; + break; + case Rook: + unicode = piece_color == White ? WHITE_ROOK : BLACK_ROOK; + break; + case Queen: + unicode = piece_color == White ? WHITE_QUEEN : BLACK_QUEEN; + break; + case King: + unicode = piece_color == White ? WHITE_KING : BLACK_KING; + break; + } + + printf("│ %s ", board.squares[i].piece == -1 ? " " : unicode); + if ((i + 1) % 8 == 0) { + const uint row = ((64 - i + 1) / 8) % 8 + 1; + printf("│ %d\n", row); + if (row != 1) + printf("├───┼───┼───┼───┼───┼───┼───┼───┤\n"); + } + i++; + } + printf("└───┴───┴───┴───┴───┴───┴───┴───┘\n"); + printf(" A B C D E F G H"); +} diff --git a/src/engine/board.h b/src/engine/board.h index c9b04bb..5c6f99e 100644 --- a/src/engine/board.h +++ b/src/engine/board.h @@ -28,5 +28,6 @@ Piece piece_getColorlessPiece(const Pieces piece); bool board_movePiece(Board board, const Coordinates from, const Coordinates to); int board_getIndex(const Coordinates coords); Coordinates *piece_getMoves(const Pieces piece, const Coordinates piece_coords); +void board_print(const Board board); #endif // !__BOARD_HEADER diff --git a/src/engine/fen.h b/src/engine/fen.h index beb3bb7..635f9cd 100644 --- a/src/engine/fen.h +++ b/src/engine/fen.h @@ -2,7 +2,19 @@ #define __FEN_HEADER #include "board.h" -typedef char FEN[75]; +/* + ; + + represents the positions of pieces on the board. + indicates which player's turn it is. + specifies castling availability. + indicates the square to which an en passant capture is +possible. + is the number of halfmoves since the last capture or +pawn advance. + is the number of the full move. +*/ +typedef char FEN[89]; void fen_fromBoard(const Board board, FEN fen); void fen_toBoard(const FEN fen, Board *board); diff --git a/src/main.c b/src/main.c index fdd9681..030f3a2 100644 --- a/src/main.c +++ b/src/main.c @@ -1,21 +1,24 @@ #include "engine.h" +#include void printFEN(void *value) { printf("%s", (char *)value); } void printString(void *value) { printf("%s", *(char **)value); } int main() { + setlocale(LC_ALL, ""); Board board; FEN fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"; fen_toBoard(fen, &board); - board.history = linkedList_init(&fen); - Coordinates *coords = - piece_getMoves(board.squares[3].piece, board.squares[3].coords); - char a[] = "hello"; - linkedList_append(board.history, &a); - printf("%d\n", linkedList_length(board.history)); - linkedList_print(board.history, printFEN); - free(coords); - linkedList_removeAll(board.history); + board_print(board); + // board.history = linkedList_init(&fen); + // Coordinates *coords = + // piece_getMoves(board.squares[3].piece, board.squares[3].coords); + // char a[] = "hello"; + // linkedList_append(board.history, &a); + // printf("%d\n", linkedList_length(board.history)); + // linkedList_print(board.history, printFEN); + // free(coords); + // linkedList_removeAll(board.history); // char *a = "hello"; // LinkedList *head = linkedList_init(&a); // char *b = "world";