From 0aa622c9b528e57df3c23ca84daa27797399e0f5 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 25 Jul 2026 18:20:04 +0200 Subject: fixing code --- src/board.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/board.cpp b/src/board.cpp index 52f6c52..e8c9fc8 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -1,6 +1,7 @@ #include "board.hpp" #include #include +#include #include #include @@ -10,7 +11,7 @@ bool BLACK = false; const char toChar(pieceType type) { switch (type) { case NONE: - return '-'; + return '.'; case PAWN: return 'P'; case KNIGHT: @@ -36,15 +37,18 @@ Piece createPiece(pieceType type, bool color, bool moved) { return piece; }; void printBoard(board *b) { - std::println(" a b c d e f g h"); - std::println(" +-----------------+"); + std::string line = " +-----------------+\n"; + std::string letter = " a b c d e f g h\n"; + + std::cout << letter; + std::cout << line; for (int rank = 0; rank < 8; rank++) { std::printf("%d |", 8 - rank); for (int file = 0; file < 8; file++) { Piece piece = b->pieces[rank * 8 + file]; - char symbol = piece.type == NONE ? '.' : toChar(piece.type); - if (piece.type != NONE && piece.color == BLACK) { + char symbol = toChar(piece.type); + if (piece.color == BLACK) { symbol = std::tolower(static_cast(symbol)); } std::printf(" %c", symbol); @@ -52,10 +56,12 @@ void printBoard(board *b) { std::printf(" | %d\n", 8 - rank); } - std::println(" +-----------------+"); - std::println(" a b c d e f g h"); - std::println("\nTurn: {}", b->turn == WHITE ? "White" : "Black"); - std::println("Castling: {}", b->castle.empty() ? "-" : b->castle); + std::cout << letter; + std::cout << line; + + std::println(); + std::println("Turn: {}", b->turn == WHITE ? "White" : "Black"); + std::println("Castling: {}", b->castle); } void setBoardFen(std::string fen, board *b) { -- cgit v1.2.3