Beispiel #1
0
def test_prepare(is_bst=True):
    my_bst = Binary_Tree("BST_1")
    if is_bst:
        my_bst.add(5)
        my_bst.add(3)
        my_bst.add(7)
        my_bst.add(1)
        my_bst.add(4)
        my_bst.add(6)
        my_bst.add(8)
    else:
        my_bst.add(3)
        my_bst.add(1)
        my_bst.add(4)
        my_bst.add(5)
        my_bst.add(6)
        my_bst.add(8)

    return my_bst
Beispiel #2
0
        Book (978-1-68050-055-4).
"""

from rectangular_grid import Rectangular_Grid
from binary_tree import Binary_Tree
from sidewinder import Sidewinder
from plotter_graphviz import GraphViz_Plotter as Plot1
from plotter_graphviz import GraphViz_Plotter_Rectangular as Plot2


    # PASSAGE CARVER

m=5
n=7
grid = Rectangular_Grid(m, n, name="BinaryTree1")
Binary_Tree.on(grid)

source = grid[m-1, n-1]           # start cell
terminus = grid[0, 0]             # finish cell

source.kwargs["content"] = "S"
terminus.kwargs["content"] = "T"
print(grid.unicode())


    # 1. tree structure of maze unravelled
    #    (crude but revealing)

pathname = "demos/graphviz1"
print("saving file %s.dot" % pathname)
plot = Plot1(grid, filename=pathname, title="Binary Tree Maze (Unravelled)")
Beispiel #3
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
Beispiel #4
0
from binary_tree import Binary_Tree

list = [1, 5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]

tree = Binary_Tree(list)

tree.printTree()
print(tree.getDepth())
Beispiel #5
0
sweepstakes.get_winner()

family = Family()
family.add_member("Nate", "Johnson", "Me")
family.add_member("Paige", "Johnson", "Wife")
print(family.members)

linked_list = LinkedList()
linked_list.append_node(5)
linked_list.append_node(30)
linked_list.append_node(65)
linked_list.add_to_beginning(1)
linked_list.add_to_beginning(3)

print(linked_list.contains_node(linked_list.head, 65))
print(linked_list.contains_node(linked_list.head, 64))

new_tree = Binary_Tree(50)
new_tree.add_node(75, new_tree)
new_tree.add_node(25, new_tree)
new_tree.add_node(15, new_tree)
new_tree.add_node(17, new_tree)
new_tree.add_node(80, new_tree)
new_tree.add_node(79, new_tree)
print(new_tree.search_for_node(80, new_tree))
print(new_tree.search_for_node(23, new_tree))
new_tree.in_order(new_tree)
print("")
new_tree.pre_order(new_tree)
Beispiel #6
0
def creator():
    """create a maze"""
    print(".", end="", flush=True)
    grid = Rectangular_Grid(rows, cols)
    Binary_Tree.on(grid)
    return grid