コード例 #1
0
 // Use this for initialization
 void Start()
 {
     initMaze();
     hk = new HuntAndKill(mazeCells);
     hk.run(length, width, render);
     render = true;
 }
コード例 #2
0
        public void TestHuntAndKillColored()
        {
            var coloredGrid = new ColoredGrid(25, 25);

            HuntAndKill.On(coloredGrid);
            coloredGrid.Distances = coloredGrid.GetCenterCell().Distances;
            coloredGrid.ToBitmap().Save("huntandkill-colored.png");
        }
コード例 #3
0
        private static void ColorizeThetaMazes()
        {
            var grid = new ColoredPolarGrid(100);

            BinaryTree.Maze(grid);
            var start = grid[0, 0];

            grid.Distances = start.Distances;

            var img = grid.ToImg(25);

            img.Save("binaryTheta.png");

            grid = new ColoredPolarGrid(100);
            Sidewinder.Maze(grid);
            start          = grid[0, 0];
            grid.Distances = start.Distances;
            img            = grid.ToImg(25);
            img.Save("sidewinderTheta.png");

            grid = new ColoredPolarGrid(100);
            AldousBroder.Maze(grid);
            start          = grid[0, 0];
            grid.Distances = start.Distances;
            img            = grid.ToImg(25);
            img.Save("aldousBroderTheta.png");

            grid = new ColoredPolarGrid(100);
            HuntAndKill.Maze(grid);
            start          = grid[0, 0];
            grid.Distances = start.Distances;
            img            = grid.ToImg(25);
            img.Save("huntAndKillTheta.png");

            grid = new ColoredPolarGrid(100);
            RecursiveBacktracker.Maze(grid, startAt: null);
            start          = grid[0, 0];
            grid.Distances = start.Distances;
            img            = grid.ToImg(25);
            img.Save("recursiveBacktrackerTheta.png");

            grid = new ColoredPolarGrid(100);
            Wilsons.Maze(grid);
            start          = grid[0, 0];
            grid.Distances = start.Distances;
            img            = grid.ToImg(25);
            img.Save("wilsonsTheta.png");

            Process.Start("binaryTheta.png");
            Process.Start("sidewinderTheta.png");
            Process.Start("aldousBroderTheta.png");
            Process.Start("huntAndKillTheta.png");
            Process.Start("recursiveBacktrackerTheta.png");
            Process.Start("wilsonsTheta.png");
        }
コード例 #4
0
    protected override void UpdateAlgorithm()
    {
        switch (algorithmType)
        {
        case Algo.BinaryTree:
            MyGrid = new BinaryTree(width, height);
            break;

        case Algo.SideWinder:
            MyGrid = new SideWinder(width, height);
            break;

        case Algo.AldousBroder:
            MyGrid = new AldousBroder(width, height);
            break;

        case Algo.HuntAndKill:
            MyGrid = new HuntAndKill(width, height);
            break;

        case Algo.RecursiveBacktracker:
            MyGrid = new RecursiveBacktracker(width, height);
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }

        IWallInstantiable wall;

        if (is3d)
        {
            wall = new WallPrefab3d {
                WallPrefab = wallPrefab3d
            }
        }
        ;
        else
        {
            wall = new WallPrefab2d {
                WallPrefab = wallPrefab2d
            }
        };
        GridRenderer.Instance.SetGrid(MyGrid).ParentToTransform(parent).RenderWithPrefab(wall);
        MyGrid.Execute(this);
    }
コード例 #5
0
    public void GerarLabirinto()
    {
        if (matrizCelulas != null)
        {
            DestruirLabirinto();
        }

        InicializarLabirinto(); //Inicia a base do labirinto, em que todas as células estão fechadas por paredes em todas direções

        Labirinto huntAndKill = new HuntAndKill(matrizCelulas);

        huntAndKill.CriarLabirinto(); //Executa o HuntAndKill para dar forma ao labirinto, quebrando paredes e formando o labirinto perfeito(todas células acessíveis)

        var camPos = matrizCelulas[(Linhas / 2), (Colunas / 2)].piso.transform.position;

        camera.transform.position = new Vector3(0, CalcularAlturaCamera(), 0);

        PosicionarLabirinto();
    }
コード例 #6
0
 // Update is called once per frame
 void Update()
 {
     Debug.Log(timeLeft);
     if (timeLeft < 0)
     {
         render = false;
     }
     if (render)
     {
         timeLeft -= Time.deltaTime;
     }
     else
     {
         hk.clear();
         initMaze();
         hk = new HuntAndKill(mazeCells);
         hk.run(length, width, render);
         render   = true;
         timeLeft = 10;
     }
 }
コード例 #7
0
    private void Start()
    {
        InitFloorAndWalls(); // not a maze yet

        // DFS & Hunt and Kill
        DFS         dfs         = new DFS(mazeRows, mazeColumns);
        HuntAndKill huntAndKill = new HuntAndKill(mazeCells); // for more info on hunt and kill, check http://jamisbuck.org/mazes/

        huntAndKill.addDfs(dfs);
        huntAndKill.GenerateMaze(); // now it's a maze
        dfs = huntAndKill.dfs;

        // Entrance and exit
        if (startDoorExists)
        {
            GameObject startDoor = mazeCells[0, mazeColumns / 2].northWall;
            if (startDoor != null)
            {
                GameObject.Destroy(startDoor);
            }
        }
        if (endDoorExists)
        {
            GameObject endDoor = mazeCells[mazeRows - 1, mazeColumns / 2].southWall;
            if (endDoor != null)
            {
                GameObject.Destroy(endDoor);
            }
        }

        // For unicursal
        if (destroyAllInnerWalls)
        {
            DestroyAllInnerWalls();
        }

        // DFS in action
        dfs.findShortestPath(
            new[] { 0, mazeColumns / 2 },
            new[] { mazeRows - 1, mazeColumns / 2 }
            );
        shortestPath = dfs.GetShortestPath();

        if (
            roadVertical != null &&
            roadHorizontal != null &&
            roadBottomRightCorner != null &&
            roadBottomLeftCorner != null &&
            roadTopRightCorner != null &&
            roadTopLeftCorner != null
            ) // shows tilemaps
        {
            for (int i = 0; i < shortestPath.Length; i++)
            {
                // before tile
                int[] pointBefore;
                if (i == 0)   // since the array came from a stack, 0 is the end tile
                {
                    pointBefore = new int[] { -1, mazeColumns / 2 };
                }
                else
                {
                    pointBefore = shortestPath[i - 1];
                }
                var p_0x = pointBefore[0];
                var p_0z = pointBefore[1];

                // current tile
                var point = shortestPath[i];
                var p_x   = point[0];
                var p_z   = point[1];

                // after tile
                int[] pointAfter;
                if (i == shortestPath.Length - 1)
                {
                    pointAfter = new int[] { mazeRows, mazeColumns / 2 };
                }
                else
                {
                    pointAfter = shortestPath[i + 1];
                }
                var p_1x = pointAfter[0];
                var p_1z = pointAfter[1];

                var cell = mazeCells[p_x, p_z];

                // Straight lines
                if (p_0x == p_x && p_x == p_1x)
                {
                    setFloorMaterial(cell, roadVertical);
                    // for some reason, my horizontal tile shows up as vertical in the game, but whatever
                }
                else if (p_0z == p_z && p_z == p_1z)
                {
                    setFloorMaterial(cell, roadHorizontal);
                    // and likewise for vertical tile
                }

                // Corner tiles
                else if (
                    (p_0z + 1 == p_z && p_x + 1 == p_1x) ||
                    (p_1z + 1 == p_z && p_x + 1 == p_0x)
                    )
                {
                    setFloorMaterial(cell, roadBottomRightCorner); // like for the straight line tiles, the materials comes out flipped, this is supposed to be road-top-left-corner
                }
                else if (
                    (p_0x + 1 == p_x && p_z == p_1z + 1) ||
                    (p_1x + 1 == p_x && p_z == p_0z + 1)
                    )
                {
                    setFloorMaterial(cell, roadBottomLeftCorner); // see above comment
                }
                else if (
                    (p_0z == p_z + 1 && p_x + 1 == p_1x) ||
                    (p_1z == p_z + 1 && p_x + 1 == p_0x)
                    )
                {
                    setFloorMaterial(cell, roadTopRightCorner);
                }
                else if (
                    (p_0x + 1 == p_x && p_z + 1 == p_1z) ||
                    (p_1x + 1 == p_x && p_z + 1 == p_0z)
                    ) // it could curve from the top or the side
                {
                    setFloorMaterial(cell, roadTopLeftCorner);
                }

                // In case of failure
                else
                {
                    setFloorMaterial(cell, highlightPathMaterial);
                }
            }
        }
        else if (highlightPathMaterial != null)
        {
            for (int i = 0; i < shortestPath.Length; i++)
            {
                var point = shortestPath[i];
                var cell  = mazeCells[point[0], point[1]];

                setFloorMaterial(cell, highlightPathMaterial);
            }
        }

        // Randomly generate pick ups
        GeneratePickUps(shortestPath);
    }
コード例 #8
0
        public void TestHuntAndKill()
        {
            var grid = new Grid(5, 5);

            HuntAndKill.On(grid).ToBitmap().Save("huntandkill.png");
        }
コード例 #9
0
ファイル: MazeTest.cs プロジェクト: ViciousFish/hackaz2018
    // Use this for initialization

    void Start()
    {
        var grid = new MazeGrid.Grid(rows, columns);

        var maze = HuntAndKill.CreateMaze(grid);


        for (int x = 0; x < columns / 2; x++)
        {
            int row    = Random.Range(1, rows - 2);
            int column = Random.Range(1, columns - 2);

            Cell cell = maze.GetCell(row, column);
            if (cell.Links().Count < 4)
            {
                Cell neighbor = null;

                while (neighbor == null)
                {
                    int direction = Random.Range(0, 3);
                    switch (direction)
                    {
                    case 0:
                        if (!cell.IsLinked(cell.North))
                        {
                            neighbor = cell.North;
                        }
                        break;

                    case 1:
                        if (!cell.IsLinked(cell.East))
                        {
                            neighbor = cell.East;
                        }
                        break;

                    case 2:
                        if (!cell.IsLinked(cell.South))
                        {
                            neighbor = cell.South;
                        }
                        break;

                    case 3:
                        if (!cell.IsLinked(cell.West))
                        {
                            neighbor = cell.West;
                        }
                        break;
                    }
                }
                cell.Link(neighbor);
            }
        }

        for (int i = 0; i < maze.Rows; i++)
        {
            for (int j = 0; j < maze.Columns; j++)
            {
                Cell cell  = maze.GetCell(i, j);
                int  links = cell.Links().Count;

                GameObject gameObject = null;

                switch (links)
                {
                case 0:
                    gameObject = Instantiate(Resources.Load("JamesTesting/Prefabs/Enclosed", typeof(GameObject))) as GameObject;
                    break;

                case 1:
                    // Dead end
                    gameObject = Instantiate(Resources.Load("JamesTesting/Prefabs/DeadEnd", typeof(GameObject))) as GameObject;
                    Vector3 rotation;
                    if (cell.IsLinked(cell.North))
                    {
                        rotation = new Vector3(0f, 270f, 0f);
                    }
                    else if (cell.IsLinked(cell.East))
                    {
                        rotation = new Vector3(0f, 0f, 0f);
                    }
                    else if (cell.IsLinked(cell.South))
                    {
                        rotation = new Vector3(0f, 90f, 0f);
                    }
                    else
                    {
                        rotation = new Vector3(0f, 180f, 0f);
                    }

                    gameObject.transform.localEulerAngles = rotation;
                    break;

                case 2:
                    //Hallway or corner

                    if (cell.IsLinked(cell.North) && cell.IsLinked(cell.South))
                    {
                        gameObject = Instantiate(Resources.Load("JamesTesting/Prefabs/Hallway", typeof(GameObject))) as GameObject;
                        gameObject.transform.localEulerAngles = new Vector3(0f, 90f, 0f);
                    }
                    else if (cell.IsLinked(cell.East) && cell.IsLinked(cell.West))
                    {
                        gameObject = Instantiate(Resources.Load("JamesTesting/Prefabs/Hallway", typeof(GameObject))) as GameObject;
                        gameObject.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
                    }
                    else if (cell.IsLinked(cell.North) && cell.IsLinked(cell.East))
                    {
                        gameObject = Instantiate(Resources.Load("JamesTesting/Prefabs/Corner", typeof(GameObject))) as GameObject;
                        gameObject.transform.localEulerAngles = new Vector3(0f, 270f, 0f);
                    }
                    else if (cell.IsLinked(cell.North) && cell.IsLinked(cell.West))
                    {
                        gameObject = Instantiate(Resources.Load("JamesTesting/Prefabs/Corner", typeof(GameObject))) as GameObject;
                        gameObject.transform.localEulerAngles = new Vector3(0f, 180f, 0f);
                    }
                    else if (cell.IsLinked(cell.South) && cell.IsLinked(cell.East))
                    {
                        gameObject = Instantiate(Resources.Load("JamesTesting/Prefabs/Corner", typeof(GameObject))) as GameObject;
                        gameObject.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
                    }
                    else
                    {
                        gameObject = Instantiate(Resources.Load("JamesTesting/Prefabs/Corner", typeof(GameObject))) as GameObject;
                        gameObject.transform.localEulerAngles = new Vector3(0f, 90f, 0f);
                    }
                    break;

                case 3:

                    gameObject = Instantiate(Resources.Load("JamesTesting/Prefabs/SingleWall", typeof(GameObject))) as GameObject;
                    if (!cell.IsLinked(cell.North))
                    {
                        gameObject.transform.localEulerAngles = new Vector3(0f, 180f, 0f);
                    }
                    if (!cell.IsLinked(cell.East))
                    {
                        gameObject.transform.localEulerAngles = new Vector3(0f, 270f, 0f);
                    }
                    if (!cell.IsLinked(cell.South))
                    {
                        gameObject.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
                    }
                    if (!cell.IsLinked(cell.West))
                    {
                        gameObject.transform.localEulerAngles = new Vector3(0f, 90f, 0f);
                    }
                    break;

                case 4:
                    gameObject = Instantiate(Resources.Load("JamesTesting/Prefabs/NoWalls", typeof(GameObject))) as GameObject;
                    break;
                }
                setLocalPosition(gameObject, i, j);
            }
        }
    }