diff options
| author | Adam <adammegarules1@gmail.com> | 2026-07-25 18:20:04 +0200 |
|---|---|---|
| committer | Adam <adammegarules1@gmail.com> | 2026-07-25 18:20:04 +0200 |
| commit | 0aa622c9b528e57df3c23ca84daa27797399e0f5 (patch) | |
| tree | 939e933cfd0b55cf689275501a22d7308823fb89 /src | |
| parent | 57411656ad351f4737dd958c0c5642d40fa435fa (diff) | |
fixing code
Diffstat (limited to 'src')
| -rw-r--r-- | src/board.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
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 <cctype> #include <cstdio> +#include <iostream> #include <print> #include <string> @@ -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<unsigned char>(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) { |
