Example #1
0
            async void AddButtonReleased(ReleasedEventArgs obj)
            {
                IPathResult result = await MenuUIManager
                                     .FileBrowsingPopUp
                                     .Request(Game.Files.PackageDirectoryPath,
                                              SelectOption.File);

                if (result == null)
                {
                    return;
                }

                try {
                    var newPack = Game.PackageManager.AddGamePack(result.RelativePath);
                    AddItem(newPack);
                }
                catch (FatalPackagingException e) {
                    Game.ErrorExit(e.Message);
                }
                catch (ArgumentException e) {
                    await MenuUIManager.ErrorPopUp.DisplayError("Error", e.Message, proxy);
                }
                catch (PackageLoadingException e) {
                    await MenuUIManager.ErrorPopUp.DisplayError("Error", e.Message, proxy);
                }
            }
    public PathNodeGenerator(PathNodeGenerator node)
    {
        m_pathingData.CurrentPosition = node.m_pathingData.CurrentPosition;
        m_pathingData.FacingDir       = node.m_pathingData.FacingDir;
        m_pathingData.TargetLocation  = node.m_pathingData.TargetLocation;

        m_result = node.m_result;
    }
Example #3
0
        public IEnumerable <PlaceDto> GetBestRoute(string originName, string destinationName, string criteria)
        {
            if (string.IsNullOrEmpty(originName) && string.IsNullOrEmpty(destinationName))
            {
                throw new ArgumentException("The Origin and Destination are required fields.");
            }

            var origin      = _readUnit.ReadRepository <Place>().Get(x => x.Description.Equals(originName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
            var destination = _readUnit.ReadRepository <Place>().Get(x => x.Description.Equals(destinationName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

            if (origin == null)
            {
                throw new InvalidOperationException("The Origin provided does not exist.");
            }

            if (destination == null)
            {
                throw new InvalidOperationException("The Destination provided does not exist.");
            }

            //Retrieve filter criteria
            //if the passed criteria is null, the default value is Cost
            //if find a match will return a RouteCriteria type
            //if the passed value doesn't exist, will throw an exception
            RouteCriteria criteriaRoute = string.IsNullOrEmpty(criteria) ? RouteCriteria.Cost :
                                          RouteCriteria.FromDisplayName <RouteCriteria>(criteria);

            //retrieve routes and places from DB
            var routes = _readRepository.GetAllIncluding(x => x.Origin, x => x.Destination).ToList();
            var places = _readUnit.ReadRepository <Place>().GetAll().ToList();

            //create the graph network
            RoutingGraph <Place> graph = new RoutingGraph <Place>();

            places.ForEach(x => graph.AddNode(x));
            routes.ForEach(r => {
                int cost = RouteCriteria.Equals(criteriaRoute, RouteCriteria.Time) ? r.Time : r.Cost;
                graph.Connect(r.Origin, r.Destination, cost);
            });

            //processa o resultado
            var         processor = new RouteProcessor <Place>(graph);
            IPathResult result    = processor.Process(origin, destination);

            //build the result
            List <Place> resultados = new List <Place>();

            result.GetPath().ToList().ForEach(x => resultados.Add(graph[x].Item));
            return(resultados.EnumerableTo <PlaceDto>());
        }
Example #4
0
    private void FindPath(ref List <IPathResult> sequence, PathingData data)
    {
        List <HeuristicResult> results = new List <HeuristicResult>(m_generators.Count);

        foreach (var gen in m_generators)
        {
            gen.Initialise(data);
            float heuristicOuput = gen.Execute();

            results.Add(new HeuristicResult
            {
                HeuristicValue = heuristicOuput,
                Node           = gen
            });

            //This means we have found a perfect result.
            if (1.0f == heuristicOuput)
            {
                break;
            }
        }

        //sort by heuricitc
        results = results.OrderBy(r => r.HeuristicValue).ToList();
        //get the first value as this should be the best result.
        HeuristicResult res = results[0];

        IPathResult path = res.Node.Path;

        sequence.Add(path);

        //if we haven't reached our destination keep going.
        if (path.EndPoint != data.TargetLocation)
        {
            data.CurrentPosition = path.EndPoint;
            data.CurrentTime     = path.EndPointTime;
            data.FacingDir       = path.FacingDir;

            FindPath(ref sequence, data);
        }
    }
 public Path(IPathResult result)
 {
     m_result = result;
 }