rewrote the whole GetDirection function + minor bugfix in castling updates
This commit is contained in:
1 parent
4226b21043
commit
ff0c0c785a
3 files changed
+24
-17
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) {
|
||||
if (targetPiece == Rook) {
|
||||
int queenSideRook = attackerColor ? a1 : a8;
|
||||
int kingSideRook = attackerColor ? a8 : h8;
|
||||
int kingSideRook = attackerColor ? h1 : h8;
|
||||
|
||||
if (targetSquare == queenSideRook) {
|
||||
board.castlingRights[!attackerColor * 2 + 1] = false;
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ int main() {
|
||||
initSliderAttacks();
|
||||
|
||||
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);
|
||||
|
||||
return 0;
|
||||
|
||||
+22
-15
@@ -316,24 +316,31 @@ static Bitboard Checkers(Board &board, bool color) {
|
||||
|
||||
// Returns the direction to target from square
|
||||
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) {
|
||||
return north;
|
||||
} 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) {
|
||||
// Main directions
|
||||
if (rankDiff == 0 && fileDiff < 0) {
|
||||
return west;
|
||||
} else if (ranks[square / 8] == ranks[target / 8] && target > square) {
|
||||
} else if (rankDiff == 0 && fileDiff > 0) {
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user