コード例 #1
0
        public override List <PieceMove> GetMovesMask(Board board, Point position)
        {
            List <PieceMove> ret    = new List <PieceMove>();
            BitBoard         locked = new BitBoard();

            board[position] = null;

            board.ForEach(
                (Piece piece) => piece.GetColour() != GetColour(),
                (Point point) => locked |= board[point].GetSeen(board, point));

            board[position] = this;

            IEnumerable <Point> kingMoves = GetSeen(board, position).GetAllSet().Where(kingMove => !locked[kingMove] && board[kingMove]?.GetColour() != GetColour());

            foreach (Point kingMove in kingMoves)
            {
                ret.Add(new PieceMove(new Vector(position, kingMove), board[kingMove] == null? MoveType.Move : MoveType.Capture));
            }

            if (!board.GetHistory().Any(historicalMove => historicalMove.p2 == position))
            {
                foreach (CastelingMask mask in castelingMasks)
                {
                    if (!board.GetHistory().Any(historicalMove => historicalMove.p1 == new Point(mask.rookInitial, position.y)) && Extentions.Extentions.Enumerate(position.x, mask.kingFinal).All(kingMoveX => board.FindAttacks(GetColour(), new Point(kingMoveX, position.y)).Count() == 0) && Extentions.Extentions.Enumerate(mask.rookInitial, position.x).SubArray(1, 1).All(movedThrough => board[movedThrough, position.y] == null))
                    {
                        ret.Add(new PieceMove(new Vector(position, new Point(mask.kingFinal, position.y)), new Vector[] { new Vector(new Point(mask.rookInitial, position.y), new Point(mask.rookFinal, position.y)) }, MoveType.Move));
                    }
                }
            }

            return(ret);
        }