Ejemplo n.º 1
0
    // Method to Generate Maze
    private Maze GenerateMaze(MazeAlgorithmMode mazeGenType)
    {
        Maze maze = null;

        switch (mazeGenType)
        {
        case MazeAlgorithmMode.GrowingTree:
            // Get starting cell for algorithm
            int x = 0;
            int y = mazeY - 1;
            int z = 0;

            // Growing Tree algorithm
            maze = new Maze(empty, blockTypes, new Tuple3 <int> (mazeX, mazeY, mazeZ), new Tuple3 <int> (x, y, z),
                            MazeAlgorithmMode.GrowingTree, ShuffleAlgorithmMode.ForceDirected);

            // Calculate Maze
            maze.CalculateMaze();

            // Instantiate Blocks in maze
            maze.InstantiateMaze();

            maze.GenerateGraph();

            break;
        }
        return(maze);
    }
Ejemplo n.º 2
0
 // Sets the maze generation algorithm for use during calculatemaze
 public void SetAlgorithm(MazeAlgorithmMode mazeAlgo)
 {
     _mazeAlgorithmMode = mazeAlgo;
     switch (mazeAlgo)
     {
     case MazeAlgorithmMode.GrowingTree:
         _mazeAlgorithm = new AlgorithmDelegate(MazeAlgorithm.GrowingTree);
         break;
     }
 }
Ejemplo n.º 3
0
    private ShuffleAlgorithmMode _shuffleAlgorithmMode; // Shuffle Algorithm Mode set

    // Constructor
    public Maze(GameObject mazeParent, GameObject[] blockTypes, Tuple3 <int> dimensions, Tuple3 <int> startingPosition,
                MazeAlgorithmMode mazeAlgo = MazeAlgorithmMode.GrowingTree, ShuffleAlgorithmMode shuffleAlgo = ShuffleAlgorithmMode.AStar)
    {
        parent                = mazeParent;
        parent.tag            = "Maze";
        rotating              = false;
        mazeDimensions        = dimensions;
        this.startingPosition = startingPosition;
        _blockTypes           = blockTypes;

        _blockMaze = new Block[mazeDimensions.first, mazeDimensions.second, mazeDimensions.third];
        _blockMap  = new bool[mazeDimensions.first, mazeDimensions.second, mazeDimensions.third];

        SetAlgorithm(mazeAlgo);
        SetShuffle(shuffleAlgo);
    }
Ejemplo n.º 4
0
    // Shuffle Maze, mazeType parameter for type of shuffling algorithm
    public void ShuffleMaze(MazeAlgorithmMode mazeAlgo = MazeAlgorithmMode.GrowingTree)
    {
        MazeAlgorithmMode originalAlgo = _mazeAlgorithmMode;

        // Generate a maze positioning with the mazeType
        SetAlgorithm(mazeAlgo);

        int currentNumber = 0;
        int targetNumber  = 1;

        while (currentNumber != targetNumber)
        {
            _blockMap = new bool[mazeDimensions.first, mazeDimensions.second, mazeDimensions.third];
            CalculateMaze();

            // Number every block in initial
            currentNumber = 0;
            for (int i = 0; i < _blockMaze.GetLength(0); ++i)
            {
                for (int j = 0; j < _blockMaze.GetLength(1); ++j)
                {
                    for (int k = 0; k < _blockMaze.GetLength(2); ++k)
                    {
                        // If it's a block, check if there is no block in target
                        if (_blockMaze [i, j, k] != null)
                        {
                            ++currentNumber;
                        }
                    }
                }
            }

            // Number every block in target
            targetNumber = 0;
            for (int i = 0; i < _blockMap.GetLength(0); ++i)
            {
                for (int j = 0; j < _blockMap.GetLength(1); ++j)
                {
                    for (int k = 0; k < _blockMap.GetLength(2); ++k)
                    {
                        // If it's a block, add
                        if (!_blockMap [i, j, k])
                        {
                            ++targetNumber;
                        }
                    }
                }
            }
        }

//		// Reconcile block counts
//		if (currentNumber < targetNumber) {
//			// Remove random blocks from target
//
//		} else if (currentNumber > targetNumber) {
//			// Move extra blocks out of cube range
//		}

        // Set algorithm back
        SetAlgorithm(originalAlgo);

        // On another thread, A* calculate the moves to sliding puzzle into the maze
        List <Tuple2 <Tuple3 <int> > > moves = _shuffleAlgorithm(this, HeuristicMode.None);

        TriggerMoves(moves);
    }