Exemplo n.º 1
0
        protected override int OnGetBlockingMoves(int start, int[] moves, int[] ray, int rayLen)
        {
            int begin = start;

            if ((PinStatus == PinStatus.None || (PinStatus & PinStatus.NS) != 0))
            {
                for (int i = 0; i < rayLen; ++i)
                {
                    int square = ray[i];
                    if (square - HomeSquare == oneStep)
                    {
                        moves[start++] = MovePackHelper.Pack(HomeSquare, square);
                        if (Square.Rank(square) == lastRank)
                        {
                            int prom = moves[start - 1];
                            moves[start - 1] |= MovePackHelper.GetPromotionMerge(PromotionTo.Queen);
                            moves[start++]    = prom | MovePackHelper.GetPromotionMerge(PromotionTo.Bishop);
                            moves[start++]    = prom | MovePackHelper.GetPromotionMerge(PromotionTo.Rook);
                            moves[start++]    = prom | MovePackHelper.GetPromotionMerge(PromotionTo.Knight);
                        }
                    }
                    if (Square.Rank(HomeSquare) == rankForEp && board.BoardArray[HomeSquare + oneStep] == null && square - HomeSquare == twoStep)
                    {
                        moves[start] = MovePackHelper.Pack(HomeSquare, square);
                        MovePackHelper.GetCleanedMove(moves[start]);
                        start++;
                    }
                }
            }
            return(start - begin);
        }
Exemplo n.º 2
0
        protected override int OnGetCaptureMoves(int start, int[] moves, int square)
        {
            int begin = start;

            if ((square - HomeSquare == diag1 || square - HomeSquare == diag2) &&
                IsEnemy(square) && PinCompatible(square - HomeSquare)
                )
            {
                moves[start++] = MovePackHelper.Pack(this, board.BoardArray[square]);

                if (Square.Rank(square) == lastRank)
                {
                    int prom = moves[start - 1];
                    moves[start - 1] |= MovePackHelper.GetPromotionMerge(PromotionTo.Queen);
                    moves[start++]    = prom | MovePackHelper.GetPromotionMerge(PromotionTo.Bishop);
                    moves[start++]    = prom | MovePackHelper.GetPromotionMerge(PromotionTo.Rook);
                    moves[start++]    = prom | MovePackHelper.GetPromotionMerge(PromotionTo.Knight);
                }
            }
            // ep.
            if (Square.Rank(HomeSquare) == rankForEpCapture)
            {
                if (HomeSquare + diag2 - oneStep == square)  // THE CAPTURED ep is the target square
                {
                    if (Square.SquareValid(HomeSquare + diag2) && HomeSquare + diag2 == board.EnPassant && PinCompatible(diag2) && board.CheckIfSafeEpCapture(Owner, HomeSquare))
                    {
                        moves[start++] = MovePackHelper.Pack(HomeSquare, HomeSquare + diag2) | MovePackHelper.EpFlag;
                    }
                }
                if (HomeSquare + diag1 - oneStep == square) // THE CAPTURED ep is the target square
                {
                    if (Square.SquareValid(HomeSquare + diag1) && HomeSquare + diag1 == board.EnPassant && PinCompatible(diag1) && board.CheckIfSafeEpCapture(Owner, HomeSquare))
                    {
                        moves[start++] = MovePackHelper.Pack(HomeSquare, HomeSquare + diag1) | MovePackHelper.EpFlag;
                    }
                }
            }
            return(start - begin);
        }
Exemplo n.º 3
0
        protected override int OnGetMoves(int start, int[] moves)
        {
            int begin = start;

            if (Square.Rank(HomeSquare) != lastRank && board.BoardArray[HomeSquare + oneStep] == null && (PinStatus == PinStatus.None || (PinStatus & PinStatus.NS) != 0))
            {
                moves[start++] = MovePackHelper.Pack(HomeSquare, HomeSquare + oneStep);
                if (Square.Rank(HomeSquare + oneStep) == lastRank)
                {
                    int prom = moves[start - 1];
                    moves[start - 1] |= MovePackHelper.GetPromotionMerge(PromotionTo.Queen);
                    moves[start++]    = prom | MovePackHelper.GetPromotionMerge(PromotionTo.Bishop);
                    moves[start++]    = prom | MovePackHelper.GetPromotionMerge(PromotionTo.Rook);
                    moves[start++]    = prom | MovePackHelper.GetPromotionMerge(PromotionTo.Knight);
                }
                if (Square.Rank(HomeSquare) == rankForEp && board.BoardArray[HomeSquare + twoStep] == null)
                {
                    moves[start] = MovePackHelper.Pack(HomeSquare, HomeSquare + twoStep);
                    MovePackHelper.GetCleanedMove(moves[start]);
                    start++;
                }
            }
            if (Square.Rank(HomeSquare) != lastRank)
            {
                if (PinStatus == PinStatus.None || (PinStatus & PinStatus.NS) == 0)
                {
                    if (Square.SquareValid(HomeSquare + diag1) && IsEnemy(HomeSquare + diag1) && PinCompatible(diag1))
                    {
                        moves[start++] = MovePackHelper.Pack(this, board.BoardArray[HomeSquare + diag1]);
                        if (Square.Rank(HomeSquare + diag1) == lastRank)
                        {
                            int prom = moves[start - 1];
                            moves[start - 1] |= MovePackHelper.GetPromotionMerge(PromotionTo.Queen);
                            moves[start++]    = prom | MovePackHelper.GetPromotionMerge(PromotionTo.Bishop);
                            moves[start++]    = prom | MovePackHelper.GetPromotionMerge(PromotionTo.Rook);
                            moves[start++]    = prom | MovePackHelper.GetPromotionMerge(PromotionTo.Knight);
                        }
                    }
                    if (Square.SquareValid(HomeSquare + diag2) && IsEnemy(HomeSquare + diag2) && PinCompatible(diag2))
                    {
                        moves[start++] = MovePackHelper.Pack(this, board.BoardArray[HomeSquare + diag2]);
                        if (Square.Rank(HomeSquare + diag2) == lastRank)
                        {
                            int prom = moves[start - 1];
                            moves[start - 1] |= MovePackHelper.GetPromotionMerge(PromotionTo.Queen);
                            moves[start++]    = prom | MovePackHelper.GetPromotionMerge(PromotionTo.Bishop);
                            moves[start++]    = prom | MovePackHelper.GetPromotionMerge(PromotionTo.Rook);
                            moves[start++]    = prom | MovePackHelper.GetPromotionMerge(PromotionTo.Knight);
                        }
                    }
                    // ep.
                    if (Square.Rank(HomeSquare) == rankForEpCapture)
                    {
                        if (Square.SquareValid(HomeSquare + diag2) && HomeSquare + diag2 == board.EnPassant && PinCompatible(diag2) && board.CheckIfSafeEpCapture(Owner, HomeSquare))
                        {
                            moves[start++] = MovePackHelper.Pack(HomeSquare, HomeSquare + diag2) | MovePackHelper.EpFlag;
                        }
                        if (Square.SquareValid(HomeSquare + diag1) && HomeSquare + diag1 == board.EnPassant && PinCompatible(diag1) && board.CheckIfSafeEpCapture(Owner, HomeSquare))
                        {
                            moves[start++] = MovePackHelper.Pack(HomeSquare, HomeSquare + diag1) | MovePackHelper.EpFlag;
                        }
                    }
                }
            }

            return(start - begin);
        }