Io rework #15
No files matched your search
+15
-31
@@ -12,43 +12,27 @@
|
|||||||
#include "perft.h"
|
#include "perft.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
void ParsePosition(Board &board, const char* command) {
|
void ParsePosition(Board &board, std::string_view command) {
|
||||||
command += 9; // Skip "position"
|
if (command.find("startpos") != std::string::npos) {
|
||||||
|
|
||||||
if (strncmp(command, "fen", 3) == 0) {
|
|
||||||
command += 4; // Skip "fen "
|
|
||||||
|
|
||||||
std::string fen;
|
|
||||||
while (*command && strncmp(command, " moves", 6) != 0) {
|
|
||||||
fen += *command;
|
|
||||||
command++;
|
|
||||||
}
|
|
||||||
|
|
||||||
board.SetByFen(fen.c_str());
|
|
||||||
|
|
||||||
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) {
|
int fenIndex = command.find("fen");
|
||||||
command += 6; // Skip " moves"
|
int movesIndex = command.find("moves");
|
||||||
|
|
||||||
|
if (fenIndex != std::string::npos) {
|
||||||
|
if (movesIndex != std::string::npos) {
|
||||||
|
board.SetByFen(command.substr(fenIndex + 4, movesIndex - 2 - (fenIndex + 3)));
|
||||||
|
} else {
|
||||||
|
std::cout << (command.substr(fenIndex + 4, command.length() - (fenIndex + 3)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*command) {
|
if (movesIndex != std::string::npos) {
|
||||||
while (*command == ' ') command++; // Skip spaces
|
std::vector<std::string> moves = split(command.substr(movesIndex + 6, command.length() - (movesIndex + 5)), ' ');
|
||||||
|
|
||||||
std::string moveString;
|
for (std::string_view move : moves) {
|
||||||
while (*command && *command != ' ') {
|
board.MakeMove(parseMove(board, move));
|
||||||
moveString += *command;
|
|
||||||
command++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!moveString.empty()) {
|
|
||||||
board.MakeMove(parseMove(board, moveString));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Initializes the position with given parameters
|
// Initializes the position with given parameters
|
||||||
void ParsePosition(Board &board, const char* command);
|
void ParsePosition(Board &board, std::string_view command);
|
||||||
|
|
||||||
// Parse UCI "go" command
|
// Parse UCI "go" command
|
||||||
// GUI sends the engine this command if it should start searching for the best move
|
// GUI sends the engine this command if it should start searching for the best move
|
||||||
|
|||||||
Reference in new issue
Block a user