rewrote the whole GetDirection function + minor bugfix in castling updates
This commit is contained in:
1 parent
4226b21043
commit
ff0c0c785a
3 files changed
+25
-18
No files matched your search
+1
-1
@@ -295,7 +295,7 @@ void Board::RemovePiece(int piece, int square, bool color) {
|
|||||||
static void UpdateCastlingRights(Board &board, int targetPiece, int targetSquare, int attackerColor) {
|
static void UpdateCastlingRights(Board &board, int targetPiece, int targetSquare, int attackerColor) {
|
||||||
if (targetPiece == Rook) {
|
if (targetPiece == Rook) {
|
||||||
int queenSideRook = attackerColor ? a1 : a8;
|
int queenSideRook = attackerColor ? a1 : a8;
|
||||||
int kingSideRook = attackerColor ? a8 : h8;
|
int kingSideRook = attackerColor ? h1 : h8;
|
||||||
|
|
||||||
if (targetSquare == queenSideRook) {
|
if (targetSquare == queenSideRook) {
|
||||||
board.castlingRights[!attackerColor * 2 + 1] = false;
|
board.castlingRights[!attackerColor * 2 + 1] = false;
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ int main() {
|
|||||||
initSliderAttacks();
|
initSliderAttacks();
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
//board.SetByFen("rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8");
|
board.SetByFen("8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1");
|
||||||
Perft(board, 5);
|
Perft(board, 5);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+23
-16
@@ -316,24 +316,31 @@ static Bitboard Checkers(Board &board, bool color) {
|
|||||||
|
|
||||||
// Returns the direction to target from square
|
// Returns the direction to target from square
|
||||||
static int GetDirection(int square, int target) {
|
static int GetDirection(int square, int target) {
|
||||||
int difference = target - square;
|
int rankDiff = (target / 8) - (square / 8);
|
||||||
|
int fileDiff = (target % 8) - (square % 8);
|
||||||
|
|
||||||
if (difference % north == 0 && difference > 0) {
|
// Main directions
|
||||||
return north;
|
if (rankDiff == 0 && fileDiff < 0) {
|
||||||
} else if (difference % south == 0 && difference < 0) {
|
|
||||||
return south;
|
|
||||||
} else if (difference % noWe == 0 && difference > 0) {
|
|
||||||
return noWe;
|
|
||||||
} else if (difference % noEa == 0 && difference > 0) {
|
|
||||||
return noEa;
|
|
||||||
} else if (difference % soWe == 0 && difference < 0) {
|
|
||||||
return soWe;
|
|
||||||
} else if (difference % soEa == 0 && difference < 0) {
|
|
||||||
return soEa;
|
|
||||||
} else if (ranks[square / 8] == ranks[target / 8] && target < square) {
|
|
||||||
return west;
|
return west;
|
||||||
} else if (ranks[square / 8] == ranks[target / 8] && target > square) {
|
} else if (rankDiff == 0 && fileDiff > 0) {
|
||||||
return east;
|
return east;
|
||||||
|
} else if (rankDiff < 0 && fileDiff == 0) {
|
||||||
|
return south;
|
||||||
|
} else if (rankDiff > 0 && fileDiff == 0) {
|
||||||
|
return north;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Diagonals
|
||||||
|
if (abs(rankDiff) == abs(fileDiff)) {
|
||||||
|
if (rankDiff < 0 && fileDiff < 0) {
|
||||||
|
return soWe;
|
||||||
|
} else if (rankDiff < 0 && fileDiff > 0) {
|
||||||
|
return soEa;
|
||||||
|
} else if (rankDiff > 0 && fileDiff < 0) {
|
||||||
|
return noWe;
|
||||||
|
} else if (rankDiff > 0 && fileDiff > 0) {
|
||||||
|
return noEa;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -853,7 +860,7 @@ static void GenCheckEvasions(Board &board, bool color) {
|
|||||||
pushMask.PopBit(kingSquare);
|
pushMask.PopBit(kingSquare);
|
||||||
pushMask.PopBit(checkerSquare);
|
pushMask.PopBit(checkerSquare);
|
||||||
}
|
}
|
||||||
|
|
||||||
// looping through own pieces to add captures and blocks
|
// looping through own pieces to add captures and blocks
|
||||||
for (int type = Pawn; type < King; type++) {
|
for (int type = Pawn; type < King; type++) {
|
||||||
Bitboard currentPiece = board.colors[color] & board.pieces[type];
|
Bitboard currentPiece = board.colors[color] & board.pieces[type];
|
||||||
|
|||||||
Reference in new issue
Block a user