aboutsummaryrefslogtreecommitdiff
path: root/src/board.cpp
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-07-28 19:03:20 +0200
committerAdam <adammegarules1@gmail.com>2026-07-28 19:03:20 +0200
commit40e242dc5450e1661c817b0bad8f9748388c278a (patch)
tree569053925f92516b1ee52a7e21ed9e1c75e1e3a0 /src/board.cpp
parentb2dbf812cb9e6da5f69a2b74c24c97d09fa7a684 (diff)
removing repl and unsuded featuares
Diffstat (limited to 'src/board.cpp')
-rw-r--r--src/board.cpp140
1 files changed, 0 insertions, 140 deletions
diff --git a/src/board.cpp b/src/board.cpp
index 41eef19..4daddfd 100644
--- a/src/board.cpp
+++ b/src/board.cpp
@@ -1,34 +1,8 @@
#include "board.hpp"
-#include "bot.hpp"
#include "zobrist.hpp"
#include <cassert>
-#include <cstdio>
-#include <iostream>
-#include <print>
#include <string>
-std::string toChar(PieceType type, bool white) {
- switch (type) {
- case NONE:
- return " ";
- case KING:
- return white ? "♚" : "♔";
- case QUEEN:
- return white ? "♛" : "♕";
- case ROOK:
- return white ? "♜" : "♖";
- case BISHOP:
- return white ? "♝" : "♗";
- case KNIGHT:
- return white ? "♞" : "♘";
- case PAWN:
- return white ? "♟" : "♙";
- default:
- assert(false && "Unknown piece");
- return " ";
- }
-}
-
Piece createPiece(PieceType type, bool color, bool moved) {
Piece piece;
piece.type = type;
@@ -36,121 +10,7 @@ Piece createPiece(PieceType type, bool color, bool moved) {
piece.moved = moved;
return piece;
}
-void printBoard(Game *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";
-
- const char *lightSquare = "\033[48;5;245m";
- const char *darkSquare = "\033[48;5;29m";
- const char *reset = "\033[0m";
-
- 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];
- std::string symbol = toChar(piece.type, piece.color);
-
- const char *bg = ((rank + file) % 2 == 0) ? lightSquare : darkSquare;
-
- std::cout << bg << " " << symbol << " " << reset;
- }
-
- 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];
- std::string symbol = toChar(piece.type, piece.color);
-
- const char *bg = ((rank + file) % 2 == 0) ? lightSquare : darkSquare;
-
- std::cout << bg << " " << symbol << " " << reset;
- }
-
- std::printf("| %d\n", 8 - rank);
- }
- }
-
- std::cout << line;
- std::cout << (b->turn ? whiteLetters : blackLetters);
-
- std::println();
- std::println("Turn: {}", b->turn ? "White" : "Black");
-
- assert(b->castle != "");
-
- std::println("Castling: {}", b->castle);
- std::println("Can enpassant: {}", b->canEnpassant ? "Yes" : "No");
- std::println("Where enpassant: {}{}", (char)((int)b->enPassant.file + 'A'),
- 8 - (int)b->enPassant.rank);
- std::printf("Move clock: %d\n", b->MoveClock);
- std::printf("Half move clock: %d\n", b->halfMoveClock);
- std::printf("Board Eval: %f\n", EvaluateBoardForWhite(b, 0));
-}
-void PlayMove(Move move, Game *b) {
- // TODO: add all fide behavior
- Piece piece = b->pieces[PositionToIndex(move.From)];
- Piece piece2 = b->pieces[PositionToIndex(move.To)];
- if (piece2.type != NONE) {
- if (piece2.color == b->turn) {
- assert(false && "capturing friendly piece error");
- }
- }
- piece.moved = true;
- if (piece.type == PAWN || piece2.type != NONE) {
- b->halfMoveClock = 0;
- } else {
- b->halfMoveClock++;
- }
- if (piece.type == PAWN && b->canEnpassant && move.To == b->enPassant) {
- Position capturedPawn = move.To;
- capturedPawn.rank += piece.color ? 1 : -1;
- b->pieces[PositionToIndex(capturedPawn)] = {false, NONE, false};
- }
-
- b->canEnpassant = false;
- b->MoveClock++;
-
- if (piece.type == PAWN) {
- Position to = move.To;
- to.rank -= (piece.color ? -2 : 2);
- if (to == move.From) {
- b->canEnpassant = true;
- Position target = move.From;
- target.rank += piece.color ? -1 : 1;
- b->enPassant = target;
- };
- }
-
- if (piece.type == PAWN && move.To.rank == (piece.color ? 0 : 7)) {
- // TODO parse the promote type from uci isntead of ignoreting it
- piece.type = move.promotion == NONE ? QUEEN : move.promotion;
- }
- if (b->halfMoveClock >= 50) {
- b->state = DRAW;
- }
- b->pieces[PositionToIndex(move.To)] = piece;
- b->pieces[PositionToIndex(move.From)] = {false, NONE, false};
-
- b->turn = !b->turn;
-
- uint64_t key = GenerateZobristKey(b);
-
- b->ThreeFoldMap[key]++;
- if (b->ThreeFoldMap[key] >= 3) {
- b->state = DRAW;
- }
-};
int PositionToIndex(Position i) { return i.rank * 8 + i.file; }
UndoMove MakeMove(Move move, Game *g) {