Exemple #1
0
 private void GetChunkCoord(float x, float y, out int chunk_x, out int chunk_y)
 {
     // yeah, this is ugly. But safe
     for (chunk_x = 0; chunk_x < 64; chunk_x++)
     {
         float max_y = ChunkReader.ZEROPOINT - (chunk_x) * ChunkReader.TILESIZE;
         float min_y = max_y - ChunkReader.TILESIZE;
         if (y >= min_y - 0.1f && y < max_y + 0.1f)
         {
             break;
         }
     }
     for (chunk_y = 0; chunk_y < 64; chunk_y++)
     {
         float max_x = ChunkReader.ZEROPOINT - (chunk_y) * ChunkReader.TILESIZE;
         float min_x = max_x - ChunkReader.TILESIZE;
         if (x >= min_x - 0.1f && x < max_x + 0.1f)
         {
             break;
         }
     }
     if (chunk_y == 64 || chunk_x == 64)
     {
         PathGraph.Log(x + " " + y + " is at " + chunk_x + " " + chunk_y);
         //GetChunkCoord(x, y, out chunk_x, out chunk_y);
     }
 }
        public Path DoSearch(PathGraph.eSearchScoreSpot searchType)
        {
            //create a new path graph if required
            const int ResetAfterMinutes = 15;

            if (PathGraph == null || this.continent != locationFrom.Continent || (DateTime.Now - startTime).TotalMinutes >= ResetAfterMinutes)
            {
                CreatePathGraph(locationFrom.Continent);
            }

            PatherPath.Graph.PathGraph.SearchEnabled = true;

            // tell the pathgraph which type of search to do
            PathGraph.searchScoreSpot = searchType;

            //slow down the search if required.
            PathGraph.sleepMSBetweenSpots = 0;

            try
            {
                return(PathGraph.CreatePath(locationFrom, locationTo, 5, null));
            }
            catch (Exception ex)
            {
                logger.WriteLine(ex.Message);
                return(null);
            }
        }
Exemple #3
0
    public void InitializeStartingPath()
    {
        int seed = (int)(System.DateTime.Now - new System.DateTime(2017, 1, 1)).TotalSeconds;

        //int seed = 33923864;
        Random.InitState(seed);
        //Debug.Log(seed);

        PathGraph graph = FindObjectOfType <PathGraph>();

        if (graph.finishNode)
        {
            SetCoreMat(graph.finishNode.gameObject, coreMaterial);
        }
        PathGraph.RandomPath randomPath = graph.GetRandomPath(targetPathLength);
        graph.startNode  = randomPath.startNode;
        graph.finishNode = randomPath.finishNode;
        // Debug.Log("CanReachFinish: " + graph.CanReachFinish());
        // Debug.Log("pathEdges: " + randomPath.pathEdges.Count);
        foreach (PathEdge edge in graph.edges)
        {
            edge.tendril.gameObject.SetActive(true);
            edge.tendril.SetTraversable(false);
        }

        foreach (PathEdge edge in randomPath.pathEdges)
        {
            edge.tendril.SetTraversable(true);
        }

        SetCoreMat(graph.finishNode.gameObject, finishLineCoreMaterial);

        EventBus.PublishEvent(new GraphConfiguredEvent(graph));
    }
        /// <summary>
        /// Breeds two parent path individuals to create an offspring path individual.
        /// </summary>
        /// <param name="firstParent">The first path individual to breed with second path individual .</param>
        /// <param name="secondParent">The second path individual to breed with first path individual.</param>
        /// <returns>Offspring path individual of specified parents.</returns>
        public static PathGraph Crossover(PathGraph firstParent, PathGraph secondParent)
        {
            // Use Crossover rate
            if (ThreadSafeRandom.CurrentThreadsRandom.NextDouble() < CrossoverRate)
            {
                switch (CrossoverOperator)
                {
                case CrossoverOperator.Default:
                    return(DefaultCrossover(firstParent, secondParent));

                case CrossoverOperator.CycleCrossover:
                    PathGraph[] Child = CycleCrossover(firstParent, secondParent);
                    if (Child[0].Distance < Child[1].Distance)
                    {
                        return(Child[0]);
                    }

                    return(Child[1]);

                default:
                    return(null);
                }
            }
            else
            {
                if (firstParent.Distance < secondParent.Distance)
                {
                    return(firstParent);
                }

                return(secondParent);
            }
        }
        public override GameState Operate(GameState currentState)
        {
            GameState newState = currentState.Copy();
            IEnumerable <PathGraphVertex> path = PathGraph.FindShortestPath(currentState.Position, Game.Player.Position, false);
            float length   = PathGraph.GetLengthOfPath(path);
            float duration = length / Human.RunSpeed;

            newState.AddTime(TimeSpan.FromSeconds(duration));
            newState.Position = Game.Player.Position;
            newState.Damage  -= Game.Player.Health;
            newState.Health  -= Game.Player.Health * 0.9f;
            bool one = false;

            for (int i = 0; i < newState.QuarterStates.Length; i++)
            {
                if (newState.QuarterStates[i].Ownership == QuarterOwnership.His)
                {
                    if (one)
                    {
                        newState.QuarterStates[i].Ownership         = QuarterOwnership.Empty;
                        newState.QuarterStates[i].OwnershipDuration = TimeSpan.Zero;
                    }
                    one = true;
                }
            }
            return(newState);
        }
Exemple #6
0
    public Vector3 GetTrapPosition()
    {
        float          t     = connection.GetInterpolationAmount();
        PathGraph      graph = FindObjectOfType <PathGraph>();
        PathEdge       edge  = graph.tendrilToEdge[tendril];
        PathNeuronNode start = connection.node1.GetComponent <PathNeuronNode>();

        return(edge.GetPointAlongPath(start, t));
    }
Exemple #7
0
 /// <summary>
 /// Recomputes the waypoints according to path graph to get to the task target.
 /// </summary>
 /// <param name="from">Start position</param>
 /// <param name="to">Destination position</param>
 protected void RecomputeWaypoints(PositionInTown from, PositionInTown to)
 {
     wayPoints.Clear();
     foreach (PathGraphVertex v in PathGraph.FindShortestPath(from, to, !(holder is Opponent)))
     {
         wayPoints.Enqueue(new WayPoint(v.Position));
     }
     wayPoints.Enqueue(new WayPoint(to));
 }
Exemple #8
0
 public EasyMover(PPather pather, Location target, bool GiveUpIfStuck, bool GiveUpIfUnsafe)
 {
     this.target         = target;
     this.Me             = BoogieCore.Player;
     this.world          = pather.world;
     mover               = PPather.mover;
     this.GiveUpIfStuck  = GiveUpIfStuck;
     this.GiveUpIfUnsafe = GiveUpIfUnsafe;
     this.pather         = pather;
 }
Exemple #9
0
        /// <summary>
        /// Breeds two parent path individuals to create an offspring path individual.
        /// </summary>
        /// <param name="firstParent">The first path individual to breed with second path individual .</param>
        /// <param name="secondParent">The second path individual to breed with first path individual.</param>
        /// <returns>Offspring path individual of specified parents.</returns>
        public static PathGraph Crossover(PathGraph firstParent, PathGraph secondParent)
        {
            int CircuitLength = Input.Size + 1;

            // Create new child path
            PathGraph ChildPath = new PathGraph(CircuitLength, Input);

            ChildPath[0] = Input[0];
            ChildPath[CircuitLength - 1] = Input[0];

            // Get random start and end indices positions for firstParent
            int StartPos = ThreadSafeRandom.CurrentThreadsRandom.Next(1, CircuitLength - 1);
            int EndPos   = ThreadSafeRandom.CurrentThreadsRandom.Next(1, CircuitLength - 1) + ThreadSafeRandom.CurrentThreadsRandom.Next(1, CircuitLength - 1);

            // Loop and add the sub tour from firstParent to our child
            for (int i = 1; i < CircuitLength - 1; ++i)
            {
                // If our start position is less than the end position
                if (StartPos < EndPos && i > StartPos && i < EndPos)
                {
                    ChildPath[i] = firstParent[i];
                }

                // If our start position is larger
                else if (StartPos > EndPos)
                {
                    //if (!(i < StartPos && i > EndPos))
                    if (i >= StartPos || i <= EndPos)
                    {
                        ChildPath[i] = firstParent[i];
                    }
                }
            }

            // Loop through parent2's path
            for (int i = 1; i < CircuitLength - 1; ++i)
            {
                // If child doesn't have the city add it
                if (!ChildPath.Contains(secondParent[i]))
                {
                    // Loop to find a spare position in the child's tour
                    for (int j = 1; j < CircuitLength - 1; ++j)
                    {
                        // Spare position found, add city
                        if (ChildPath[j] == null)
                        {
                            ChildPath[j] = secondParent[i];
                            break;
                        }
                    }
                }
            }

            return(ChildPath);
        }
Exemple #10
0
        public TriangleMatrix(TriangleCollection tc)
        {
            {
                DateTime pre = DateTime.Now;
                PathGraph.Log("Build hash  " + tc.GetNumberOfTriangles());
                matrix = new SparseFloatMatrix2D <List <int> >(resolution, tc.GetNumberOfTriangles());

                Vector vertex0;
                Vector vertex1;
                Vector vertex2;

                for (int i = 0; i < tc.GetNumberOfTriangles(); i++)
                {
                    tc.GetTriangleVertices(i,
                                           out vertex0.x, out vertex0.y, out vertex0.z,
                                           out vertex1.x, out vertex1.y, out vertex1.z,
                                           out vertex2.x, out vertex2.y, out vertex2.z);

                    float minx = Utils.min(vertex0.x, vertex1.x, vertex2.x);
                    float maxx = Utils.max(vertex0.x, vertex1.x, vertex2.x);
                    float miny = Utils.min(vertex0.y, vertex1.y, vertex2.y);
                    float maxy = Utils.max(vertex0.y, vertex1.y, vertex2.y);

                    Vector box_center;
                    Vector box_halfsize;
                    box_halfsize.x = resolution / 2;
                    box_halfsize.y = resolution / 2;
                    box_halfsize.z = 1E6f;

                    int startx = matrix.LocalToGrid(minx);
                    int endx   = matrix.LocalToGrid(maxx);
                    int starty = matrix.LocalToGrid(miny);
                    int endy   = matrix.LocalToGrid(maxy);

                    for (int x = startx; x <= endx; x++)
                    {
                        for (int y = starty; y <= endy; y++)
                        {
                            float grid_x = matrix.GridToLocal(x);
                            float grid_y = matrix.GridToLocal(y);
                            box_center.x = grid_x + resolution / 2;
                            box_center.y = grid_y + resolution / 2;
                            box_center.z = 0;
                            if (Utils.TestTriangleBoxIntersect(vertex0, vertex1, vertex2, box_center, box_halfsize))
                            {
                                AddTriangleAt(grid_x, grid_y, i);
                            }
                        }
                    }
                }
                DateTime post = DateTime.Now;
                TimeSpan ts   = post.Subtract(pre);
                PathGraph.Log("done " + maxAtOne + " time " + ts);
            }
        }
Exemple #11
0
    public void HandleLevelCreationStart(LevelCreationActuallyStartEvent e)
    {
        PathGraph graph = FindObjectOfType <PathGraph>();

        if (graph.finishNode != this)
        {
            GameManager.Instance.SetCoreMat(gameObject, GameManager.Instance.coreMaterial);
        }

        StartCoroutine(Util.DeferForOneFrame(InitializeUINode));
    }
Exemple #12
0
 public MoveAlonger(PPather pather, Path path)
 {
     this.Me    = BoogieCore.Player;
     this.path  = path;
     this.world = pather.world;
     mover      = PPather.mover;
     sd         = new StuckDetecter(pather, 1, 2);
     prev       = null;
     current    = path.GetFirst();
     next       = path.GetSecond();
 }
Exemple #13
0
        public override GameState Operate(GameState currentState)
        {
            IEnumerable <PathGraphVertex> path = PathGraph.FindShortestPath(currentState.Position, actionObject.Position, false);
            float     length   = PathGraph.GetLengthOfPath(path);
            GameState newState = currentState.Copy();
            float     duration = length / Human.RunSpeed;

            newState.AddTime(TimeSpan.FromSeconds(duration));
            newState.Position = actionObject.Position;
            return(newState);
        }
Exemple #14
0
        public bool AddArchive(string file)
        {
            var a = new Archive(GameDir + file, 0, 0);

            if (a.IsOpen())
            {
                archives.Add(a);
                PathGraph.Log("Add archive " + file);
                return(true);
            }
            return(false);
        }
Exemple #15
0
        public void CreatePathGraph(string continent)
        {
            MPQTriangleSupplier mpq = new MPQTriangleSupplier(this.logger);

            mpq.SetContinent(continent);
            var triangleWorld = new ChunkedTriangleCollection(512, this.logger);

            triangleWorld.SetMaxCached(512);
            triangleWorld.AddSupplier(mpq);
            PathGraph      = new PathGraph(continent, triangleWorld, null, this.logger);
            this.continent = continent;
        }
        public void FindNumsTest()
        {
            SquarePolygon centerWall = ((50, 50), 30);

            var graph = new PathGraph(100, 100);

            graph.AddWalls(centerWall);

            graph.FindNums((2, 2));

            Debug.WriteLine(graph.ToNums());
        }
Exemple #17
0
 public MoveAlonger(PPather pather, Path path)
 {
     this.Context = GContext.Main;
     this.Me      = Context.Me;
     this.path    = path;
     this.world   = PPather.world;
     mover        = PPather.mover;
     sd           = new StuckDetecter(pather, 1, 2);
     prev         = null;
     current      = path.GetFirst();
     next         = path.GetSecond();
 }
Exemple #18
0
        public Pather(string continent)
        {
            Continent = continent;
            var mpq = new MPQTriangleSupplier();

            mpq.SetContinent(continent);
            var triangleWorld = new ChunkedTriangleCollection(512);

            triangleWorld.SetMaxCached(64);
            triangleWorld.AddSupplier(mpq);
            PG = new PathGraph(continent, triangleWorld, null, (string s) => { Log.WriteLine(s); });
        }
Exemple #19
0
 public EasyMover(PPather pather, Location target, bool GiveUpIfStuck,
                  bool GiveUpIfUnsafe)
 {
     this.target         = target;
     this.Me             = GContext.Main.Me;
     this.Context        = GContext.Main;
     this.world          = PPather.world;
     mover               = PPather.mover;
     this.GiveUpIfStuck  = GiveUpIfStuck;
     this.GiveUpIfUnsafe = GiveUpIfUnsafe;
     this.pather         = pather;
 }
        private static PathGraph DefaultCrossover(PathGraph firstParent, PathGraph secondParent)
        {
            int CircuitLength = Input.Size + 1;

            // Create new child path
            PathGraph ChildPath = new PathGraph(CircuitLength, Input);

            ChildPath[0] = Input[0];
            ChildPath[CircuitLength - 1] = Input[0];

            // Get random start and end indices positions for firstParent
            int StartPos = ThreadSafeRandom.CurrentThreadsRandom.Next(1, CircuitLength - 1);
            int EndPos   = ThreadSafeRandom.CurrentThreadsRandom.Next(1, CircuitLength - 1) + ThreadSafeRandom.CurrentThreadsRandom.Next(1, CircuitLength - 1);

            // Iterate firstParent to add subset to the child
            for (int i = 1; i < CircuitLength - 1; ++i)
            {
                if (StartPos < EndPos && i > StartPos && i < EndPos)
                {
                    ChildPath[i] = firstParent[i];
                }

                else if (StartPos > EndPos)
                {
                    if (i >= StartPos || i <= EndPos)
                    {
                        ChildPath[i] = firstParent[i];
                    }
                }
            }

            // Iterate secondParent's vertices to fill the remaining vertices
            for (int i = 1; i < CircuitLength - 1; ++i)
            {
                // Add vertex if child does not contain it already
                if (!ChildPath.Contains(secondParent[i]))
                {
                    // Find an empty position in child
                    for (int j = 1; j < CircuitLength - 1; ++j)
                    {
                        // Add vertex to empty spot
                        if (ChildPath[j] == null)
                        {
                            ChildPath[j] = secondParent[i];
                            break;
                        }
                    }
                }
            }

            return(ChildPath);
        }
Exemple #21
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        PathGraph graph = target as PathGraph;

        if (GUILayout.Button("Create Node"))
        {
            PathNode node = graph.CreateRoot();
            node.transform.position    = graph.transform.position;
            Selection.activeGameObject = node.gameObject;
        }
    }
Exemple #22
0
        public static IPathSearch FromPoint(World world, MobileInfo mi, Actor self, CPos from, CPos target, bool checkForBlocked)
        {
            var graph = new PathGraph(CellInfoLayerManager.Instance.NewLayer(world.Map), mi, self, world, checkForBlocked);
            var search = new PathSearch(graph)
            {
                heuristic = DefaultEstimator(target)
            };

            if (world.Map.Contains(from))
                search.AddInitialCell(from);

            return search;
        }
Exemple #23
0
        public static IPathSearch FromPoints(World world, MobileInfo mi, Actor self, IEnumerable<CPos> froms, CPos target, bool checkForBlocked)
        {
            var graph = new PathGraph(CellInfoLayerManager.Instance.NewLayer(world.Map), mi, self, world, checkForBlocked);
            var search = new PathSearch(graph)
            {
                heuristic = DefaultEstimator(target)
            };

            foreach (var sl in froms.Where(sl => world.Map.Contains(sl)))
                search.AddInitialCell(sl);

            return search;
        }
Exemple #24
0
        internal void LoadPathing(string path)
        {
            mbBusy = true;
            mGraph = PathGraph.CreatePathGrid();

            mGraph.Load(path);

            mPathDraw.BuildDrawInfo(mGraph);

            mbBusy = false;

            Misc.SafeInvoke(ePickReady, true);
        }
    //find the best path through the map using the breadth first search algorithm
    private List <Vector3Int> FindBestPath(Vector2Int[] maze, Vector2Int root, Vector2Int goal)
    {
        PathGraph pathGraph = new PathGraph(maze, root, goal);

        //create queue and set it up
        Queue <PathNode> pathQueue = new Queue <PathNode>();

        pathGraph.RootNode.Visited = true;
        pathQueue.Enqueue(pathGraph.RootNode);

        PathNode currentNode = new PathNode(0, 0);

        //Debug.Log("start");

        while (pathQueue.Count > 0)
        {
            currentNode = pathQueue.Dequeue();
            //Debug.Log(currentNode + " : " + currentNode.NeighborNodes.Count);
            //foreach (PathNode testNode in currentNode.NeighborNodes)
            //{
            //    Debug.Log(testNode.BriefToString());
            //}

            if (currentNode == pathGraph.EndNode)
            {
                //change PathNodes to Vector2Ints
                List <Vector3Int> vector3Path = new List <Vector3Int>();

                do
                {
                    vector3Path.Insert(0, new Vector3Int(currentNode.Position[0], currentNode.Position[1], 0));
                    currentNode = currentNode.Parent;
                }while (currentNode != null);

                return(vector3Path);
            }

            foreach (PathNode neighbor in currentNode.NeighborNodes)
            {
                if (!neighbor.Visited)
                {
                    neighbor.Visited = true;
                    neighbor.Parent  = currentNode;
                    pathQueue.Enqueue(neighbor);
                }
            }
        }

        Debug.Log("queue reached 0 (this should never happen)");
        return(null);
    }
Exemple #26
0
    private void EnsureValid()
    {
        Graph = GetComponentInParent <PathGraph>();

        foreach (PathNode node in Next)
        {
            node.AddPrevious(this);
        }

        foreach (PathNode node in Previous)
        {
            node.AddNext(this);
        }
    }
        public void FindPathTest()
        {
            SquarePolygon pointToGo = ((11, 5), 2);
            SquarePolygon wall1     = ((19, 8), 4);
            SquarePolygon wall2     = ((11, 19), 4);
            SquarePolygon wall3     = ((23, 17), 4);

            var graph = new PathGraph(30, 30);

            graph.AddWalls(wall1, wall2, wall3);

            graph.FindPath(pointToGo);

            Debug.WriteLine(graph.ToPath());
        }
Exemple #28
0
        public static bool TestTriangleBoxIntersect(Vector vertex0, Vector vertex1, Vector vertex2,
                                                    Vector boxcenter, Vector boxhalfsize)
        {
            int i          = 0;
            var pcenter    = (float *)&boxcenter;
            var phalf      = (float *)&boxhalfsize;
            var ptriangle0 = (float *)&vertex0;
            var ptriangle1 = (float *)&vertex1;
            var ptriangle2 = (float *)&vertex2;

            //int triBoxOverlap(float boxcenter[3],float boxhalfsize[3],float triverts[3][3]);
            try
            {
                i = ccode.triBoxOverlap(pcenter, phalf, ptriangle0, ptriangle1, ptriangle2);
            }
            catch (Exception e)
            {
                PathGraph.Log("WTF " + e);
            }
            if (i == 1)
            {
                return(true);
            }
            return(false);

            /*
             * Vector min, max;
             * min.x = ((vertex0.x < vertex1.x && vertex0.x < vertex2.x) ? vertex0.x : ((vertex1.x < vertex2.x) ? vertex1.x : vertex2.x));
             * min.y = ((vertex0.y < vertex1.y && vertex0.y < vertex2.y) ? vertex0.y : ((vertex1.y < vertex2.y) ? vertex1.y : vertex2.y));
             * min.z = ((vertex0.z < vertex1.z && vertex0.z < vertex2.z) ? vertex0.z : ((vertex1.z < vertex2.z) ? vertex1.z : vertex2.z));
             *
             * max.x = ((vertex0.x > vertex1.x && vertex0.x > vertex2.x) ? vertex0.x : ((vertex1.x > vertex2.x) ? vertex1.x : vertex2.x));
             * max.y = ((vertex0.y > vertex1.y && vertex0.y > vertex2.y) ? vertex0.y : ((vertex1.y > vertex2.y) ? vertex1.y : vertex2.y));
             * max.z = ((vertex0.z > vertex1.z && vertex0.z > vertex2.z) ? vertex0.z : ((vertex1.z > vertex2.z) ? vertex1.z : vertex2.z));
             *
             * bool outside = false;
             * if (min.x > boxcenter.x + boxhalfsize.x) outside = true;
             * if (max.x < boxcenter.x - boxhalfsize.x) outside = true;
             *
             * if (min.y > boxcenter.y + boxhalfsize.y) outside = true;
             * if (max.y < boxcenter.y - boxhalfsize.y) outside = true;
             *
             * if (min.z > boxcenter.z + boxhalfsize.z) outside = true;
             * if (max.z < boxcenter.z - boxhalfsize.z) outside = true;
             *
             * return !outside;*/
        }
Exemple #29
0
        public TriangleQuadtree(TriangleCollection tc)
        {
            PathGraph.Log("Build oct " + tc.GetNumberOfTriangles());
            this.tc = tc;
            tc.GetBBox(out min.x, out min.y, out min.z,
                       out max.x, out max.y, out max.z);
            rootNode = new Node(this, min, max);

            var tlist = new SimpleLinkedList();

            for (int i = 0; i < tc.GetNumberOfTriangles(); i++)
            {
                tlist.AddNew(i);
            }
            rootNode.Build(tlist, 0);
            PathGraph.Log("done");
        }
        public void FindPathATest()
        {
            PointPolygon pointToGo = (11, 5);
            //SquarePolygon pointToGo = ((11, 5), 2);
            Index         pointA = (28, 10);
            SquarePolygon wall1  = ((19, 8), 4);
            SquarePolygon wall2  = ((11, 17), 4);
            SquarePolygon wall3  = ((23, 17), 4);

            var graph = new PathGraph(30, 30);

            graph.AddWalls(wall1, wall2, wall3);

            graph.FindPath1(pointToGo, pointA);

            Debug.WriteLine(graph.ToPath());
        }
        private static PathGraph[] CycleCrossover(PathGraph Parent1, PathGraph Parent2)
        {
            Mark[]    P1Marked = new Mark[Parent1.Count];
            Mark[]    P2Marked = new Mark[Parent1.Count];
            PathGraph Child1   = new PathGraph(Parent1.Count, Parent1.SupersetGraph);
            PathGraph Child2   = new PathGraph(Parent1.Count, Parent1.SupersetGraph);

            for (int i = 1; i < Parent1.Count - 1; ++i)
            {
                if (P1Marked[Parent1[i].Index].IsMarked == true)
                {
                    continue;
                }

                Graph.Vertex X1 = Parent1[i]; P1Marked[X1.Index].Set(true, i);
                Graph.Vertex X2 = Parent2[i]; P2Marked[X2.Index].Set(true, i);
                do
                {
                    X1 = Parent1[Parent1.IndexOf(X2)]; P1Marked[X1.Index].Set(true, i);
                    X2 = Parent2[Parent1.IndexOf(X2)]; P2Marked[X2.Index].Set(true, i);
                } while (X2 != Parent1[i]);
            }

            // Set initial and final vertices to 0
            Child1[0] = Parent1[0];
            Child2[0] = Parent1[0];
            Child1[Parent1.Count - 1] = Parent1[0];
            Child2[Parent1.Count - 1] = Parent1[0];

            // Fill the children from cycles detected above
            for (int i = 1; i < Parent2.Count - 1; ++i)
            {
                if (P1Marked[Parent1[i].Index].Order % 2 == 0)         // 1, 3, 5 - Cycles
                {
                    Child1[i] = Parent1[i];
                    Child2[i] = Parent2[i];
                }
                else                                            // 2, 4, 6 - Cycles
                {
                    Child1[i] = Parent2[i];
                    Child2[i] = Parent1[i];
                }
            }
            return(new PathGraph[] { Child1, Child2 });
        }
Exemple #32
0
    // Start is called before the first frame update
    void Start()
    {
        p0               = new Vector3Int((int)(backTilemap.origin.x), (int)(wallsTilemap.origin.y), 0);
        pathGraph        = new PathGraph(backTilemap.size.x, backTilemap.size.y, backTilemap.cellSize.x, p0, wallsTilemap);
        movePoint.parent = null; //prevent movepoint from moving as a child of player

        for (int x = 0; x < wallsTilemap.size.x; x++)
        {
            for (int y = 0; y < wallsTilemap.size.y; y++)
            {
                if (wallsTilemap.HasTile(new Vector3Int(x + p0.x, y + p0.y, 0)))
                {
                    //Debug.Log("INIT has tile " + new Vector3Int(x+p0.x, y+p0.y, 0));
                    Debug.DrawLine(new Vector3(x, y) + p0 + wallsTilemap.transform.position, new Vector3(x, y) + p0 + wallsTilemap.transform.position + 0.5f * Vector3.one, Color.blue, 200f, false);
                }
            }
        }
    }
Exemple #33
0
        public static IPathSearch FromPoints(World world, MobileInfo mi, Actor self, IEnumerable<CPos> froms, CPos target, bool checkForBlocked)
        {
            var graph = new PathGraph(LayerPoolForWorld(world), mi, self, world, checkForBlocked);
            var search = new PathSearch(graph)
            {
                heuristic = DefaultEstimator(target)
            };

            search.isGoal = loc =>
            {
                var locInfo = search.Graph[loc];
                return locInfo.EstimatedTotal - locInfo.CostSoFar == 0;
            };

            foreach (var sl in froms.Where(sl => world.Map.Contains(sl)))
                search.AddInitialCell(sl);

            return search;
        }
Exemple #34
0
        public static IPathSearch FromPoint(World world, MobileInfo mi, Actor self, CPos from, CPos target, bool checkForBlocked)
        {
            var graph = new PathGraph(LayerPoolForWorld(world), mi, self, world, checkForBlocked);
            var search = new PathSearch(graph)
            {
                heuristic = DefaultEstimator(target)
            };

            search.isGoal = loc =>
            {
                var locInfo = search.Graph[loc];
                return locInfo.EstimatedTotal - locInfo.CostSoFar == 0;
            };

            if (world.Map.Contains(from))
                search.AddInitialCell(from);

            return search;
        }
Exemple #35
0
 public static IPathSearch Search(World world, MobileInfo mi, Actor self, bool checkForBlocked, Func<CPos, bool> goalCondition)
 {
     var graph = new PathGraph(CellInfoLayerManager.Instance.NewLayer(world.Map), mi, self, world, checkForBlocked);
     var search = new PathSearch(graph);
     search.isGoal = goalCondition;
     search.heuristic = loc => 0;
     return search;
 }
Exemple #36
0
 public static IPathSearch Search(World world, MobileInfo mi, Actor self, bool checkForBlocked, Func<CPos, bool> goalCondition)
 {
     var graph = new PathGraph(LayerPoolForWorld(world), mi, self, world, checkForBlocked);
     var search = new PathSearch(graph);
     search.isGoal = goalCondition;
     search.heuristic = loc => 0;
     return search;
 }
Exemple #37
0
 public static IPathSearch Search(World world, MobileInfo mi, Actor self, bool checkForBlocked)
 {
     var graph = new PathGraph(CellInfoLayerManager.Instance.NewLayer(world.Map), mi, self, world, checkForBlocked);
     return new PathSearch(graph);
 }