aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/board.cpp24
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) {