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; +}