コード例 #1
0
    // Use this for initialization
    void Start()
    {
        // Testing graph functions
        // Reading
        Graph g = Graph.readFromFile("Assets/Graphs/graph2.txt");

        // Showing
        Debug.Log(g.toString());
        // A*
        PathVertexInfo aResult = g.aStar(0, 3);

        // Distance obtained by the A*
        Debug.Log("Distance to target: " + aResult.DistanceToVertex);
        // Showing the path found by A*
        List <PathVertexInfo> path = aResult.pathTo();
        string resPath             = "";

        foreach (PathVertexInfo v in path)
        {
            resPath += v.VertexIndex + " -> ";
        }
        Debug.Log(resPath);

        Map m = Map.readFromFile("Assets/Maps/map1.txt");

        Debug.Log(m.toString());
        //Debug.Log (m.getGraph.print());
    }
コード例 #2
0
 public List <PathVertexInfo> findPathDijkstra(Character enemy)
 {
     if (this.players.Count > 0)
     {
         PathVertexInfo targetPathInfo = this.graph.dijkstra(
             this.graphIndexFromTile(this.getCharacterPositionX(enemy), this.getCharacterPositionY(enemy)),
             this.graphIndexFromTile(this.getCharacterPositionX(this.players[0]), this.getCharacterPositionY(this.players[0])));
         if (targetPathInfo != null)
         {
             return(targetPathInfo.pathTo());
         }
     }
     return(null);
 }