diff --git a/source/board.cpp b/source/board.cpp index 2a9319e..97ba763 100644 --- a/source/board.cpp +++ b/source/board.cpp @@ -16,7 +16,6 @@ void Board::Reset() { colors = std::array(); moveList = std::array(); - attackMaps = std::array, 2>(); currentMoveIndex = 0; @@ -149,18 +148,12 @@ int Board::GetPieceColor(int square) { return (colors[Black].IsSet(square)); } -U64 Board::GetAttackMaps(bool side) { - U64 combined = 0ULL; - for (int type = Pawn; type <= King; type++) { - combined |= attackMaps[side][type]; - } - return combined; +bool Board::InCheck() { + // TODO } -bool Board::InCheck() { - Bitboard myKingSquare = colors[sideToMove] & pieces[King]; - - return GetAttackMaps(!sideToMove) & myKingSquare; +bool Board::IsLegal(Move &move) { + // TODO } void Board::SetPiece(int piece, int square, bool color) { diff --git a/source/board.h b/source/board.h index b823299..aad4225 100644 --- a/source/board.h +++ b/source/board.h @@ -18,8 +18,6 @@ public: std::array pieces; std::array colors; - std::array, 2> attackMaps; - //U64 attackMaps[2][64]; Bitboard occupied; @@ -44,9 +42,9 @@ public: int GetPieceType(int square); int GetPieceColor(int square); - - U64 GetAttackMaps(bool side); + bool InCheck(); + bool IsLegal(Move &move); void SetPiece(int piece, int square, bool color); void RemovePiece(int piece, int square, bool color); diff --git a/source/movegen.cpp b/source/movegen.cpp index 3ee4521..778b981 100644 --- a/source/movegen.cpp +++ b/source/movegen.cpp @@ -299,18 +299,6 @@ Bitboard getPawnPushes(int square, bool color, Bitboard &occupancy) { 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 static int GetDirection(int square, int target) { int rankDiff = (target / 8) - (square / 8); diff --git a/source/movegen.h b/source/movegen.h index 36758bc..d488044 100644 --- a/source/movegen.h +++ b/source/movegen.h @@ -21,6 +21,7 @@ Bitboard getBishopAttack(int square, U64 occupancy); Bitboard getRookAttack(int square, U64 occupancy); Bitboard getQueenAttack(int square, U64 occupancy); Bitboard getPawnPushes(int square, bool color, Bitboard &occupancy); +Bitboard getPieceAttacks(int square, int piece, int color, U64 occupancy); template void GenPawnMoves(Board &board); diff --git a/source/movegen.tpp b/source/movegen.tpp index 61d9255..4eb5c71 100644 --- a/source/movegen.tpp +++ b/source/movegen.tpp @@ -272,7 +272,7 @@ template void GenKingMoves(Board &board) { 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]; moves &= ~board.colors[!board.sideToMove]; @@ -313,8 +313,7 @@ void GenKingMoves(Board &board) { U64 QueenSide = board.sideToMove ? 0x1f00000000000000 : 0x1f; U64 mask = board.sideToMove ? 0x1c00000000000000 : 0x1c; int targetSquare = board.sideToMove ? c8 : c1; - if ((Bitboard(QueenSide) & board.occupied).PopCount() == 2 - && !(mask & board.GetAttackMaps(!board.sideToMove))) { + if ((Bitboard(QueenSide) & board.occupied).PopCount() == 2) { board.AddMove(Move(kingSquare, targetSquare, queenCastle)); } } @@ -323,8 +322,7 @@ void GenKingMoves(Board &board) { U64 KingSide = board.sideToMove ? 0xf000000000000000 : 0xf0; U64 mask = board.sideToMove ? 0x7000000000000000 : 0x70; int targetSquare = board.sideToMove ? g8 : g1; - if ((Bitboard(KingSide) & board.occupied).PopCount() == 2 - && !(mask & board.GetAttackMaps(!board.sideToMove))) { + if ((Bitboard(KingSide) & board.occupied).PopCount() == 2) { board.AddMove(Move(kingSquare, targetSquare, kingCastle)); } } diff --git a/source/perft.cpp b/source/perft.cpp index 9320e71..801c537 100644 --- a/source/perft.cpp +++ b/source/perft.cpp @@ -12,10 +12,9 @@ static U64 HelperPerft(Board board, int depth) { for (int i = 0; i < board.currentMoveIndex; i++) { Board copy = board; - board.MakeMove(board.moveList[i]); - nodes += HelperPerft(board, depth - 1); + copy.MakeMove(board.moveList[i]); + nodes += HelperPerft(copy, depth - 1); positionIndex--; - board = copy; } return nodes; } @@ -28,10 +27,9 @@ void Perft(Board &board, int depth) { Stopwatch sw; for (int i = 0; i < board.currentMoveIndex; i++) { Board copy = board; - board.MakeMove(board.moveList[i]); - U64 nodeCount = HelperPerft(board, depth - 1); + copy.MakeMove(board.moveList[i]); + U64 nodeCount = HelperPerft(copy, depth - 1); positionIndex--; - board = copy; totalNodes += nodeCount; board.moveList[i].PrintMove();