Io rework #15

Merged
rektdie merged 7 commits from IO_rework into legalMovegen 2025-03-12 19:42:20 +01:00
2 changed files with 16 additions and 32 deletions
Showing only changes of commit 09f648e1f8 - Show all commits

No files matched your search

+15 -31
View File
@@ -12,43 +12,27 @@
#include "perft.h"
#include "utils.h"
void ParsePosition(Board &board, const char* command) {
command += 9; // Skip "position"
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"
void ParsePosition(Board &board, std::string_view command) {
if (command.find("startpos") != std::string::npos) {
board.SetByFen(StartingFen);
}
if (strncmp(command, " moves", 6) == 0) {
command += 6; // Skip " moves"
int fenIndex = command.find("fen");
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) {
while (*command == ' ') command++; // Skip spaces
if (movesIndex != std::string::npos) {
std::vector<std::string> moves = split(command.substr(movesIndex + 6, command.length() - (movesIndex + 5)), ' ');
std::string moveString;
while (*command && *command != ' ') {
moveString += *command;
command++;
}
if (!moveString.empty()) {
board.MakeMove(parseMove(board, moveString));
for (std::string_view move : moves) {
board.MakeMove(parseMove(board, move));
}
}
}
+1 -1
View File
@@ -14,7 +14,7 @@ public:
};
// 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
// GUI sends the engine this command if it should start searching for the best move