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); }
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>()); } }
public T this[int index] { get { Debug.Assert(index >= 0); return(_buffer .Select(buffer => buffer[index]) .OrElse(() => _source[index])); } }
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); }
public static IMaybe <TResult> Map <T, TResult>( this IMaybe <T> source, Func <T, TResult> selector) => source.Select(selector);
public void Select_Theory(IMaybe <int> m1, Func <int, string> mapFn, object expectation) { var result = m1.Select(mapFn); Assert.Equal(expectation, result); }
public static IMaybe <TResult> SelectMany <T, TResult>( this IMaybe <T> source, Func <T, IMaybe <TResult> > selector) { return(source.Select(selector).Flatten()); }