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

            for (int i = 0; i < rayLen; ++i)
            {
                int square = ray[i];
                int dir    = StraightAttackLookup[Square.Ox88Dist(square, HomeSquare)];
                if ((PinStatus == PinStatus.None || PinCompatible(dir)) &&
                    AttackPathFree(dir, square))
                {
                    int castlingMask = 0;
                    if (HomeSquare == kingSide)
                    {
                        castlingMask = MovePackHelper.GetCastlingMerge(castlingMaskKing & (int)board.CastlingStatus);
                    }
                    if (HomeSquare == queenSide)
                    {
                        castlingMask = MovePackHelper.GetCastlingMerge(castlingMaskQueen & (int)board.CastlingStatus);
                    }
                    moves[start++] = MovePackHelper.Pack(HomeSquare, square) | castlingMask;
                }
            }
            return(start - begin);
        }
Exemplo n.º 2
0
        protected override int OnGetMoves(int start, int[] moves)
        {
            int castling = 0;

            castling = MovePackHelper.GetCastlingMerge(castlingMask & (int)board.CastlingStatus);
            int begin = start;

            foreach (int dest in rose)
            {
                if (Square.SquareValid(HomeSquare + dest) && (PinEscape(dest) || dest + HomeSquare == Checker.HomeSquare) && !board.InAttack(HomeSquare + dest, Owner))
                {
                    if (board.BoardArray[HomeSquare + dest] == null)
                    {
                        moves[start++] = MovePackHelper.Pack(HomeSquare, HomeSquare + dest) | castling;
                    }
                    else
                    if (IsEnemy(HomeSquare + dest))
                    {
                        moves[start++] = MovePackHelper.Pack(this, board.BoardArray[HomeSquare + dest]) | castling;
                    }
                }
            }

            if (CheckCount == 0)
            {
                // castlings
                if (0 != ((int)board.CastlingStatus & castlingKing) && CastlingKingSideFree && KingSideUnattacked())
                {
                    moves[start++] = MovePackHelper.Pack(HomeSquare, HomeSquare + EAST + EAST) | castling | MovePackHelper.Castling;
                }
                if (0 != ((int)board.CastlingStatus & castlingQueen) && CastlingQueenSideFree && QueenSideUnattacked())
                {
                    moves[start++] = MovePackHelper.Pack(HomeSquare, HomeSquare + WEST + WEST) | castling | MovePackHelper.Castling;
                }
            }

            return(start - begin);
        }
Exemplo n.º 3
0
        protected override int OnGetCaptureMoves(int start, int[] moves, int square)
        {
            int dir = StraightAttackLookup[Square.Ox88Dist(square, HomeSquare)];

            if ((PinStatus == PinStatus.None || PinCompatible(dir)) &&
                AttackPathFree(dir, square) &&
                board.BoardArray[square] != null &&
                IsEnemy(square))
            {
                int castlingMask = 0;
                if (HomeSquare == kingSide)
                {
                    castlingMask = MovePackHelper.GetCastlingMerge(castlingMaskKing & (int)board.CastlingStatus);
                }
                if (HomeSquare == queenSide)
                {
                    castlingMask = MovePackHelper.GetCastlingMerge(castlingMaskQueen & (int)board.CastlingStatus);
                }
                moves[start++] = MovePackHelper.Pack(this, board.BoardArray[square]) | castlingMask;
                return(1);
            }

            return(0);
        }
Exemplo n.º 4
0
        protected override int OnGetCaptureMoves(int start, int[] moves, int square)
        {
            int rd = Square.Rank(square) - Square.Rank(HomeSquare);
            int cd = Square.Col(square) - Square.Col(HomeSquare);

            if (rd == -1)
            {
                rd *= -1;
            }
            if (cd == -1)
            {
                cd *= -1;
            }
            if (rd <= 1 && cd <= 1 && IsEnemy(square))
            {
                int castling = MovePackHelper.GetCastlingMerge(castlingMask & (int)board.CastlingStatus);
                if (!board.InAttack(square, Owner))
                {
                    moves[start++] = MovePackHelper.Pack(this, board.BoardArray[square]) | castling;
                    return(1);
                }
            }
            return(0);
        }
Exemplo n.º 5
0
        protected override int OnGetMoves(int start, int[] moves)
        {
            int begin = start;
            int sq;
            //NORTH
            int castlingMask = 0;

            if (HomeSquare == kingSide)
            {
                castlingMask = MovePackHelper.GetCastlingMerge(castlingMaskKing & (int)board.CastlingStatus);
            }
            if (HomeSquare == queenSide)
            {
                castlingMask = MovePackHelper.GetCastlingMerge(castlingMaskQueen & (int)board.CastlingStatus);
            }
            if (PinStatus == PinStatus.None || (PinStatus & PinStatus.NS) != 0)
            {
                sq = HomeSquare;
                while (Square.SquareValid(sq + NORTH))
                {
                    sq += NORTH;
                    if (board.BoardArray[sq] == null)
                    {
                        moves[start++] = MovePackHelper.Pack(HomeSquare, sq) | castlingMask;
                    }
                    else
                    {
                        if (IsEnemy(sq))
                        {
                            moves[start++] = MovePackHelper.Pack(this, board.BoardArray[sq]) | castlingMask;
                        }
                        break;
                    }
                }
            }
            //WEST
            if (PinStatus == PinStatus.None || (PinStatus & PinStatus.WE) != 0)
            {
                sq = HomeSquare;
                while (Square.SquareValid(sq + WEST))
                {
                    sq += WEST;
                    if (board.BoardArray[sq] == null)
                    {
                        moves[start++] = MovePackHelper.Pack(HomeSquare, sq) | castlingMask;
                    }
                    else
                    {
                        if (IsEnemy(sq))
                        {
                            moves[start++] = MovePackHelper.Pack(this, board.BoardArray[sq]) | castlingMask;
                        }
                        break;
                    }
                }
            }
            //SOUTH
            if (PinStatus == PinStatus.None || (PinStatus & PinStatus.NS) != 0)
            {
                sq = HomeSquare;
                while (Square.SquareValid(sq + SOUTH))
                {
                    sq += SOUTH;
                    if (board.BoardArray[sq] == null)
                    {
                        moves[start++] = MovePackHelper.Pack(HomeSquare, sq) | castlingMask;
                    }
                    else
                    {
                        if (IsEnemy(sq))
                        {
                            moves[start++] = MovePackHelper.Pack(this, board.BoardArray[sq]) | castlingMask;
                        }
                        break;
                    }
                }
            }
            //EAST
            if (PinStatus == PinStatus.None || (PinStatus & PinStatus.WE) != 0)
            {
                sq = HomeSquare;
                while (Square.SquareValid(sq + EAST))
                {
                    sq += EAST;
                    if (board.BoardArray[sq] == null)
                    {
                        moves[start++] = MovePackHelper.Pack(HomeSquare, sq) | castlingMask;
                    }
                    else
                    {
                        if (IsEnemy(sq))
                        {
                            moves[start++] = MovePackHelper.Pack(this, board.BoardArray[sq]) | castlingMask;
                        }
                        break;
                    }
                }
            }
            return(start - begin);
        }