From ad6ee77a465a17dab41817a5a7c70fc1c300d5f5 Mon Sep 17 00:00:00 2001 From: rektdie Date: Wed, 12 Mar 2025 14:30:12 +0100 Subject: [PATCH] finished setbyfen --- source/board.cpp | 14 ++++++++++++-- source/utils.h | 11 ++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/source/board.cpp b/source/board.cpp index a976463..626650b 100644 --- a/source/board.cpp +++ b/source/board.cpp @@ -58,8 +58,18 @@ void Board::SetByFen(std::string_view fen) { sideToMove = tokens[1] == "b"; - occupied = colors[White] | colors[Black]; - hashKey = GetHashKey(*this); + for (const char piece : tokens[2]) { + if (piece == 'K') castlingRights |= whiteKingRight; + else if (piece == 'Q') castlingRights |= whiteQueenRight; + else if (piece == 'k') castlingRights |= blackKingRight; + else if (piece == 'q') castlingRights |= blackQueenRight; + } + + if (tokens[3] != "-") enPassantTarget = parseSquare(tokens[3]); + + occupied = colors[White] | colors[Black]; + hashKey = GetHashKey(*this); + GenAttackMaps(*this); } void Board::PrintBoard() { diff --git a/source/utils.h b/source/utils.h index e76ea95..6e5ffe0 100644 --- a/source/utils.h +++ b/source/utils.h @@ -16,4 +16,13 @@ std::vector split(std::string_view str, char delim) { } return results; -} \ No newline at end of file +} + +int parseSquare(std::string_view str) { + constexpr std::string_view files = "abcdefgh"; + + int file = files.find(str[0]); + int rank = str[1] - '0'; + + return file + rank * 8; +}