diff options
Diffstat (limited to 'src/board.cpp')
| -rw-r--r-- | src/board.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/board.cpp b/src/board.cpp index e8fa787..cbafcc6 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -35,41 +35,48 @@ Piece createPiece(pieceType type, bool color, bool moved) { }; void printBoard(board *b) { std::string line = " +-----------------+\n"; - std::string letter = " a b c d e f g h\n"; + std::string whiteLetters = " a b c d e f g h\n"; + std::string blackLetters = " h g f e d c b a\n"; - std::cout << letter; + std::cout << (b->turn ? whiteLetters : blackLetters); std::cout << line; if (b->turn) { 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 = toChar(piece.type); - if (piece.color == false) { + + if (!piece.color) symbol = std::tolower(static_cast<unsigned char>(symbol)); - } + std::printf(" %c", symbol); } + std::printf(" | %d\n", 8 - rank); } } else { for (int rank = 7; rank >= 0; rank--) { std::printf("%d |", 8 - rank); + for (int file = 7; file >= 0; file--) { Piece piece = b->pieces[rank * 8 + file]; char symbol = toChar(piece.type); - if (piece.color == false) { + + if (!piece.color) symbol = std::tolower(static_cast<unsigned char>(symbol)); - } + std::printf(" %c", symbol); } + std::printf(" | %d\n", 8 - rank); } } std::cout << line; - std::cout << letter; + std::cout << (b->turn ? whiteLetters : blackLetters); std::println(); std::println("Turn: {}", b->turn ? "White" : "Black"); |
