private static bool IsAttackedByPawn( BoardSquare targetSquare, Board board, Player attacker) { var pawnAttackDeltaRow = attacker == Player.Black ? -1 : 1; var possiblePawnRow = targetSquare.Row - pawnAttackDeltaRow; if (possiblePawnRow < 0 || possiblePawnRow >= Board.RowCount) { return(false); } if (targetSquare.Column > 0) { var possiblePawnSquare = new BoardSquare( possiblePawnRow, targetSquare.Column - 1); if (IsAttackerPawnAt(possiblePawnSquare, attacker, board)) { return(true); } } if (targetSquare.Column + 1 < Board.ColumnCount) { var possiblePawnSquare = new BoardSquare( possiblePawnRow, targetSquare.Column + 1); if (IsAttackerPawnAt(possiblePawnSquare, attacker, board)) { return(true); } } return(false); }
private static bool IsAttackerPawnAt(BoardSquare square, Player player, Board board) { if (board.IsEmpty(square)) { return(false); } var pieceAtSquare = board.GetPieceAt(square); return(pieceAtSquare.player == player && pieceAtSquare.piece == Piece.Pawn); }
private static bool IsAllSquaresEmptyAlongBishopAttack( Bitmask64 targetBishopMovesBitmask, BoardSquare targetSquare, BoardSquare attackerSquare, long freeSquares) { long rayAttack = targetBishopMovesBitmask.Value & GetBitmaskInBetweenRows(targetSquare.Row, attackerSquare.Row).Value & GetBitmaskInBetweenColumns(targetSquare.Column, attackerSquare.Column).Value; return(rayAttack == (rayAttack & freeSquares)); }
private static bool IsBishopAttack( Bitmask64 targetBishopMovesBitmask, BoardSquare targetSquare, BoardSquare attackerSquare, long freeSquares) { if (!IsBishopDelta(new MoveDelta(targetSquare, attackerSquare))) { return(false); } return(IsAllSquaresEmptyAlongBishopAttack( targetBishopMovesBitmask, targetSquare, attackerSquare, freeSquares)); }
private static bool IsRookAttack( Bitmask64 targetRookMovesBitmask, BoardSquare targetSquare, BoardSquare attackerSquare, long freeSquares) { if (targetSquare.Row == attackerSquare.Row) { return(IsAllSquaresEmptyAlongHorizontalAttack( targetRookMovesBitmask, targetSquare.Column, attackerSquare.Column, freeSquares)); } else if (targetSquare.Column == attackerSquare.Column) { return(IsAllSquaresEmptyAlongVerticalAttack( targetRookMovesBitmask, targetSquare.Row, attackerSquare.Row, freeSquares)); } return(false); }
public static bool IsBoardSquareAttacked( BoardSquare targetSquare, Board board, Player attacker) { if (IsAttackedByPawn(targetSquare, board, attacker)) { return(true); } var targetBishopMovesBitmask = GetBishopBitmask(targetSquare); var targetRookMovesBitmask = GetRookBitmask(targetSquare); long freeSquares = ~board.OccupiedSquares.Value; foreach (var attackingPiece in board.GetPieces(attacker)) { switch (attackingPiece.piece) { case Piece.Pawn: // Already checked break; case Piece.Knight: { if (IsKnightDelta(new MoveDelta(targetSquare, attackingPiece.square))) { return(true); } } break; case Piece.Bishop: { if (IsBishopAttack( targetBishopMovesBitmask, targetSquare, attackingPiece.square, freeSquares)) { return(true); } } break; case Piece.Rook: { if (IsRookAttack( targetRookMovesBitmask, targetSquare, attackingPiece.square, freeSquares)) { return(true); } } break; case Piece.Queen: { if (IsBishopAttack( targetBishopMovesBitmask, targetSquare, attackingPiece.square, freeSquares)) { return(true); } if (IsRookAttack( targetRookMovesBitmask, targetSquare, attackingPiece.square, freeSquares)) { return(true); } } break; case Piece.King: { if (IsKingDelta(new MoveDelta(targetSquare, attackingPiece.square))) { return(true); } } break; } } return(false); }
private void MovePiece(BoardSquare originSquare, BoardSquare destSquare) { _pieceTable.MovePiece(originSquare.IntValue, destSquare.IntValue); _occupiedSquares.UnsetBit(originSquare.IntValue); _occupiedSquares.SetBit(destSquare.IntValue); }
public PieceOnBoard GetPieceAt(BoardSquare square) { return(_pieceTable.GetPieceAt(square.IntValue)); }
public bool IsEmpty(BoardSquare square) { return(!_occupiedSquares.IsBitSet(square.IntValue)); }