Esempio n. 1
0
    void OnGUI()
    {
        GameObject obj = Waypoints[0];

        if (CurrentWaypoint >= 0)
        {
            obj = Waypoints[CurrentWaypoint];
        }

        GUI.Box(new Rect(10, 10, 100, 110), "Guard's Orders");
        if (GUI.Button(new Rect(20, 40, 80, 20), "Patrol"))
        {
            CurrentWaypoint = 0;
            WaypointGraph.AStar(Waypoints[0], Waypoints[Waypoints.Count - 1]);
            animation.Play("run");
        }

        if (GUI.Button(new Rect(20, 60, 80, 20), "Doorway"))
        {
            WaypointGraph.AStar(obj, Doorway);
            animation.Play("run");
        }

        if (GUI.Button(new Rect(20, 80, 80, 20), "Driveway"))
        {
            WaypointGraph.AStar(obj, Driveway);
            animation.Play("run");
        }
    }
Esempio n. 2
0
 public void EnemyAI()
 {
     //int temp = Random.Range(0, waypoints.Length);
     //int temp = waypoints.Length - 1;
     Debug.Log("heee");
     if (currentNode == waypoints[1])
     {
         graph.AStar(currentNode, waypoints[7]);
         currentWaypoint = 0;
     }
     else if (currentNode == waypoints[7])
     {
         foreach (GameObject wall in gameManager.walls)
         {
             if (wall.name == "FirstWall1")
             {
                 wall.SetActive(true);
                 break;
             }
         }
         graph.AStar(currentNode, waypoints[11]);
         currentWaypoint = 0;
     }
     else if (currentNode == waypoints[11])
     {
         foreach (GameObject wall in gameManager.walls)
         {
             if (wall.name == "SecondWall2")
             {
                 wall.SetActive(true);
                 break;
             }
         }
         graph.AStar(currentNode, waypoints[17]);
         currentWaypoint = 0;
     }
     else if (currentNode == waypoints[17])
     {
         foreach (GameObject wall in gameManager.walls)
         {
             if (wall.name == "ThirdWall2")
             {
                 wall.SetActive(true);
                 break;
             }
         }
         graph.AStar(currentNode, waypoints[20]);
         currentWaypoint = 0;
     }
 }
Esempio n. 3
0
 public void SetDestination(GameObject city)
 {
     if (city.CompareTag("City"))
     {
         g.AStar(currentNode, city);
         currentWP = 0;
         Debug.Log(city.name + " is now the destination (" + g.getPathLength() + ")");
         //g.printPath();
     }
 }
 public static bool Dijkstra <V, E>(
     this Graph <V, E> graph,
     int from,
     int to,
     WeightCalculator <E> calculator,
     out GraphPath <V, E> path,
     ExplorationCallbacks <V, E> callbacks = default
     )
 {
     return(graph.AStar(from, to, ZeroHeuristics, calculator, out path, callbacks));
 }
Esempio n. 5
0
    public List <GameObject> GetPath(GameObject start, GameObject end)
    {
        var pathList = new List <GameObject>();

        graph.AStar(start, end);

        foreach (var node in graph.PathList)
        {
            pathList.Add(node.id);
        }

        return(pathList);
    }
Esempio n. 6
0
        private IWeighted <IEnumerable <char> > AStar(
            char start, char goal,
            Dictionary <char, IEnumerable <IWeighted <char> > > next,
            bool isConsistent, Dictionary <char, double> heuristic)
        {
            var descriptor = WeightedGraphDescriptor.Create(n => n, Function(next));

            return(Graph.AStar(
                       EnumerableEx.Return(new Weighted <char>(start, 0)),
                       descriptor.Key,
                       descriptor.Next,
                       n => n == goal,
                       Heuristic.Create(F(heuristic), isConsistent)));
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            Graph graph = new Graph();

            ReadFromFile("SpainMap.txt", graph);


            graph.GreedyBFS();


            Console.WriteLine();

            Console.WriteLine(" Results of Greedy BFS:");


            Node current = graph.Destination;

            while (current.cameFrom != current)
            {
                Console.WriteLine(" City name: " + current.cityName + " total cost: " + current.totalCost + " heruistic: " + current.heurisitc);
                current = current.cameFrom;
            }

            Console.WriteLine(" City name: " + current.cityName + " total cost: " + current.totalCost + " heruistic: " + current.heurisitc);


            graph.Clean();


            graph.AStar();

            Console.WriteLine();


            Console.WriteLine(" Results of Astar:");


            current = graph.Destination;
            while (current.cameFrom != current)
            {
                Console.WriteLine(" City name: " + current.cityName + " total cost: " + current.totalCost + " heruistic: " + current.heurisitc);
                current = current.cameFrom;
            }

            Console.WriteLine(" City name: " + current.cityName + " total cost: " + current.totalCost + " heruistic: " + current.heurisitc);
        }
        public long[] Solve(long nodeCount,
                            long edgeCount,
                            long[][] points,
                            long[][] edges,
                            long queriesCount,
                            long[][] queries)
        {
            Graph myGraph = new Graph(nodeCount, points);

            myGraph.BuildEdges(edgeCount, edges);
            long[] results = new long[queriesCount];
            for (int i = 0; i < queriesCount; i++)
            {
                results[i] = myGraph.AStar(queries[i][0], queries[i][1]);
            }
            return(results);
        }
Esempio n. 9
0
        private static int RootOfVertexInTree(Graph F, bool[] rootsF, int v)
        {
            Edge[] path;
            if (rootsF[v])
            {
                return(v);
            }

            for (int i = 0; i < rootsF.Length; i++)
            {
                if (rootsF[i] && F.AStar(v, i, out path))
                {
                    return(i);
                }
            }

            return(-1);
        }
Esempio n. 10
0
    ////////////////////////////////////////////////////////////////////////////////////


    // Update is called once per frame
    void Update()
    {
        if (Control.mouseclickControls)
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (playerScript)
                {
                    if (playerScript.SetTargetPosition(allNodes))
                    {
                        if (playerScript.currNode != null && playerScript.targetNode != null)
                        {
                            List <Node> path = g.AStar(playerScript.currNode, playerScript.targetNode);
                            // USE THAT TO DIRECT THE PATH OF THE CHARACTER
                            playerScript.WalkAlongPath(path);
                        }
                    }
                }
            }
        }
    }
Esempio n. 11
0
        private bool CheckIfPathExists(Graph g, int source, int target, out Edge[] path)
        {
            bool pathFound = false;

            //Predicate<int> beforeVisit = (int n) =>
            //{
            //    if (n == target)
            //    {
            //        pathFound = true;
            //        return false;
            //    }
            //    else
            //        return true;
            //};

            //g.DFSearchFrom(source, beforeVisit, null);

            pathFound = g.AStar(source, target, out path);

            return(pathFound);
        }
Esempio n. 12
0
        private static bool IsUnmarkedVertexInForestWithRootEvenDistance(Graph F, bool[] markedVertices, bool[] insideF, bool[] rootsF, out int v)
        {
            v = -1;

            for (int i = 0; i < F.VerticesCount; i++)
            {
                if (insideF[i] && !markedVertices[i])
                {
                    Edge[] path;
                    if (F.AStar(i, RootOfVertexInTree(F, rootsF, i), out path))
                    {
                        if (path.Length % 2 == 0)
                        {
                            v = i;
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Esempio n. 13
0
 public void gotToHeli()
 {
     g.AStar(currentNode, wps[9]);
     currentWP = 0;
 }
Esempio n. 14
0
 public void Goto(int valor)// gatilho que execulta uma ação, que seria se mover em um ponto denominado pela varial posta dentro do metodo que é  modificada qando se  poen dentor de um evento na unity
 {
     g.AStar(currentNode, wp[valor]);
     currentWP = 0;
 }
 public void GoToHeli()
 {
     graph.AStar(currentNode, wps[9]);
     currentWP = 0;
 }
Esempio n. 16
0
 public void GotoHeli()
 {
     g.AStar(currentNode, GetObjectFromGraph(HelipadPoint));
     currentWP = 0;
 }
Esempio n. 17
0
 public void GoToHeli()
 {
     g.AStar(currentNode, wps[1]);
     currentWP = 0;
 }
Esempio n. 18
0
 //Telling the Ai where to go
 public void GotoHeli()
 {
     //agent.SetDestination(wps[4].transform.position);
     g.AStar(currentNode, wps[11]);
     Currentwp = 0;
 }
Esempio n. 19
0
 public void GoToTwinMountains()
 {
     graph.AStar(currentNode, wps[4]);
     currentWaypointIndex = 0;
 }
Esempio n. 20
0
 public void GoToHelipad()
 {
     graph.AStar(currentNode, wps[1]);
     currentWaypointIndex = 0;
 }
Esempio n. 21
0
 public void GoToDestination()
 {
     g.AStar(currentNode, wps[3]);
     currentWpTracker = 0;
 }