rewrote ParsePosition to be more robust (epd was buggy)
This commit is contained in:
1 parent
43bf5a20a4
commit
4d88936fe5
1 file changed
+24
-38
+24
-38
@@ -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
|
while (*command) {
|
||||||
if (*command == 'm') {
|
while (*command == ' ') command++; // Skip spaces
|
||||||
// skipping word 'moves'
|
|
||||||
command += 5;
|
|
||||||
|
|
||||||
// looping through the moves
|
std::string moveString;
|
||||||
while (*command) {
|
while (*command && *command != ' ') {
|
||||||
// skipping previous space
|
moveString += *command;
|
||||||
command++;
|
command++;
|
||||||
|
}
|
||||||
|
|
||||||
std::string moveString = "";
|
if (!moveString.empty()) {
|
||||||
|
board.MakeMove(ParseMove(board, moveString.c_str()));
|
||||||
bool multipleMoves = std::string(command).length() > 5;
|
|
||||||
|
|
||||||
if (multipleMoves) {
|
|
||||||
while (*command != ' ') {
|
|
||||||
moveString += *command;
|
|
||||||
command++;
|
|
||||||
}
|
|
||||||
|
|
||||||
board.MakeMove(ParseMove(board, moveString.c_str()));
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
while (*command) {
|
|
||||||
moveString += *command;
|
|
||||||
command++;
|
|
||||||
}
|
|
||||||
board.MakeMove(ParseMove(board, moveString.c_str()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user