void Start()
    {
        // A*
        dijkstra = new Dijkstra(width, height, depth, nodeSize, origin);

        // Create main camera
        Vector3 position = new Vector3(width * -6, height * 18, depth * -6);

        Instantiate(cam, position, cam.transform.rotation);

        grid = dijkstra.GetGrid();

        // Add walls manually
        dijkstra.GetNode(2, 2, 2).SetWalkable(!dijkstra.GetNode(2, 2, 2).isWalkable);

        // Draw walls
        DrawWalls();

        // Create visual nodes
        stepVisual.Setup(grid);

        // Show goal node
        Object.Instantiate(goalObject, grid.GetPosition(goalX, goalY, goalZ) + new Vector3(5, 5, 5), new Quaternion());
        Object.Instantiate(goalObject, grid.GetPosition(startX, startY, startZ) + new Vector3(5, 5, 5), new Quaternion());
    }
    void Start()
    {
        // A*
        aStar = new AStar(width, height, depth, nodeSize, origin);

        // Create main camera
        Vector3 position = new Vector3(width * -6, height * 18, depth * -6);

        Instantiate(cam, position, cam.transform.rotation);
        oldCam.enabled = false;
        control.SetupNewCamera();
        cam.enabled = true;

        grid = aStar.GetGrid();

        // Add walls manually
        //aStar.GetNode(5, 5, 5).SetWalkable(!aStar.GetNode(5, 5, 5).isWalkable);

        // Add weighted tiles manually
        aStar.GetNode(4, 4, 4).SetWeighted(!aStar.GetNode(4, 4, 4).isWeighted);
        aStar.GetNode(5, 5, 5).SetWeighted(!aStar.GetNode(5, 5, 5).isWeighted);
        aStar.GetNode(5, 5, 4).SetWeighted(!aStar.GetNode(5, 5, 4).isWeighted);
        aStar.GetNode(5, 4, 4).SetWeighted(!aStar.GetNode(5, 4, 4).isWeighted);
        aStar.GetNode(5, 4, 5).SetWeighted(!aStar.GetNode(5, 4, 5).isWeighted);
        aStar.GetNode(4, 4, 5).SetWeighted(!aStar.GetNode(4, 4, 5).isWeighted);
        aStar.GetNode(4, 5, 5).SetWeighted(!aStar.GetNode(4, 5, 5).isWeighted);
        aStar.GetNode(4, 5, 4).SetWeighted(!aStar.GetNode(4, 5, 4).isWeighted);

        // Draw walls
        DrawWalls();

        // Create visual nodes
        stepVisual.Setup(grid);

        // Show goal node
        Object.Instantiate(goalObject, grid.GetPosition(goalX, goalY, goalZ) + new Vector3(5, 5, 5), new Quaternion());
        Object.Instantiate(goalObject, grid.GetPosition(startX, startY, startZ) + new Vector3(5, 5, 5), new Quaternion());
    }
Exemplo n.º 3
0
    void SetupBFSearch()
    {
        bFSearch = new BFSearch(width, height, depth, nodeSize, origin);

        bFSearchGrid = bFSearch.GetGrid();

        // Add walls manually
        bFSearch.GetNode(2, 2, 0).SetWalkable(!bFSearch.GetNode(2, 2, 0).isWalkable);
        bFSearch.GetNode(2, 3, 0).SetWalkable(!bFSearch.GetNode(2, 3, 0).isWalkable);
        bFSearch.GetNode(2, 4, 0).SetWalkable(!bFSearch.GetNode(2, 4, 0).isWalkable);
        bFSearch.GetNode(3, 4, 0).SetWalkable(!bFSearch.GetNode(3, 4, 0).isWalkable);
        bFSearch.GetNode(4, 4, 0).SetWalkable(!bFSearch.GetNode(4, 4, 0).isWalkable);
        bFSearch.GetNode(5, 4, 0).SetWalkable(!bFSearch.GetNode(5, 4, 0).isWalkable);
        bFSearch.GetNode(6, 4, 0).SetWalkable(!bFSearch.GetNode(6, 4, 0).isWalkable);
        bFSearch.GetNode(6, 3, 0).SetWalkable(!bFSearch.GetNode(6, 3, 0).isWalkable);
        bFSearch.GetNode(6, 2, 0).SetWalkable(!bFSearch.GetNode(6, 2, 0).isWalkable);
        bFSearch.GetNode(1, 9, 0).SetWalkable(!bFSearch.GetNode(1, 9, 0).isWalkable);
        bFSearch.GetNode(1, 8, 0).SetWalkable(!bFSearch.GetNode(1, 8, 0).isWalkable);
        bFSearch.GetNode(3, 7, 0).SetWalkable(!bFSearch.GetNode(3, 7, 0).isWalkable);
        bFSearch.GetNode(4, 7, 0).SetWalkable(!bFSearch.GetNode(4, 7, 0).isWalkable);
        bFSearch.GetNode(5, 7, 0).SetWalkable(!bFSearch.GetNode(5, 7, 0).isWalkable);
        bFSearch.GetNode(6, 7, 0).SetWalkable(!bFSearch.GetNode(6, 7, 0).isWalkable);
        bFSearch.GetNode(7, 7, 0).SetWalkable(!bFSearch.GetNode(7, 7, 0).isWalkable);
        bFSearch.GetNode(8, 7, 0).SetWalkable(!bFSearch.GetNode(8, 7, 0).isWalkable);

        // Add weighted tiles manually
        bFSearch.GetNode(0, 4, 0).SetWeighted(!bFSearch.GetNode(0, 4, 0).isWeighted);
        bFSearch.GetNode(1, 4, 0).SetWeighted(!bFSearch.GetNode(1, 4, 0).isWeighted);

        // Draw walls
        for (int x = 0; x < bFSearchGrid.GetWidth(); x++)
        {
            for (int y = 0; y < bFSearchGrid.GetHeight(); y++)
            {
                for (int z = 0; z < bFSearchGrid.GetDepth(); z++)
                {
                    Node node = bFSearchGrid.GetGridObject(x, y, z);

                    // If the node is not walkable draw a wall
                    if (!node.isWalkable)
                    {
                        Object.Instantiate(wallObject, bFSearchGrid.GetPosition(x, y, z) + new Vector3(5, 5, 5), new Quaternion());
                    }

                    if (node.isWeighted)
                    {
                        Object.Instantiate(weightedObject, bFSearchGrid.GetPosition(x, y, z) + new Vector3(5, 5, 5), new Quaternion());
                    }
                }
            }
        }

        // Create visual nodes
        stepVisual.Setup(bFSearchGrid);

        // Show goal node
        Object.Instantiate(goalObject, bFSearchGrid.GetPosition(goalX, goalY, goalZ) + new Vector3(5, 5, 5), new Quaternion());
        Object.Instantiate(goalObject, bFSearchGrid.GetPosition(startX, startY, startZ) + new Vector3(5, 5, 5), new Quaternion());

        currentAlgorithm = "bFSearch";
    }