Pseudo legal #28

Merged
rektdie merged 14 commits from pseudoLegal into main 2025-03-25 14:16:56 +01:00
6 changed files with 14 additions and 38 deletions
Showing only changes of commit d0ba47c956 - Show all commits

No files matched your search

+4 -11
View File
@@ -16,7 +16,6 @@ void Board::Reset() {
colors = std::array<Bitboard, 2>(); colors = std::array<Bitboard, 2>();
moveList = std::array<Move, 218>(); moveList = std::array<Move, 218>();
attackMaps = std::array<std::array<U64, 64>, 2>();
currentMoveIndex = 0; currentMoveIndex = 0;
@@ -149,18 +148,12 @@ int Board::GetPieceColor(int square) {
return (colors[Black].IsSet(square)); return (colors[Black].IsSet(square));
} }
U64 Board::GetAttackMaps(bool side) { bool Board::InCheck() {
U64 combined = 0ULL; // TODO
for (int type = Pawn; type <= King; type++) {
combined |= attackMaps[side][type];
}
return combined;
} }
bool Board::InCheck() { bool Board::IsLegal(Move &move) {
Bitboard myKingSquare = colors[sideToMove] & pieces[King]; // TODO
return GetAttackMaps(!sideToMove) & myKingSquare;
} }
void Board::SetPiece(int piece, int square, bool color) { void Board::SetPiece(int piece, int square, bool color) {
+2 -4
View File
@@ -18,8 +18,6 @@ public:
std::array<Bitboard, 6> pieces; std::array<Bitboard, 6> pieces;
std::array<Bitboard, 2> colors; std::array<Bitboard, 2> colors;
std::array<std::array<U64, 64>, 2> attackMaps;
//U64 attackMaps[2][64];
Bitboard occupied; Bitboard occupied;
@@ -44,9 +42,9 @@ public:
int GetPieceType(int square); int GetPieceType(int square);
int GetPieceColor(int square); int GetPieceColor(int square);
U64 GetAttackMaps(bool side);
bool InCheck(); bool InCheck();
bool IsLegal(Move &move);
void SetPiece(int piece, int square, bool color); void SetPiece(int piece, int square, bool color);
void RemovePiece(int piece, int square, bool color); void RemovePiece(int piece, int square, bool color);
-12
View File
@@ -299,18 +299,6 @@ Bitboard getPawnPushes(int square, bool color, Bitboard &occupancy) {
return pushes; return pushes;
} }
// Returns bitboard of checkers
static Bitboard Checkers(Board &board, bool color) {
int kingSquare = (board.colors[color] & board.pieces[King]).getLS1BIndex();
Bitboard checkerBoard = 0ULL;
for (int type = Pawn; type < King; type++) {
Bitboard targets = getPieceAttacks(kingSquare, type, color, board.occupied);
checkerBoard |= targets & board.pieces[type] & board.colors[!color];
}
return checkerBoard;
}
// 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 rankDiff = (target / 8) - (square / 8); int rankDiff = (target / 8) - (square / 8);
+1
View File
@@ -21,6 +21,7 @@ Bitboard getBishopAttack(int square, U64 occupancy);
Bitboard getRookAttack(int square, U64 occupancy); Bitboard getRookAttack(int square, U64 occupancy);
Bitboard getQueenAttack(int square, U64 occupancy); Bitboard getQueenAttack(int square, U64 occupancy);
Bitboard getPawnPushes(int square, bool color, Bitboard &occupancy); Bitboard getPawnPushes(int square, bool color, Bitboard &occupancy);
Bitboard getPieceAttacks(int square, int piece, int color, U64 occupancy);
template <MovegenMode mode> template <MovegenMode mode>
void GenPawnMoves(Board &board); void GenPawnMoves(Board &board);
+3 -5
View File
@@ -272,7 +272,7 @@ template <MovegenMode mode>
void GenKingMoves(Board &board) { void GenKingMoves(Board &board) {
int kingSquare = (board.colors[board.sideToMove] & board.pieces[King]).getLS1BIndex(); int kingSquare = (board.colors[board.sideToMove] & board.pieces[King]).getLS1BIndex();
Bitboard moves = (kingAttacks[kingSquare] & ~board.GetAttackMaps(!board.sideToMove)) & ~board.colors[board.sideToMove]; Bitboard moves = (kingAttacks[kingSquare] & ~board.colors[board.sideToMove]);
Bitboard captures = moves & board.colors[!board.sideToMove]; Bitboard captures = moves & board.colors[!board.sideToMove];
moves &= ~board.colors[!board.sideToMove]; moves &= ~board.colors[!board.sideToMove];
@@ -313,8 +313,7 @@ void GenKingMoves(Board &board) {
U64 QueenSide = board.sideToMove ? 0x1f00000000000000 : 0x1f; U64 QueenSide = board.sideToMove ? 0x1f00000000000000 : 0x1f;
U64 mask = board.sideToMove ? 0x1c00000000000000 : 0x1c; U64 mask = board.sideToMove ? 0x1c00000000000000 : 0x1c;
int targetSquare = board.sideToMove ? c8 : c1; int targetSquare = board.sideToMove ? c8 : c1;
if ((Bitboard(QueenSide) & board.occupied).PopCount() == 2 if ((Bitboard(QueenSide) & board.occupied).PopCount() == 2) {
&& !(mask & board.GetAttackMaps(!board.sideToMove))) {
board.AddMove(Move(kingSquare, targetSquare, queenCastle)); board.AddMove(Move(kingSquare, targetSquare, queenCastle));
} }
} }
@@ -323,8 +322,7 @@ void GenKingMoves(Board &board) {
U64 KingSide = board.sideToMove ? 0xf000000000000000 : 0xf0; U64 KingSide = board.sideToMove ? 0xf000000000000000 : 0xf0;
U64 mask = board.sideToMove ? 0x7000000000000000 : 0x70; U64 mask = board.sideToMove ? 0x7000000000000000 : 0x70;
int targetSquare = board.sideToMove ? g8 : g1; int targetSquare = board.sideToMove ? g8 : g1;
if ((Bitboard(KingSide) & board.occupied).PopCount() == 2 if ((Bitboard(KingSide) & board.occupied).PopCount() == 2) {
&& !(mask & board.GetAttackMaps(!board.sideToMove))) {
board.AddMove(Move(kingSquare, targetSquare, kingCastle)); board.AddMove(Move(kingSquare, targetSquare, kingCastle));
} }
} }
+4 -6
View File
@@ -12,10 +12,9 @@ static U64 HelperPerft(Board board, int depth) {
for (int i = 0; i < board.currentMoveIndex; i++) { for (int i = 0; i < board.currentMoveIndex; i++) {
Board copy = board; Board copy = board;
board.MakeMove(board.moveList[i]); copy.MakeMove(board.moveList[i]);
nodes += HelperPerft(board, depth - 1); nodes += HelperPerft(copy, depth - 1);
positionIndex--; positionIndex--;
board = copy;
} }
return nodes; return nodes;
} }
@@ -28,10 +27,9 @@ void Perft(Board &board, int depth) {
Stopwatch sw; Stopwatch sw;
for (int i = 0; i < board.currentMoveIndex; i++) { for (int i = 0; i < board.currentMoveIndex; i++) {
Board copy = board; Board copy = board;
board.MakeMove(board.moveList[i]); copy.MakeMove(board.moveList[i]);
U64 nodeCount = HelperPerft(board, depth - 1); U64 nodeCount = HelperPerft(copy, depth - 1);
positionIndex--; positionIndex--;
board = copy;
totalNodes += nodeCount; totalNodes += nodeCount;
board.moveList[i].PrintMove(); board.moveList[i].PrintMove();