bugfix in parseSquare + rewrote parseMove

This commit is contained in:
rektdie committed 2025-03-12 16:55:36 +01:00
1 parent 7fb413fb01
commit 842cb45f38
4 files changed
+75 -98

No files matched your search

+2 -75
View File
@@ -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));
}
}
}