Example #1
0
def generate_maze(grid):
    """generate a perfect maze on the grid"""
    from aldous_broder import Aldous_Broder

    print("Generate perfect maze... (Aldous/Broder)")
    Aldous_Broder.on(grid)
    print("Done!")
Example #2
0
def main(args):
    """entry point"""
    import matplotlib.pyplot as plt
    from polar_grid import Polar_Grid
    from layout_plot_polar import Polar_Layout

    m = 20
    grid = Polar_Grid(m)
    Aldous_Broder.on(grid)

    layout = Polar_Layout(grid, plt, title="Aldous/Broder - Single Pole Cell")
    layout.palette[0] = 'red'
    layout.palette[1] = 'green'
    layout.color[grid[0, 0]] = 0
    layout.color[grid[m - 1, 0]] = 1

    layout.draw_grid()
    layout.render('demos/polar1.png')

    grid = Polar_Grid(m, poleCells=3)
    Aldous_Broder.on(grid)

    layout = Polar_Layout(grid,
                          plt,
                          title="Aldous/Broder - Three Wedges at Pole")
    layout.palette[0] = 'red'
    layout.palette[1] = 'green'
    layout.color[grid[0, 0]] = 0
    layout.color[grid[m - 1, 0]] = 1

    layout.draw_grid()
    layout.render('demos/polar2.png')
Example #3
0
def generate_maze(algorithm, height, width, path, displayMaze):
    if algorithm == "backtracking":
        backtracking = Backtracking(height, width, path, displayMaze)
        backtracking.createMaze()
    elif algorithm == "aldous_broder":
        aldous_broder = Aldous_Broder(height, width, path, displayMaze)
        aldous_broder.createMaze()
    elif algorithm == "hunt_and_kill":
        hunt_and_kill = Hunt_and_Kill(height, width, path, displayMaze)
        hunt_and_kill.createMaze()
    elif algorithm == "prims":
        prims = Prims(height, width, path, displayMaze)
        prims.createMaze()
Example #4
0
def main(args):
    grid, masked = make_mask(args.input, debug=True)
    m, n = grid.rows, grid.cols
    print("Grid: m=%d, n=%d, v=%d" % (m, n, m * n))
    Aldous_Broder.on(masked)
    render_plot(grid, masked, args.output)
Example #5
0
def generate_maze(algorithm, grid, bias):
    """generate a maze"""
    print("Algorithm = %s, bias = %s" % (algorithm, str(bias)))
    basename = None

    if algorithm in ['AB', 'AldousBroder']:
        from aldous_broder import Aldous_Broder
        Aldous_Broder.on(grid)
        basename = "AldousBroder"
    elif algorithm in ['RAB', 'ReverseAldousBroder']:
        from aldous_broder import Aldous_Broder
        Aldous_Broder.reverse_on(grid)
        basename = "ReverseAldousBroder"
    elif algorithm in ['ABW', 'AldousBroderWilson']:
        from wilson import Wilson as ABW
        if bias is None:
            bias = 0.5
        ABW.hybrid_on(grid, cutoff=bias)
        basename = "AldousBroderWilson"
    elif algorithm in ['BT', 'BinaryTree']:
        from binary_tree import Binary_Tree
        if bias is None:
            bias = 0.5
        Binary_Tree.on(grid, bias=bias)
        basename = "BinaryTree"
    elif algorithm in ['BT2', 'BinaryTree2']:
        from binary_tree2 import Binary_Tree
        Binary_Tree.on(grid)
        basename = "BinaryTree2"
    elif algorithm in ['DFS', 'RBT', 'RecursiveBackTracker']:
        from recursive_backtracker import Recursive_Backtracker
        Recursive_Backtracker.on(grid)
        basename = "RecursiveBacktracker"
    elif algorithm in ['HK', 'HuntKill', 'HuntAndKill']:
        from hunt_and_kill import Hunt_and_Kill
        Hunt_and_Kill.on(grid)
        basename = "HuntAndKill"
    elif algorithm in ['NRDFS', 'Labyrinth']:
        from recursive_backtracker import Recursive_Backtracker
        Recursive_Backtracker.deterministic_on(grid)
        basename = "Labyrinth"
    elif algorithm in ['SW', 'Sidewinder']:
        from sidewinder import Sidewinder
        if bias is None:
            bias = 0.5
        Sidewinder.on(grid, bias=bias)
        basename = "Sidewinder"
    elif algorithm in ['BFS', 'BreadthFirstSearch']:
        from tree_search import Tree_Search
        Tree_Search.bfs_on(grid)
        basename = "BreadthFirstSearch"
    elif algorithm in ['HEAP', 'HeapSearch']:
        from tree_search import Tree_Search
        Tree_Search.heap_on(grid)
        basename = "HeapSearch"
    elif algorithm in ['W', 'Wilson']:
        from wilson import Wilson
        Wilson.on(grid)
        basename = "Wilson"
    print("maze generation: complete!")
    return basename
def creator():
    """create a maze"""
    print(".", end="", flush=True)
    grid = Rectangular_Grid(rows, cols)
    Aldous_Broder.on(grid)
    return grid
Example #7
0
def test_aldous_broder():
    aldous_broder = Aldous_Broder(201, 201, "maze.png", False)
    assert aldous_broder.createMaze() == 0