Пример #1
0
        public static int CalculateMoveCost(IMaybe <LocationCandiate> parent, Vector location)
        {
            var parentCost = parent.Select(x => x._currentCost).OrElse(0);

            var moveCost = parent
                           .Select(x => (int)(x.Location.DistanceFrom(location) * DistanceMultiplier))
                           .OrElse(0);

            return(parentCost + moveCost);
        }
Пример #2
0
 public static IMaybe <U> Apply <T, U>(this IMaybe <Func <T, U> > func, IMaybe <T> m)
 {
     if (func.HasValue)
     {
         return(m.Select(func.Value));
     }
     else
     {
         return(None <U>());
     }
 }
Пример #3
0
            public T this[int index]
            {
                get
                {
                    Debug.Assert(index >= 0);

                    return(_buffer
                           .Select(buffer => buffer[index])
                           .OrElse(() => _source[index]));
                }
            }
Пример #4
0
        public static IMaybe <Path> FindRoute(
            this Vector start, Vector target,
            Func <Vector, bool> isValidMove,
            IMaybe <int> breakSize)
        {
            Debug.Assert(isValidMove != null);

            if (start == target)
            {
                return(Maybe <Path> .None);
            }

            var lists = RouteFinderLists
                        .Create()
                        .Open(LocationCandiate.Create(target, start));

            while (lists.HasOpenCandidates)
            {
                // Capture to stop access modified closure
                var closedList = lists.ClosedList;
                if (breakSize.Select(x => x < closedList.Count).OrElse(false))
                {
                    break;
                }

                var currentNode = lists.NextOpenCandiate;

                if (currentNode.Location == target)
                {
                    return(BuildActorPath(currentNode).ToSome());
                }

                lists = OpenCandidateMoves(
                    lists, currentNode, target, isValidMove);
            }

            return(Maybe <Path> .None);
        }
Пример #5
0
 public static IMaybe <TResult> Map <T, TResult>(
     this IMaybe <T> source,
     Func <T, TResult> selector)
 => source.Select(selector);
Пример #6
0
        public void Select_Theory(IMaybe <int> m1, Func <int, string> mapFn, object expectation)
        {
            var result = m1.Select(mapFn);

            Assert.Equal(expectation, result);
        }
Пример #7
0
 public static IMaybe <TResult> SelectMany <T, TResult>(
     this IMaybe <T> source,
     Func <T, IMaybe <TResult> > selector)
 {
     return(source.Select(selector).Flatten());
 }