Exemplo n.º 1
0
        public void CircumventWallCountTest()
        {
            var _smallPF   = new Pathfinding(_smallGraph);
            var bottomLeft = _smallGraph.Grid[0, 0];
            var topMiddle  = _smallGraph.Grid[2, 1];
            var pathAB     = _smallPF.AStar(bottomLeft, topMiddle);
            var pathBA     = _smallPF.AStar(topMiddle, bottomLeft);

            Assert.IsTrue(pathAB.Count == 3);
            Assert.IsTrue(pathBA.Count == 3);
        }
Exemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        Debug.Log("********************************* DEPTHWISE");
        List <Node> path = Pathfinding.DepthwiseSearch(start, end);

        for (int i = 0; i < path.Count; i++)
        {
            Debug.Log(path [i].transform.name);
        }



        Debug.Log("********************************* BREADTHWISE");

        path = Pathfinding.BreadthwiseSearch(start, end);
        for (int i = 0; i < path.Count; i++)
        {
            Debug.Log(path [i].transform.name);
        }



        Debug.Log("********************************* A*");

        path = Pathfinding.AStar(start, end);
        for (int i = 0; i < path.Count; i++)
        {
            Debug.Log(path [i].transform.name);
        }

        myPath      = new List <Node> (path);
        currentNode = 0;
    }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            List <Edge <Point> > edges = new List <Edge <Point> >()
            {
                new Edge <Point>(new Point(0, 0), new Point(0, 1), 1),
                new Edge <Point>(new Point(0, 1), new Point(0, 2), 1),
                new Edge <Point>(new Point(0, 2), new Point(0, 3), 10),
                new Edge <Point>(new Point(0, 3), new Point(0, 4), 1),
                new Edge <Point>(new Point(0, 4), new Point(0, 5), 1),
                new Edge <Point>(new Point(0, 5), new Point(0, 6), 1),

                new Edge <Point>(new Point(0, 2), new Point(1, 2), 1),
                new Edge <Point>(new Point(1, 2), new Point(2, 2), 1),
                new Edge <Point>(new Point(2, 2), new Point(3, 2), 1),
                new Edge <Point>(new Point(3, 2), new Point(4, 2), 1),
            };

            Point goal = new Point(0, 6);
            IEnumerable <Edge <Point> > search = Pathfinding <Point> .AStar(
                new Point(0, 0),
                goal,
                Edge <Point> .NeighborsFromAdyascenceMatrix(edges),
                Point.Dist(goal)
                );

            IEnumerable <double> weights = Edge <Point> .AccumulatedWeight(search);

            Console.WriteLine(":v");
        }
Exemplo n.º 4
0
    public void MoveTo()
    {
        path = Pathfinding.AStar(TileGenerator.map, position, target);
        //Debug.Log("Our path is this long: " + path.Count);

        //Debug.Log(dist[target]);
    }
Exemplo n.º 5
0
        public override void Execute()
        {
            LinkedList <Tile> path = Pathfinding.AStar(Mover, TargetTile, Mover.Session, PathfindingMode.FindClosestIfDirectIsImpossible);

            if (path != null)
            {
                Mover.MovementProgress = new MovementProgress(path);
            }
        }
Exemplo n.º 6
0
 private void beginChasingPlayer()
 {
     this.chasingPlayer = true;
     anim.SetBool("chasingPlayer", this.chasingPlayer);
     this.speed            = CHASING_SPEED;
     this.pathToPlayer     = Pathfinding.AStar(this.tileAt(), player.tileAt());
     this.playerLastSeenAt = player.tileAt();
     this.indexInPath      = 0;
 }
Exemplo n.º 7
0
        public void StraightLightCountTest()
        {
            Node bottomLeft  = _graph.Grid[0, 0];
            Node bottomRight = _graph.Grid[0, 15];
            var  path        = _pathfinder.AStar(bottomLeft, bottomRight);

            Console.WriteLine("Path count : {0}", path.Count);
            Assert.IsTrue(path.Count == 15);
        }
Exemplo n.º 8
0
        public override void Run()
        {
            Init();
            var startPos = _grid[0, 0];

            _steering.SetCourseToNode(startPos);


            var currentTime = EventTime;

            while (_running)
            {
                if (_commissioner.found)
                {
                    if (_path.Count == 0 && _commissioner.velocity < 0.0001)
                    {
                        var newGoal = new Node(_commissioner.position);
                        if (newGoal != _goal)                         // in case
                        {
                            _goal = newGoal;
                            _path = _pathfinding.AStar(PositionNode, _goal);
                        }
                    }

                    //while we have a goal and we have not reached it
                    if (!ReferenceEquals(_goal, null) && !ArrivedAtNode(_goal))
                    {
                        if (ArrivedAtNode(_currentTargetNode))
                        {
                            // get the next step
                            Console.WriteLine("Path nodes remaining: {0}", _path.Count);
                            _currentTargetNode = _path.Pop();
                        }
                        if (EventTime > currentTime)
                        {
                            _steering.Seek(_currentTargetNode);
                            currentTime = EventTime;
                        }
                    }
                }

                // Scan at all times
                if (Math.Abs(RadarTurnRemaining) < 0.0001)
                {
                    SetTurnRadarRightRadians(double.PositiveInfinity);
                }

                try{
                    Execute();
                }
                catch (Exception e) {
                    Console.WriteLine("Execute() failed: {0}", e.Message);
                    _running = false;
                }
            }
        }
Exemplo n.º 9
0
    private bool playerIsNearby()
    {
        List <Tile> pathToPlayer = Pathfinding.AStar(this.getTileAt(), player.getTileAt());

        if (pathToPlayer != null && pathToPlayer.Count <= 8)
        {
            return(true);
        }
        return(false);
    }
Exemplo n.º 10
0
    public List <Vector3> AStarPathfinder(Vector3 start, Vector3 end)
    {
        if (Utilities.ValidatePosition(end) == true)
        {
            return(Pathfinding.AStar(start, end));
        }

        Debug.Log("End position is not valid");
        return(null);
    }
Exemplo n.º 11
0
    // Start is called before the first frame update
    void Start()
    {
        //List<Waypoint> path = Pathfinding.Breadthwise(start, end);
        //List<Waypoint> path = Pathfinding.Depthwise(start, end);
        List <Waypoint> path = Pathfinding.AStar(start, end);

        foreach (Waypoint w in path)
        {
            Debug.Log(w.transform.name);
        }
    }
Exemplo n.º 12
0
    public void beginPatrolling(int delta)
    {
        this.chasingPlayer = false;
        if (anim != null)
        {
            anim.SetBool("chasingPlayer", this.chasingPlayer);
        }
        Tile currentPosition = this.tileAt();

        this.pathDestination = Tile.getRandomFloorTile(currentPosition, delta);
        this.path            = Pathfinding.AStar(currentPosition, pathDestination);
        this.indexInPath     = 0;
        this.direction       = 1;
        this.speed           = DEFAULT_SPEED;
    }
Exemplo n.º 13
0
 void PathFinder()
 {
     //Quand on clic sur une thuile, on appel la fonction Astar et on allume les thuile
     //On indique le nombre de tours pour s<y rendre
     //seulement si cest le tour du joueur
     if (GameController.TM.IsPlayerTurn)
     {
         //Allume toutes les tiles sur le chemin
         Path.Clear();
         //List des Actions (from,to)
         foreach (TileInfo ti in GameController.GM.mapinfo)
         {
             GameController.GM.VisualUpdate(ti);
             ti.MyVisual.GetComponentInChildren <TextMesh>().text = "";
         }
         int Distance = 0;
         foreach (Action a in PF.AStar(GameController.GM.mapGOtoTI[MyTile], GameController.GM.mapGOtoTI[TileClicked]))
         {
             Distance++;
             if (Distance <= 5)
             {
                 a.To.MyVisual.GetComponentInChildren <TextMesh>().text = "1";
                 GameController.GM.mapTItoGO[a.To].GetComponentInChildren <MeshRenderer>().material = DistanceColor[0];
                 Path.Add(a);
             }
             else if (Distance <= 10)
             {
                 a.To.MyVisual.GetComponentInChildren <TextMesh>().text = "2";
                 GameController.GM.mapTItoGO[a.To].GetComponentInChildren <MeshRenderer>().material = DistanceColor[1];
             }
             else
             {
                 a.To.MyVisual.GetComponentInChildren <TextMesh>().text = ((int)((Distance + 0.5f) / 5)).ToString();
                 GameController.GM.mapTItoGO[a.To].GetComponentInChildren <MeshRenderer>().material = DistanceColor[2];
             }
         }
         if (Path.Count == 1)
         {
             if (Path[0].To == Path[0].From)
             {
                 clicCount = 0;
             }
         }
     }
 }
Exemplo n.º 14
0
    /// <summary>
    /// Returns the path from the character's current hex to the goal hex.
    /// </summary>
    /// <param name="goal">The goal of the path.</param>
    /// <returns></returns>
    public List <Hex> GetPath(Hex goal)
    {
        // Find the path to the goal.
        HexNode    goalNode = map[goal.position];
        List <Hex> path     = new List <Hex>();

        foreach (HexNode hexNode in Pathfinding.AStar(map[character.location.position], goalNode).Cast <HexNode>())
        {
            path.Add(hexNode.hex);
        }

        // Reset the search graph so it can be cleanly searched again.
        foreach (HexNode hexNode in map.Values)
        {
            hexNode.Reset();
        }

        // Return the path.
        return(path);
    }
Exemplo n.º 15
0
 void Update()
 {
     if (target)
     {
         // If there is a path and a current place to move towards
         if (followingPath)
         {
             // set speed for the frame
             float step = (speed * speedMod) * Time.deltaTime;
             if (Vector3.Distance(transform.position, current) > step + 0.05f)
             {
                 // move toward node if far enough and if it's set
                 transform.position = Vector3.MoveTowards(transform.position, current, step);
             }
             else
             {
                 // Pull next node from path if close enough or stop path if no more nodes
                 if (path.Count > 0)
                 {
                     current = path.Dequeue();
                 }
                 else
                 {
                     followingPath = false;
                 }
             }
         }
         else
         {
             if (Vector3.Distance(transform.position, target.transform.position) > 3)
             {
                 newPath = Pathfinding.AStar(transform.position, target.transform.position, PathGrid.nodes, includeDiagonals);
                 foreach (var node in newPath)
                 {
                     path.Enqueue(node);
                 }
                 followingPath = true;
             }
         }
     }
 }
Exemplo n.º 16
0
    public static Queue <Hex> FindPath(HexMap world, Hex start, Hex end)
    {
        Pathfinding pathfinder = new Pathfinding(world, start, end);

        return(pathfinder.AStar());
    }
Exemplo n.º 17
0
 // Start is called before the first frame update
 // Update is called once per frame
 void FixedUpdate()
 {
     transform.position += new Vector3(Input.GetAxis("Horizontal") * speed * Time.deltaTime, Input.GetAxis("Vertical") * speed * Time.deltaTime, 0f);
     pf.AStar(transform.position.x, transform.position.y, target.position.x, target.position.y);
 }