finished setbyfen

This commit is contained in:
rektdie committed 2025-03-12 14:30:12 +01:00
1 parent 69a7855f96
commit ad6ee77a46
2 files changed
+19

No files matched your search

+10
View File
@@ -58,8 +58,18 @@ void Board::SetByFen(std::string_view fen) {
sideToMove = tokens[1] == "b"; sideToMove = tokens[1] == "b";
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]; occupied = colors[White] | colors[Black];
hashKey = GetHashKey(*this); hashKey = GetHashKey(*this);
GenAttackMaps(*this);
} }
void Board::PrintBoard() { void Board::PrintBoard() {
+9
View File
@@ -17,3 +17,12 @@ std::vector<std::string> split(std::string_view str, char delim) {
return results; return results;
} }
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;
}