Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attacks near king evaluation rework #29

Merged
merged 7 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ Thanks to:
- Some ideas in this engine are inspired by [Stockfish](https://github.com/official-stockfish/Stockfish)

# License
Zagreus is a chess engine that supports the UCI protocol

Copyright (C) 2023 Danny Jelsma

This program is free software: you can redistribute it and/or modify
Expand All @@ -71,3 +69,5 @@ GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.

This project uses the [Senjo UCI Adapter](https://github.com/zd3nik/SenjoUCIAdapter) by zd3nik which is licensed under the MIT license. All files from the Senjo UCI Adapter retain their original copyright and license notices.
14 changes: 7 additions & 7 deletions src/features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <iostream>

namespace Zagreus {
int evalValues[72] = { 97, 105, 354, 344, 361, 352, 530, 531, 1010, 1005, 6, 6, 3, -1, 5, 5, 2, 6, 0, 12, -50, 0, -25, 0, -29, -6, -16, -5, -4, -1, -2, 3, -3, 2, -8, -5, 6, 8, 16, 1, 12, 3, 0, 3, 7, 7, 20, 20, 15, 15, 6, 3, 5, 5, 7, -1, -27, -26, 23, 6, -4, 0, -1, 0, -20, -20, 2, -6, 3, 3, 25, -2, };
int evalValues[72] = { 101, 111, 360, 349, 374, 358, 539, 538, 1012, 1010, 7, 11, 7, 0, 8, 5, 4, 7, 0, 15, -50, 0, -25, 0, -30, -4, -9, -1, -8, 0, -3, -3, -5, -5, -10, -10, 5, 12, 20, 8, 13, 9, 1, 15, 11, 9, 20, 20, 15, 15, 5, 1, 9, 4, 8, 6, -32, -21, 24, 1, -4, 0, -1, 0, -20, -20, 0, -2, 3, 3, 32, -4, };

int baseEvalValues[72] = {
100, // MIDGAME_PAWN_MATERIAL
Expand Down Expand Up @@ -54,12 +54,12 @@ namespace Zagreus {
0, // ENDGAME_QUEENSIDE_CASTLING_PREVENTED
-10, // MIDGAME_KINGSIDE_CASTLING_PREVENTED
0, // ENDGAME_KINGSIDE_CASTLING_PREVENTED
3, // MIDGAME_BISHOP_ATTACK_NEAR_KING
3, // ENDGAME_BISHOP_ATTACK_NEAR_KING
5, // MIDGAME_ROOK_ATTACK_NEAR_KING
5, // ENDGAME_ROOK_ATTACK_NEAR_KING
10, // MIDGAME_QUEEN_ATTACK_NEAR_KING
10, // ENDGAME_QUEEN_ATTACK_NEAR_KING
-3, // MIDGAME_BISHOP_ATTACK_NEAR_KING
-3, // ENDGAME_BISHOP_ATTACK_NEAR_KING
-5, // MIDGAME_ROOK_ATTACK_NEAR_KING
-5, // ENDGAME_ROOK_ATTACK_NEAR_KING
-10, // MIDGAME_QUEEN_ATTACK_NEAR_KING
-10, // ENDGAME_QUEEN_ATTACK_NEAR_KING
10, // MIDGAME_PAWN_CONNECTIVITY
10, // ENDGAME_PAWN_CONNECTIVITY
7, // MIDGAME_KNIGHT_CONNECTIVITY
Expand Down
24 changes: 12 additions & 12 deletions src/pst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@
#include <vector>

namespace Zagreus {
int midgamePawnTable[64] = { 0, 0, 0, 0, 0, 0, 0, 0, 96, 130, 63, 93, 70, 123, 39, -9, -6, 4, 24, 30, 62, 59, 27, -15, -17, 9, 1, 17, 19, 15, 23, -20, -35, -10, -10, 14, 25, 10, 11, -29, -21, 0, -10, 0, -3, 2, 20, -12, -26, 4, -10, -11, -14, 6, 37, -19, 0, 0, 0, 0, 0, 0, 0, 0 };
int endgamePawnTable[64] = { 0, 0, 0, 0, 0, 0, 0, 0, 180, 175, 161, 132, 147, 132, 165, 189, 100, 100, 79, 65, 53, 53, 87, 92, 30, 23, 12, 1, 0, 5, 22, 26, 6, 7, -9, -9, -12, -9, 4, 4, 5, 2, -11, 6, 3, -4, -1, -6, 8, 5, 7, 14, 14, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0 };
int midgamePawnTable[64] = { 0, 0, 0, 0, 0, 0, 0, 0, 98, 130, 59, 98, 66, 124, 34, -7, -2, 9, 28, 32, 62, 60, 31, -16, -12, 11, -1, 19, 19, 17, 22, -16, -41, -10, -11, 16, 23, 11, 10, -31, -26, 0, -9, -8, 0, 0, 17, -18, -23, 12, -6, -16, -10, 7, 38, -13, 0, 0, 0, 0, 0, 0, 0, 0 };
int endgamePawnTable[64] = { 0, 0, 0, 0, 0, 0, 0, 0, 185, 175, 159, 136, 145, 130, 173, 191, 104, 106, 86, 70, 60, 62, 91, 89, 35, 23, 5, -4, -8, 5, 24, 27, 6, 1, -7, -14, -9, -13, 4, 5, 2, 3, -11, 0, 0, -4, -3, 0, 14, 11, 11, 15, 14, 4, 0, -6, 0, 0, 0, 0, 0, 0, 0, 0 };

int midgameKnightTable[64] = { -164, -88, -35, -50, 61, -97, -15, -109, -74, -38, 68, 39, 28, 63, 9, -18, -48, 57, 34, 62, 84, 128, 73, 43, -7, 19, 21, 50, 32, 62, 21, 24, -16, 3, 17, 9, 24, 18, 19, -11, -26, -3, 21, 12, 22, 12, 22, -18, -27, -48, -9, 5, 4, 18, -15, -12, -103, -29, -55, -28, -12, -26, -21, -23 };
int endgameKnightTable[64] = { -57, -36, -15, -30, -31, -27, -63, -101, -26, -10, -24, 0, -8, -23, -21, -50, -26, -22, 8, 8, -1, -9, -20, -40, -13, 4, 22, 18, 24, 11, 12, -17, -17, -4, 16, 28, 16, 14, 2, -16, -22, -6, -5, 16, 13, -7, -23, -22, -42, -19, -7, -2, 0, -18, -23, -43, -29, -52, -24, -16, -19, -15, -56, -63 };
int midgameKnightTable[64] = { -166, -89, -34, -48, 59, -95, -15, -108, -72, -37, 76, 36, 23, 61, 2, -17, -48, 59, 38, 67, 86, 128, 74, 45, -8, 11, 18, 46, 38, 60, 19, 24, -13, 6, 16, 19, 31, 19, 22, -9, -22, -8, 18, 10, 18, 13, 18, -13, -25, -53, -13, 2, 7, 17, -12, -12, -107, -24, -54, -27, -17, -25, -19, -23 };
int endgameKnightTable[64] = { -59, -38, -13, -29, -33, -26, -64, -97, -27, -8, -22, -1, -11, -27, -24, -52, -22, -18, 10, 13, 0, -6, -20, -41, -16, 9, 19, 21, 22, 10, 4, -18, -19, -6, 17, 23, 18, 15, 4, -15, -26, -4, -6, 15, 12, -7, -21, -25, -40, -20, -11, 0, 0, -19, -22, -41, -30, -46, -20, -13, -21, -16, -48, -65 };

int midgameBishopTable[64] = { -29, 3, -79, -37, -25, -43, 2, -7, -29, 14, -16, -11, 30, 55, 19, -44, -9, 37, 46, 42, 34, 54, 34, 2, -4, 6, 18, 47, 32, 35, 1, 0, -3, 13, 5, 24, 26, 9, 15, 1, -4, 19, 13, 12, 6, 23, 22, 11, 4, 24, 16, 5, 7, 25, 40, 0, -31, -2, -14, -18, -6, -3, -37, -18 };
int endgameBishopTable[64] = { -12, -19, -9, -6, -6, -7, -21, -23, -10, -5, 6, -9, -5, -15, -3, -15, 4, -8, 0, 0, -4, 5, -2, 5, 0, 8, 9, 9, 15, 9, 3, 1, -5, 1, 9, 17, 6, 9, 0, -9, -12, -3, 2, 9, 8, 0, -6, -12, -12, -14, -7, -3, 3, -8, -8, -25, -21, -13, -22, 0, -2, -15, -3, -16 };
int midgameBishopTable[64] = { -26, 4, -81, -36, -26, -42, 4, -7, -25, 12, -15, -9, 27, 57, 19, -42, -10, 35, 40, 37, 37, 53, 35, 2, -1, 0, 20, 46, 33, 35, 1, 0, -8, 11, 4, 27, 32, 8, 8, 1, 0, 20, 17, 4, 7, 21, 16, 12, 3, 28, 17, 6, 12, 22, 39, 0, -32, -6, -6, -19, -11, 0, -38, -17 };
int endgameBishopTable[64] = { -11, -17, -12, -6, -3, -9, -19, -23, -7, -3, 6, -10, -4, -14, -3, -12, 6, -9, 0, 0, 0, 6, 0, 10, 0, 6, 9, 9, 11, 6, 1, 1, -5, 3, 10, 16, 5, 5, -2, -10, -11, -2, 6, 3, 11, 4, -7, -15, -11, -15, -7, 1, 11, -7, -13, -29, -23, -9, -16, 0, -10, -13, -3, -14 };

int midgameRookTable[64] = { 31, 42, 30, 51, 60, 10, 31, 41, 28, 29, 59, 58, 79, 67, 27, 41, -3, 21, 27, 35, 17, 45, 60, 18, -22, -10, 6, 26, 25, 33, -4, -18, -39, -25, -14, -5, 8, -7, 7, -26, -45, -26, -16, -19, 5, 0, -6, -34, -47, -15, -16, -11, 0, 12, -6, -70, -13, -11, 0, 8, 16, 6, -30, -25 };
int endgameRookTable[64] = { 12, 12, 16, 14, 7, 12, 7, 4, 10, 8, 11, 7, -1, 2, 9, 2, 10, 8, 5, 4, 8, 0, -4, -3, 4, 5, 10, 0, 0, 0, 0, 6, 1, 8, 8, 0, -4, -6, -7, -9, -2, 0, -5, 0, -4, -11, -10, -15, -8, -5, 0, 0, -7, -7, -12, 0, -5, 1, 1, -2, -4, -13, 5, -18 };
int midgameRookTable[64] = { 31, 42, 30, 48, 59, 10, 29, 44, 27, 30, 59, 61, 79, 61, 31, 42, -5, 19, 27, 36, 17, 47, 60, 14, -20, -10, 6, 25, 21, 34, -8, -19, -34, -25, -12, -2, 8, -6, 6, -22, -45, -21, -15, -17, 5, 0, -1, -35, -49, -18, -17, -10, 0, 12, -6, -66, -15, -19, 4, 15, 17, 6, -30, -25 };
int endgameRookTable[64] = { 14, 9, 13, 12, 5, 13, 4, 4, 10, 9, 13, 9, 0, 0, 8, 1, 7, 8, 8, 4, 5, 0, -5, -1, 5, 4, 13, 2, 0, 6, -3, 6, 5, 4, 7, 2, -5, -6, -6, -8, -2, 2, -3, 0, -9, -15, -4, -14, -3, -6, 1, -1, -4, -7, -10, -2, -2, 0, 0, 0, -4, -6, 9, -18 };

int midgameQueenTable[64] = { -26, 0, 28, 13, 58, 43, 41, 44, -22, -37, -4, 0, -16, 58, 25, 50, -8, -17, 12, 6, 30, 54, 44, 57, -19, -28, -18, -17, 0, 18, -5, 5, -15, -21, -13, -7, -9, -6, 3, 0, -17, 0, -10, -8, -4, -6, 11, 2, -29, -6, 7, 0, 4, 22, 0, 2, 0, -15, -9, 0, 0, -20, -32, -44 };
int endgameQueenTable[64] = { -8, 25, 20, 29, 27, 17, 9, 18, -13, 20, 33, 42, 57, 26, 29, 0, -17, 7, 12, 50, 47, 31, 17, 12, 4, 20, 24, 42, 54, 38, 54, 36, -19, 27, 14, 47, 27, 34, 40, 21, -16, -26, 12, 2, 7, 12, 10, 4, -18, -20, -30, -18, -20, -20, -36, -27, -31, -26, -21, -44, 1, -28, -20, -37 };
int midgameQueenTable[64] = { -25, -1, 28, 11, 58, 43, 43, 44, -20, -36, -8, -1, -17, 57, 22, 49, -10, -12, 9, 9, 26, 55, 42, 57, -25, -24, -15, -13, -2, 18, 0, 0, -14, -22, -16, -12, 0, -2, 1, -5, -13, 0, -8, -4, -2, 0, 10, 4, -33, -1, 6, -5, 2, 14, -2, 0, -4, -15, -11, 2, 3, -28, -32, -44 };
int endgameQueenTable[64] = { -4, 20, 20, 25, 29, 18, 10, 20, -11, 19, 32, 38, 58, 24, 26, 0, -17, 8, 10, 47, 47, 31, 17, 7, 5, 23, 23, 45, 52, 38, 56, 37, -17, 27, 15, 44, 30, 36, 35, 23, -14, -26, 15, 6, 12, 19, 6, 5, -19, -21, -33, -16, -12, -24, -34, -30, -35, -25, -22, -40, 0, -32, -18, -36 };

int midgameKingTable[64] = { -64, 22, 15, -14, -55, -33, 2, 13, 29, 0, -20, -6, -8, -3, -37, -28, -7, 25, 3, -14, -19, 5, 21, -22, -15, -19, -10, -27, -29, -24, -13, -35, -49, -3, -27, -39, -46, -42, -33, -53, -12, -15, -24, -44, -42, -29, -14, -26, 1, 10, -15, -64, -42, -16, 13, 10, -4, 31, 1, -32, -8, -24, 23, 14 };
int endgameKingTable[64] = { -74, -35, -15, -16, -11, 15, 5, -18, -12, 17, 15, 17, 16, 37, 22, 10, 10, 19, 22, 14, 21, 44, 41, 14, -8, 20, 23, 27, 24, 33, 26, 6, -17, -4, 17, 25, 28, 26, 7, -11, -19, -3, 11, 25, 24, 18, 7, -10, -25, -10, 1, 14, 15, 8, 0, -15, -52, -39, -27, -6, -36, -10, -30, -44 };
int midgameKingTable[64] = { -65, 22, 16, -14, -56, -34, 3, 12, 29, -1, -19, -7, -7, -4, -37, -29, -9, 24, 2, -16, -20, 6, 25, -22, -17, -19, -13, -25, -32, -24, -14, -34, -49, -1, -28, -37, -44, -40, -31, -50, -15, -12, -22, -46, -44, -29, -15, -28, 5, 6, -11, -65, -47, -15, 11, 12, -5, 32, 1, -31, -13, -30, 24, 19 };
int endgameKingTable[64] = { -74, -34, -17, -16, -11, 13, 6, -17, -12, 19, 15, 18, 15, 35, 25, 11, 10, 16, 24, 11, 21, 43, 49, 13, -7, 22, 23, 27, 21, 33, 29, 4, -19, -1, 18, 22, 31, 32, 11, -9, -21, -2, 13, 20, 23, 19, 6, -11, -26, -8, 0, 18, 16, 7, -6, -17, -48, -43, -25, -10, -34, -17, -25, -46 };

/* int midgamePawnTable[64] = {
0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
136 changes: 114 additions & 22 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ namespace Zagreus {
void getWhiteKingScore(EvalContext &evalContext, Bitboard &bitboard) {
uint64_t kingBB = bitboard.getPieceBoard<PieceType::WHITE_KING>();
uint64_t kingLocation = bitscanForward(kingBB);
uint64_t kingAttacks = bitboard.getKingAttacks(kingLocation);
uint64_t kingAttacks = evalContext.attacksFrom[kingLocation];
uint64_t pawnBB = bitboard.getPieceBoard<PieceType::WHITE_PAWN>();
uint64_t safetyMask = nortOne(kingBB) | noEaOne(kingBB) | noWeOne(kingBB);
safetyMask |= nortOne(safetyMask);
Expand Down Expand Up @@ -725,20 +725,43 @@ namespace Zagreus {
}
}

evalContext.whiteMidgameScore += popcnt(evalContext.blackBishopAttacks & kingAttacks) * getEvalValue(MIDGAME_BISHOP_ATTACK_NEAR_KING);
evalContext.whiteEndgameScore += popcnt(evalContext.blackBishopAttacks & kingAttacks) * getEvalValue(ENDGAME_BISHOP_ATTACK_NEAR_KING);
evalContext.whiteMidgameScore += popcnt(evalContext.blackRookAttacks & kingAttacks) * getEvalValue(MIDGAME_ROOK_ATTACK_NEAR_KING);
evalContext.whiteEndgameScore += popcnt(evalContext.blackRookAttacks & kingAttacks) * getEvalValue(ENDGAME_ROOK_ATTACK_NEAR_KING);
evalContext.whiteMidgameScore += popcnt(evalContext.blackQueenAttacks & kingAttacks) * getEvalValue(MIDGAME_QUEEN_ATTACK_NEAR_KING);
evalContext.whiteEndgameScore += popcnt(evalContext.blackQueenAttacks & kingAttacks) * getEvalValue(ENDGAME_QUEEN_ATTACK_NEAR_KING);
while (kingAttacks) {
int8_t attackIndex = bitscanForward(kingAttacks);
uint64_t attacksTo = evalContext.attacksTo[attackIndex] & bitboard.getColorBoard<PieceColor::BLACK>();

while (attacksTo) {
int8_t index = bitscanForward(attacksTo);

PieceType pieceOnSquare = bitboard.getPieceOnSquare(index);

switch (pieceOnSquare) {
case PieceType::WHITE_BISHOP:
evalContext.whiteMidgameScore += getEvalValue(MIDGAME_BISHOP_ATTACK_NEAR_KING);
evalContext.whiteEndgameScore += getEvalValue(ENDGAME_BISHOP_ATTACK_NEAR_KING);
break;
case PieceType::WHITE_ROOK:
evalContext.whiteMidgameScore += getEvalValue(MIDGAME_ROOK_ATTACK_NEAR_KING);
evalContext.whiteEndgameScore += getEvalValue(ENDGAME_ROOK_ATTACK_NEAR_KING);
break;
case PieceType::WHITE_QUEEN:
evalContext.whiteMidgameScore += getEvalValue(MIDGAME_QUEEN_ATTACK_NEAR_KING);
evalContext.whiteEndgameScore += getEvalValue(ENDGAME_QUEEN_ATTACK_NEAR_KING);
break;
}

attacksTo &= ~(1ULL << index);
}

kingAttacks &= ~(1ULL << attackIndex);
}
}

uint64_t blackQueenCastlingAttackPattern = 0x7000000000000000;
uint64_t blackKingCastlingAttackPattern = 0x600000000000000;
void getBlackKingScore(EvalContext &evalContext, Bitboard &bitboard) {
uint64_t kingBB = bitboard.getPieceBoard<PieceType::BLACK_KING>();
uint64_t kingLocation = bitscanForward(kingBB);
uint64_t kingAttacks = bitboard.getKingAttacks(kingLocation);
uint64_t kingAttacks = evalContext.attacksFrom[kingLocation];
uint64_t pawnBB = bitboard.getPieceBoard<PieceType::BLACK_PAWN>();
uint64_t safetyMask = soutOne(kingBB) | soEaOne(kingBB) | soWeOne(kingBB);
safetyMask |= soutOne(safetyMask);
Expand Down Expand Up @@ -783,12 +806,35 @@ namespace Zagreus {
}
}

evalContext.blackMidgameScore += popcnt(evalContext.whiteBishopAttacks & kingAttacks) * getEvalValue(MIDGAME_BISHOP_ATTACK_NEAR_KING);
evalContext.blackEndgameScore += popcnt(evalContext.whiteBishopAttacks & kingAttacks) * getEvalValue(ENDGAME_BISHOP_ATTACK_NEAR_KING);
evalContext.blackMidgameScore += popcnt(evalContext.whiteRookAttacks & kingAttacks) * getEvalValue(MIDGAME_ROOK_ATTACK_NEAR_KING);
evalContext.blackEndgameScore += popcnt(evalContext.whiteRookAttacks & kingAttacks) * getEvalValue(ENDGAME_ROOK_ATTACK_NEAR_KING);
evalContext.blackMidgameScore += popcnt(evalContext.whiteQueenAttacks & kingAttacks) * getEvalValue(MIDGAME_QUEEN_ATTACK_NEAR_KING);
evalContext.blackEndgameScore += popcnt(evalContext.whiteQueenAttacks & kingAttacks) * getEvalValue(ENDGAME_QUEEN_ATTACK_NEAR_KING);
while (kingAttacks) {
int8_t attackIndex = bitscanForward(kingAttacks);
uint64_t attacksTo = evalContext.attacksTo[attackIndex] & bitboard.getColorBoard<PieceColor::WHITE>();

while (attacksTo) {
int8_t index = bitscanForward(attacksTo);

PieceType pieceOnSquare = bitboard.getPieceOnSquare(index);

switch (pieceOnSquare) {
case PieceType::BLACK_BISHOP:
evalContext.blackMidgameScore += getEvalValue(MIDGAME_BISHOP_ATTACK_NEAR_KING);
evalContext.blackEndgameScore += getEvalValue(ENDGAME_BISHOP_ATTACK_NEAR_KING);
break;
case PieceType::BLACK_ROOK:
evalContext.blackMidgameScore += getEvalValue(MIDGAME_ROOK_ATTACK_NEAR_KING);
evalContext.blackEndgameScore += getEvalValue(ENDGAME_ROOK_ATTACK_NEAR_KING);
break;
case PieceType::BLACK_QUEEN:
evalContext.blackMidgameScore += getEvalValue(MIDGAME_QUEEN_ATTACK_NEAR_KING);
evalContext.blackEndgameScore += getEvalValue(ENDGAME_QUEEN_ATTACK_NEAR_KING);
break;
}

attacksTo &= ~(1ULL << index);
}

kingAttacks &= ~(1ULL << attackIndex);
}
}

void getWhiteConnectivityScore(EvalContext &evalContext, Bitboard &bitboard) {
Expand Down Expand Up @@ -1066,6 +1112,7 @@ namespace Zagreus {
uint64_t blackRookAttacks = 0;
uint64_t blackQueenAttacks = 0;
uint64_t attacksFrom[64] = { 0ULL };
uint64_t attacksTo[64] = { 0ULL };

while (whiteKnightBB) {
uint64_t index = bitscanForward(whiteKnightBB);
Expand All @@ -1074,6 +1121,12 @@ namespace Zagreus {
whiteKnightAttacks |= attacks;
attacksFrom[index] = attacks;

while (attacks) {
uint64_t attackIndex = bitscanForward(attacks);
attacksTo[attackIndex] |= (1ULL << index);
attacks &= ~(1ULL << attackIndex);
}

whiteKnightBB &= ~(1ULL << index);
}

Expand All @@ -1084,6 +1137,12 @@ namespace Zagreus {
blackKnightAttacks |= attacks;
attacksFrom[index] = attacks;

while (attacks) {
uint64_t attackIndex = bitscanForward(attacks);
attacksTo[attackIndex] |= (1ULL << index);
attacks &= ~(1ULL << attackIndex);
}

blackKnightBB &= ~(1ULL << index);
}

Expand All @@ -1094,6 +1153,12 @@ namespace Zagreus {
whiteBishopAttacks |= attacks;
attacksFrom[index] = attacks;

while (attacks) {
uint64_t attackIndex = bitscanForward(attacks);
attacksTo[attackIndex] |= (1ULL << index);
attacks &= ~(1ULL << attackIndex);
}

whiteBishopBB &= ~(1ULL << index);
}

Expand All @@ -1104,6 +1169,12 @@ namespace Zagreus {
whiteRookAttacks |= attacks;
attacksFrom[index] = attacks;

while (attacks) {
uint64_t attackIndex = bitscanForward(attacks);
attacksTo[attackIndex] |= (1ULL << index);
attacks &= ~(1ULL << attackIndex);
}

whiteRookBB &= ~(1ULL << index);
}

Expand All @@ -1114,6 +1185,12 @@ namespace Zagreus {
whiteQueenAttacks |= attacks;
attacksFrom[index] = attacks;

while (attacks) {
uint64_t attackIndex = bitscanForward(attacks);
attacksTo[attackIndex] |= (1ULL << index);
attacks &= ~(1ULL << attackIndex);
}

whiteQueenBB &= ~(1ULL << index);
}

Expand All @@ -1124,6 +1201,12 @@ namespace Zagreus {
blackBishopAttacks |= attacks;
attacksFrom[index] = attacks;

while (attacks) {
uint64_t attackIndex = bitscanForward(attacks);
attacksTo[attackIndex] |= (1ULL << index);
attacks &= ~(1ULL << attackIndex);
}

blackBishopBB &= ~(1ULL << index);
}

Expand All @@ -1134,6 +1217,12 @@ namespace Zagreus {
blackRookAttacks |= attacks;
attacksFrom[index] = attacks;

while (attacks) {
uint64_t attackIndex = bitscanForward(attacks);
attacksTo[attackIndex] |= (1ULL << index);
attacks &= ~(1ULL << attackIndex);
}

blackRookBB &= ~(1ULL << index);
}

Expand All @@ -1144,6 +1233,12 @@ namespace Zagreus {
blackQueenAttacks |= attacks;
attacksFrom[index] = attacks;

while (attacks) {
uint64_t attackIndex = bitscanForward(attacks);
attacksTo[attackIndex] |= (1ULL << index);
attacks &= ~(1ULL << attackIndex);
}

blackQueenBB &= ~(1ULL << index);
}

Expand All @@ -1157,24 +1252,21 @@ namespace Zagreus {
0,
0,
whitePawnAttacks,
whiteKnightAttacks,
whiteBishopAttacks,
whiteRookAttacks,
whiteQueenAttacks,
whiteCombinedAttacks,
blackPawnAttacks,
blackKnightAttacks,
blackBishopAttacks,
blackRookAttacks,
blackQueenAttacks,
blackCombinedAttacks,
{},
{}
};

for (int i = 0; i < 64; i++) {
context.attacksFrom[i] = attacksFrom[i];
}

for (int i = 0; i < 64; i++) {
context.attacksTo[i] = attacksTo[i];
}

return context;
}
}
Expand Down
Loading