Io rework #15
No files matched your search
+2
-75
@@ -10,80 +10,7 @@
|
||||
#include <cstring>
|
||||
#include "tt.h"
|
||||
#include "perft.h"
|
||||
|
||||
Move ParseMove(Board &board, const char* moveString) {
|
||||
GenerateMoves(board, board.sideToMove);
|
||||
|
||||
// Source square
|
||||
std::string fromString = "";
|
||||
fromString += moveString[0];
|
||||
fromString += moveString[1];
|
||||
|
||||
auto it = std::find(squareCoords.begin(), squareCoords.end(), fromString);
|
||||
|
||||
int from = std::distance(squareCoords.begin(), it);
|
||||
|
||||
// Target square
|
||||
std::string toString = "";
|
||||
toString += moveString[2];
|
||||
toString += moveString[3];
|
||||
|
||||
it = std::find(squareCoords.begin(), squareCoords.end(), toString);
|
||||
|
||||
int to = std::distance(squareCoords.begin(), it);
|
||||
std::string promotionString = "";
|
||||
|
||||
// Finding the move from available moves
|
||||
for (Move move : board.moveList) {
|
||||
if (move.MoveFrom() == from && move.MoveTo() == to) {
|
||||
// Checking for promotion
|
||||
if (std::string(moveString).length() == 5) {
|
||||
int promotePiece = 0;
|
||||
|
||||
// Checking for capture promotion
|
||||
if (board.GetPieceColor(from) != board.GetPieceColor(to)) {
|
||||
switch (moveString[4])
|
||||
{
|
||||
case 'r':
|
||||
promotePiece = rookPromoCapture;
|
||||
break;
|
||||
case 'q':
|
||||
promotePiece = queenPromoCapture;
|
||||
break;
|
||||
case 'b':
|
||||
promotePiece = bishopPromoCapture;
|
||||
break;
|
||||
case 'n':
|
||||
promotePiece = knightPromoCapture;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (moveString[4])
|
||||
{
|
||||
case 'r':
|
||||
promotePiece = rookPromotion;
|
||||
break;
|
||||
case 'q':
|
||||
promotePiece = queenPromotion;
|
||||
break;
|
||||
case 'b':
|
||||
promotePiece = bishopPromotion;
|
||||
break;
|
||||
case 'n':
|
||||
promotePiece = knightPromotion;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Move(from, to, promotePiece);
|
||||
}
|
||||
|
||||
return move;
|
||||
}
|
||||
}
|
||||
|
||||
return Move();
|
||||
}
|
||||
#include "utils.h"
|
||||
|
||||
void ParsePosition(Board &board, const char* command) {
|
||||
command += 9; // Skip "position"
|
||||
@@ -121,7 +48,7 @@ void ParsePosition(Board &board, const char* command) {
|
||||
}
|
||||
|
||||
if (!moveString.empty()) {
|
||||
board.MakeMove(ParseMove(board, moveString.c_str()));
|
||||
board.MakeMove(parseMove(board, moveString));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,6 @@ public:
|
||||
SearchParams(){}
|
||||
};
|
||||
|
||||
// Returns Move object from a string
|
||||
Move ParseMove(Board &board, const char* moveString);
|
||||
|
||||
// Initializes the position with given parameters
|
||||
void ParsePosition(Board &board, const char* command);
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "utils.h"
|
||||
|
||||
std::vector<std::string> split(std::string_view str, char delim) {
|
||||
std::vector<std::string> results;
|
||||
|
||||
std::istringstream stream(std::string{str});
|
||||
|
||||
for (std::string token{}; std::getline(stream, token, delim);) {
|
||||
if (token.empty()) continue;
|
||||
|
||||
results.push_back(token);
|
||||
}
|
||||
|
||||
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' - 1;
|
||||
|
||||
return file + rank * 8;
|
||||
}
|
||||
|
||||
Move parseMove(Board &board, std::string_view str) {
|
||||
int from = parseSquare(str.substr(0, 2));
|
||||
int to = parseSquare(str.substr(2, 2));
|
||||
|
||||
int flag = 0;
|
||||
|
||||
// Promotion
|
||||
if (str.length() > 4) {
|
||||
if (board.GetPieceColor(from) != board.GetPieceColor(to)) {
|
||||
switch(str[4]) {
|
||||
case 'r':
|
||||
flag = rookPromoCapture;
|
||||
break;
|
||||
case 'q':
|
||||
flag = queenPromoCapture;
|
||||
break;
|
||||
case 'b':
|
||||
flag = bishopPromoCapture;
|
||||
break;
|
||||
case 'n':
|
||||
flag = knightPromoCapture;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch(str[4]) {
|
||||
case 'r':
|
||||
flag = rookPromotion;
|
||||
break;
|
||||
case 'q':
|
||||
flag = queenPromotion;
|
||||
break;
|
||||
case 'b':
|
||||
flag = bishopPromotion;
|
||||
break;
|
||||
case 'n':
|
||||
flag = knightPromotion;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Move(from, to, flag);
|
||||
}
|
||||
+5
-20
@@ -3,26 +3,11 @@
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <sstream>
|
||||
#include "move.h"
|
||||
#include "board.h"
|
||||
|
||||
std::vector<std::string> split(std::string_view str, char delim) {
|
||||
std::vector<std::string> results;
|
||||
std::vector<std::string> split(std::string_view str, char delim);
|
||||
|
||||
std::istringstream stream(std::string{str});
|
||||
int parseSquare(std::string_view str);
|
||||
|
||||
for (std::string token{}; std::getline(stream, token, delim);) {
|
||||
if (token.empty()) continue;
|
||||
|
||||
results.push_back(token);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
Move parseMove(Board &board, std::string_view str);
|
||||
Reference in new issue
Block a user