rewrote ParsePosition to be more robust (epd was buggy) #8

Merged
rektdie merged 1 commits from parse_position_fix into legalMovegen 2025-03-05 05:42:53 +01:00
Showing only changes of commit 4d88936fe5 - Show all commits
+20 -34
View File
@@ -7,6 +7,7 @@
#include "movegen.h" #include "movegen.h"
#include "search.h" #include "search.h"
#include "benchmark.h" #include "benchmark.h"
#include <cstring>
Move ParseMove(Board &board, const char* moveString) { Move ParseMove(Board &board, const char* moveString) {
GenerateMoves(board, board.sideToMove); GenerateMoves(board, board.sideToMove);
@@ -83,57 +84,42 @@ Move ParseMove(Board &board, const char* moveString) {
} }
void ParsePosition(Board &board, const char* command) { void ParsePosition(Board &board, const char* command) {
// shifting pointer to where the token begins (skipping 'position' word) command += 9; // Skip "position"
command += 9;
// fen if (strncmp(command, "fen", 3) == 0) {
if (*command == 'f') { command += 4; // Skip "fen "
command += 4;
std::string fen = ""; std::string fen;
while (*command && strncmp(command, " moves", 6) != 0) {
while (*command && *(command + 1) != 'm') {
fen += *command; fen += *command;
command++; command++;
} }
// skipping space
command++;
board.SetByFen(fen.c_str()); board.SetByFen(fen.c_str());
} else if (*command == 's') { // startpos
command += 9; if (strncmp(command, " moves", 6) == 0) {
command += 6; // Skip " moves"
}
} else if (strncmp(command, "startpos", 8) == 0) {
command += 8; // Skip "startpos"
board.SetByFen(StartingFen); board.SetByFen(StartingFen);
if (strncmp(command, " moves", 6) == 0) {
command += 6; // Skip " moves"
}
} }
// moves
if (*command == 'm') {
// skipping word 'moves'
command += 5;
// looping through the moves
while (*command) { while (*command) {
// skipping previous space while (*command == ' ') command++; // Skip spaces
command++;
std::string moveString = ""; std::string moveString;
while (*command && *command != ' ') {
bool multipleMoves = std::string(command).length() > 5;
if (multipleMoves) {
while (*command != ' ') {
moveString += *command; moveString += *command;
command++; command++;
} }
if (!moveString.empty()) {
board.MakeMove(ParseMove(board, moveString.c_str())); board.MakeMove(ParseMove(board, moveString.c_str()));
continue;
} else {
while (*command) {
moveString += *command;
command++;
}
board.MakeMove(ParseMove(board, moveString.c_str()));
}
} }
} }
} }