コード例 #1
0
ファイル: MAZE 2.0.py プロジェクト: amonreal3/lab_7
def Maze2(rows, columns, wallList):
    n = rows * columns  #number of cells
    print("there are ", n, "cells ")
    m = input("How many walls would you like to remove")
    m = int(m)
    s = dsf.DisjointSetForest(n)
    #a
    if m < n - 1:
        print(
            "A path from source to destination is not guaranteed to exist (when m < n − 1)"
        )
    #b
    if m == n - 1:
        print(
            "The is a unique path from source to destination (when m = n − 1)")
    #c
    if m > n - 1:
        print(
            "There is at least one path from source to destination (when m > n − 1)"
        )
    if m > len(wallList):
        while m > 0:

            x = random.randint(0, len(wallList) - 1)
            wallList.pop(x)
            m -= 1
        return wallList
    while m > 0:
        curr = random.randint(0, len(wallList) - 1)
        wall = wallList[curr]
        if dsf.find(s, wall[0]) != dsf.find(s, wall[1]):
            dsf.union(s, wall[0], wall[1])
            wallList.pop(curr)
            m -= 1
    return wallList
コード例 #2
0
ファイル: Maze.py プロジェクト: amonreal3/Lab6
def dsfMaze(rows,columns,wallList):
    cells = rows * columns
    s = dsf.DisjointSetForest(cells)
    while dsf.NumSets(s)> 1:
        curr = random.randint(0,len(wallList)-1)
        wall = wallList[curr]
        if dsf.find(s,wall[0]) != dsf.find(s,wall[1]):
            dsf.union(s, wall[0], wall[1])
            wallList.pop(curr)
コード例 #3
0
ファイル: Lab6Maze.py プロジェクト: luisren64/Cs2302
def SameSet(Set, walls, d):
    #This method checks if two cells are in the same set.
    i = int(walls[d][0])
    j = int(walls[d][1])
    #The find method is used to check the root of two cells.
    #If they are the same, it returns true. If not, it returns false.
    if dsf.find(Set, i) == dsf.find(Set, j):
        return True
    else:
        return False
コード例 #4
0
ファイル: MAZE 2.0.py プロジェクト: amonreal3/lab_7
def adjListdsfMaze(rows, columns, wallList):
    cells = rows * columns
    s = dsf.DisjointSetForest(cells)
    G = [[] for i in range(len(cells))]
    while dsf.NumSets(s) > 1:
        curr = random.randint(0, len(wallList) - 1)
        wall = wallList[curr]
        if dsf.find(s, wall[0]) != dsf.find(s, wall[1]):
            dsf.union(s, wall[0], wall[1])
            newEntry = wallList.pop(curr)
            G[newEntry[0]].append(newEntry[1])
    return G
コード例 #5
0
ファイル: lab7.py プロジェクト: kmora2b/CS2302
def num_sets(S):
    count = 0

    #Checks each set to see if they have similar parents
    for i in range(len(S)):
        ri = dsf.find(S, i)

        #If the element equal to the root then it is in the same set
        if i == ri:
            count += 1
    return count
コード例 #6
0
def Choice_3(S, walls, num_cells):
    G = []
    for i in range(num_cells):
        G.append([])
    while CountSets(S) > 1:
        d = random.randint(0, len(walls) - 1)
        print('removing wall ', walls[d])
        if dsf.find(S, walls[d][0]) != dsf.find(S, walls[d][1]):
            #       dsf.union(S,walls[d][0],walls[d][1])
            dsf.union_by_size(S, walls[d][0], walls[d][1])
            poppedWall = walls.pop(d)
            G[poppedWall[0]].append(poppedWall[1])
            G[poppedWall[1]].append(poppedWall[0])
    dsf.draw_dsf(S)
    pic = draw_maze(walls, maze_rows, maze_cols)
    print()
    print("breadth_first_search")
    Path = breadth_first_search(G, 0)
    draw_path(pic, Path, num_cells - 1, maze_cols - .5, maze_rows - .5)
    print(Path)
    printPath(Path, num_cells - 1)
    return G