aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/board.cpp62
-rw-r--r--src/board.hpp2
2 files changed, 34 insertions, 30 deletions
diff --git a/src/board.cpp b/src/board.cpp
index 0d884a6..d7fe87b 100644
--- a/src/board.cpp
+++ b/src/board.cpp
@@ -1,32 +1,30 @@
#include "board.hpp"
#include "bot.hpp"
#include <cassert>
-#include <cctype>
#include <cstdio>
#include <iostream>
#include <print>
#include <string>
-char toChar(PieceType type) {
+std::string toChar(PieceType type, bool white) {
switch (type) {
case NONE:
- return '.';
- case PAWN:
- return 'P';
- case KNIGHT:
- return 'N';
- case BISHOP:
- return 'B';
- case ROOK:
- return 'R';
- case QUEEN:
- return 'Q';
+ return " ";
case KING:
- return 'K';
+ return white ? "♚" : "♔";
+ case QUEEN:
+ return white ? "♛" : "♕";
+ case ROOK:
+ return white ? "♜" : "♖";
+ case BISHOP:
+ return white ? "♝" : "♗";
+ case KNIGHT:
+ return white ? "♞" : "♘";
+ case PAWN:
+ return white ? "♟" : "♙";
default:
- std::cout << "\n" << type << "\n";
- assert(false && "Unknown piece" && type);
- return '?';
+ assert(false && "Unknown piece");
+ return " ";
}
}
@@ -38,9 +36,17 @@ Piece createPiece(PieceType type, bool color, bool moved) {
return piece;
}
void printBoard(Board *b) {
- std::string line = " +-----------------+\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::string line = " +------------------------+\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";
+
+ // const char *lightSquare = "\033[48;5;145m";
+ // // const char *darkSquare = "\033[48;5;28m";
+ // const char *lightSquare = "\033[48;5;240m"; // Dark gray
+ // const char *darkSquare = "\033[48;5;22m"; // Forest green
+ const char *lightSquare = "\033[48;5;245m"; // Medium gray
+ const char *darkSquare = "\033[48;5;29m"; // Rich green
+ const char *reset = "\033[0m";
std::cout << (b->turn ? whiteLetters : blackLetters);
std::cout << line;
@@ -51,15 +57,14 @@ void printBoard(Board *b) {
for (int file = 0; file < 8; file++) {
Piece piece = b->pieces[rank * 8 + file];
- char symbol = toChar(piece.type);
+ std::string symbol = toChar(piece.type, piece.color);
- if (!piece.color)
- symbol = std::tolower(static_cast<unsigned char>(symbol));
+ const char *bg = ((rank + file) % 2 == 0) ? lightSquare : darkSquare;
- std::printf(" %c", symbol);
+ std::cout << bg << " " << symbol << " " << reset;
}
- std::printf(" | %d\n", 8 - rank);
+ std::printf("| %d\n", 8 - rank);
}
} else {
for (int rank = 7; rank >= 0; rank--) {
@@ -67,12 +72,11 @@ void printBoard(Board *b) {
for (int file = 7; file >= 0; file--) {
Piece piece = b->pieces[rank * 8 + file];
- char symbol = toChar(piece.type);
+ std::string symbol = toChar(piece.type, piece.color);
- if (!piece.color)
- symbol = std::tolower(static_cast<unsigned char>(symbol));
+ const char *bg = ((rank + file) % 2 == 0) ? lightSquare : darkSquare;
- std::printf(" %c", symbol);
+ std::cout << bg << " " << symbol << " " << reset;
}
std::printf(" | %d\n", 8 - rank);
diff --git a/src/board.hpp b/src/board.hpp
index 44d32ee..e782be5 100644
--- a/src/board.hpp
+++ b/src/board.hpp
@@ -20,7 +20,7 @@ enum GameState {
STALEMATE,
DRAW,
};
-char toChar(PieceType type);
+std::string toChar(PieceType type, bool white);
struct Piece {
bool color;