Exemplo n.º 1
0
        public static IEnumerable <Move> GetLegalMoves(Color color, Board board)
        {
            foreach (int index in Board.Indexes)
            {
                Piece piece = board[index];
                if (!piece.IsPiece())
                {
                    continue;
                }

                if (piece.ToColor() != color)
                {
                    continue;
                }

                IEnumerable <int> movableRange = GetMovableRange(index, color, board);
                foreach (int candidate in Move.GetMovableIndexes(piece, index))
                {
                    if (piece.ToPieceType() == Piece.Knight)
                    {
                        Piece dest = board[candidate];
                        if (dest != Piece.Empty && dest.ToColor() == color)
                        {
                            continue;
                        }
                    }
                    else if (!movableRange.Contains(candidate))
                    {
                        continue;
                    }

                    yield return(new Move()
                    {
                        SrcIndex = index,
                        DstIndex = candidate,
                        PieceType = piece.ToPieceType(),
                        Promote = false
                    });

                    if ((color == Color.Black && Board.GetRank(candidate) <= 3) ||
                        (color == Color.White && Board.GetRank(candidate) >= 7))
                    {
                        yield return(new Move()
                        {
                            SrcIndex = index,
                            DstIndex = candidate,
                            PieceType = piece.ToPieceType(),
                            Promote = true
                        });
                    }
                }
            }
        }
Exemplo n.º 2
0
 private static bool CheckWhiteKnightDrop(int index)
 {
     return(Board.GetRank(index) < 8);
 }
Exemplo n.º 3
0
 private static bool CheckBlackKnightDrop(int index)
 {
     return(Board.GetRank(index) > 2);
 }
Exemplo n.º 4
0
 private static bool CheckWhitePawnLanceDrop(int index)
 {
     return(Board.GetRank(index) < 9);
 }
Exemplo n.º 5
0
 private static bool CheckBlackPawnLanceDrop(int index)
 {
     return(Board.GetRank(index) > 1);
 }