From 887231df689e91c341a35868fd0b6d79d922fba9 Mon Sep 17 00:00:00 2001 From: rektdie Date: Mon, 24 Mar 2025 00:49:35 +0100 Subject: [PATCH] generating knight moves --- source/movegen.tpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/source/movegen.tpp b/source/movegen.tpp index b7d2456..44161ec 100644 --- a/source/movegen.tpp +++ b/source/movegen.tpp @@ -46,6 +46,7 @@ void GenPawnMoves(Board &board) { pushes.PopBit(pushSquare); } + pawns.PopBit(square); continue; } else { // Checking for en passant @@ -97,6 +98,47 @@ void GenPawnMoves(Board &board) { } template void GenKnightMoves(Board &board) { + Bitboard knights = board.colors[board.sideToMove] & board.pieces[Knight]; + + while (knights) { + int square = knights.getLS1BIndex(); + + Bitboard moves = knightAttacks[square] & ~board.colors[board.sideToMove]; + Bitboard captures = moves & board.colors[!board.sideToMove]; + + if constexpr (mode == Noisy) { + while (captures) { + int targetSquare = captures.getLS1BIndex(); + + board.AddMove(Move(square, targetSquare, capture)); + + captures.PopBit(targetSquare); + + captures.PopBit(targetSquare); + } + + knights.PopBit(square); + continue; + } else { + while (moves) { + int targetSquare = moves.getLS1BIndex(); + + board.AddMove(Move(square, targetSquare, quiet)); + + moves.PopBit(targetSquare); + } + + while (captures) { + int targetSquare = captures.getLS1BIndex(); + + board.AddMove(Move(square, targetSquare, capture)); + + captures.PopBit(targetSquare); + } + + knights.PopBit(square); + } + } } template void GenRookMoves(Board &board) {