aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/board.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/board.cpp b/src/board.cpp
index 92704c3..1d647a4 100644
--- a/src/board.cpp
+++ b/src/board.cpp
@@ -1,7 +1,6 @@
#include "board.hpp"
#include <cctype>
#include <cstdio>
-#include <iostream>
#include <print>
#include <string>
@@ -37,16 +36,26 @@ Piece createPiece(pieceType type, bool color, bool moved) {
return piece;
};
void printBoard(board *b) {
- for (int i = 0; i < 64; i++) {
- Piece currentPiece = b->pieces[i];
- std::printf("%c%d%d ", toChar(currentPiece.type), currentPiece.moved,
- currentPiece.color);
- if (i % 8 == 7 && i != 0) {
- std::printf("\n");
+ std::println(" a b c d e f g h");
+ std::println(" +-----------------+");
+
+ 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) {
+ symbol = std::tolower(static_cast<unsigned char>(symbol));
+ }
+ std::printf(" %c", symbol);
}
+ std::printf(" | %d\n", 8 - rank);
}
- std::printf("%d to play\n", b->turn);
- std::cout << "castle: " << b->castle << "\n";
+
+ 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);
}
void setBoardFen(std::string fen, board *b) {
// example fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1