三种迷宫生成算法+三种走迷宫算法+pyqt5可视化

这是近期作业的总结,实现截图如下:

1.作业实现

1.1截图

1.2实现思路

  1. 将迷宫单元用二维列表表示,-1为墙,0为可以走的路
  2. 首先初始化格子,等待输入,当点击按下后接受输入的迷宫列数,行数
  3. 生成迷宫矩阵,据此画出迷宫。
  4. 点击走迷宫按钮后,根据全局变量矩阵maz由三种算法计算路径。

2.涉及的知识点

  • 迷宫生成算法:dfs算法,bfs算法,Prim算法,Kruskal算法
  • 走迷宫算法:dfs算法,bfs算法,A*算法,(迪杰斯特拉算法,弗洛伊德算法)
  • PyQt5的布局与作图
  • bfs如何走迷宫并打印出迷宫路径(与dfs记录路径不一样)

3.出现的问题

  • 关于Python参数传递问题(值传递 or 址传递)
  • 如何动态刷新
  • 关于pyqt5函数的一些参数问题

4.代码部分

4.1使用的库

# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
import sys,random
from PyQt5.QtWidgets import QApplication,QMainWindow,QGraphicsItem
from PyQt5.QtCore import Qt,QRectF
import numpy as np
from queue import Queue,PriorityQueue

4.2全局变量

WIDTH,HEIGHT=800,800 #Graphicsview的尺寸
COL_INTERVAL,ROW_INTERVAL = 3,3 #格子间的间距
COL_LEN,ROW_LEN = 20,20  #格子的长度
COL_NUM,ROW_NUM = 35,35  #格子的数量
FIND,GENERATE,SPEED=0,0,0 #生成方式,走迷宫方式,刷新速度
maz=np.ones((ROW_NUM,COL_NUM)) #迷宫矩阵
dx,dy=ROW_NUM - 2,COL_NUM - 1 #终点
record,ans,process= [],[],[] #记录答案

完整代码,配置好环境即可运行

# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
import sys,random
from PyQt5.QtWidgets import QApplication,QMainWindow,QGraphicsItem
from PyQt5.QtCore import Qt,QRectF
import numpy as np
from queue import Queue,PriorityQueueWIDTH,HEIGHT=800,800 #Graphicsview的尺寸
COL_INTERVAL,ROW_INTERVAL = 3,3 #格子间的间距
COL_LEN,ROW_LEN = 20,20  #格子的长度
COL_NUM,ROW_NUM = 35,35  #格子的数量
FIND,GENERATE,SPEED=0,0,0 #生成方式,走迷宫方式,刷新速度
maz=np.ones((ROW_NUM,COL_NUM)) #迷宫矩阵
dx,dy=ROW_NUM - 2,COL_NUM - 1 #终点
record,ans,process= [],[],[] #记录答案class DFSg(object):def __init__(self, width=11, height=11):# 迷宫最小长宽为5assert width >= 5 and height >= 5, "Length of width or height must be larger than 5."# 确保迷宫的长和宽均为奇数self.width = (width // 2) * 2 + 1self.height = (height // 2) * 2 + 1self.start = [1, 0]self.destination = [self.height - 2, self.width - 1]self.matrix = Nonedef generate_matrix_dfs(self):# 地图初始化,并将出口和入口处的值设置为0self.matrix = -np.ones((self.height, self.width))self.matrix[self.start[0], self.start[1]] = 0self.matrix[self.destination[0], self.destination[1]] = 0visit_flag = [[0 for i in range(self.width)] for j in range(self.height)]def check(row, col, row_, col_):temp_sum = 0for d in [[0, 1], [0, -1], [1, 0], [-1, 0]]:temp_sum += self.matrix[row_ + d[0]][col_ + d[1]]return temp_sum <= -3def dfs(row, col):visit_flag[row][col] = 1self.matrix[row][col] = 0if row == self.start[0] and col == self.start[1] + 1:returndirections = [[0, 2], [0, -2], [2, 0], [-2, 0]]random.shuffle(directions)for d in directions:row_, col_ = row + d[0], col + d[1]if row_ > 0 and row_ < self.height - 1 and col_ > 0 and col_ < self.width - 1 and visit_flag[row_][col_] == 0 and check(row, col, row_, col_):if row == row_:visit_flag[row][min(col, col_) + 1] = 1self.matrix[row][min(col, col_) + 1] = 0else:visit_flag[min(row, row_) + 1][col] = 1self.matrix[min(row, row_) + 1][col] = 0dfs(row_, col_)dfs(self.destination[0], self.destination[1] - 1)self.matrix[self.start[0], self.start[1] + 1] = 0
class PRIMg(object):def __init__(self, width=11, height=11):assert width >= 5 and height >= 5, "Length of width or height must be larger than 5."self.width = (width // 2) * 2 + 1self.height = (height // 2) * 2 + 1self.start = [1, 0]self.destination = [self.height - 2, self.width - 1]self.matrix = None# 虽然说是prim算法,但是我感觉更像随机广度优先算法def generate_matrix_prim(self):# 地图初始化,并将出口和入口处的值设置为0self.matrix = -np.ones((self.height, self.width))def check(row, col):temp_sum = 0for d in [[0, 1], [0, -1], [1, 0], [-1, 0]]:temp_sum += self.matrix[row + d[0]][col + d[1]]return temp_sum < -3queue = []row, col = (np.random.randint(1, self.height - 1) // 2) * 2 + 1, (np.random.randint(1, self.width - 1) // 2) * 2 + 1queue.append((row, col, -1, -1))while len(queue) != 0:row, col, r_, c_ = queue.pop(np.random.randint(0, len(queue)))if check(row, col):self.matrix[row, col] = 0if r_ != -1 and row == r_:self.matrix[row][min(col, c_) + 1] = 0elif r_ != -1 and col == c_:self.matrix[min(row, r_) + 1][col] = 0for d in [[0, 2], [0, -2], [2, 0], [-2, 0]]:row_, col_ = row + d[0], col + d[1]if row_ > 0 and row_ < self.height - 1 and col_ > 0 and col_ < self.width - 1 and self.matrix[row_][col_] == -1:queue.append((row_, col_, row, col))self.matrix[self.start[0], self.start[1]] = 0self.matrix[self.destination[0], self.destination[1]] = 0
class UnionSet(object):def __init__(self, arr):self.parent = {pos: pos for pos in arr}self.count = len(arr)def find(self, root):if root == self.parent[root]:return rootreturn self.find(self.parent[root])def union(self, root1, root2):self.parent[self.find(root1)] = self.find(root2)
class KRUSKALg(object):def __init__(self, width = 11, height = 11):assert width >= 5 and height >= 5, "Length of width or height must be larger than 5."self.width = (width // 2) * 2 + 1self.height = (height // 2) * 2 + 1self.start = [1, 0]self.destination = [self.height - 2, self.width - 1]self.matrix = None# 最小生成树算法-kruskal(选边法)思想生成迷宫地图,这种实现方法最复杂。def generate_matrix_kruskal(self):# 地图初始化,并将出口和入口处的值设置为0self.matrix = -np.ones((self.height, self.width))def check(row, col):ans, counter = [], 0for d in [[0, 1], [0, -1], [1, 0], [-1, 0]]:row_, col_ = row + d[0], col + d[1]if row_ > 0 and row_ < self.height - 1 and col_ > 0 and col_ < self.width - 1 and self.matrix[row_, col_] == -1:ans.append([d[0] * 2, d[1] * 2])counter += 1if counter <= 1:return []return ansnodes = set()row = 1while row < self.height:col = 1while col < self.width:self.matrix[row, col] = 0nodes.add((row, col))col += 2row += 2unionset = UnionSet(nodes)while unionset.count > 1:row, col = nodes.pop()directions = check(row, col)if len(directions):random.shuffle(directions)for d in directions:row_, col_ = row + d[0], col + d[1]if unionset.find((row, col)) == unionset.find((row_, col_)):continuenodes.add((row, col))unionset.count -= 1unionset.union((row, col), (row_, col_))if row == row_:self.matrix[row][min(col, col_) + 1] = 0else:self.matrix[min(row, row_) + 1][col] = 0breakself.matrix[self.start[0], self.start[1]] = 0self.matrix[self.destination[0], self.destination[1]] = 0
class Ui_MainWindow(object):def setupUi(self, MainWindow):MainWindow.setObjectName("MainWindow")MainWindow.resize(1089, 850)font = QtGui.QFont()font.setFamily("Yu Gothic")MainWindow.setFont(font)self.centralwidget = QtWidgets.QWidget(MainWindow)self.centralwidget.setObjectName("centralwidget")self.pushButton = QtWidgets.QPushButton(self.centralwidget)self.pushButton.setGeometry(QtCore.QRect(870, 420, 141, 41))font = QtGui.QFont()font.setFamily("华文行楷")font.setPointSize(13)self.pushButton.setFont(font)self.pushButton.setObjectName("pushButton")self.label_4 = QtWidgets.QLabel(self.centralwidget)self.label_4.setGeometry(QtCore.QRect(880, 210, 151, 51))font = QtGui.QFont()font.setFamily("华文行楷")font.setPointSize(20)self.label_4.setFont(font)self.label_4.setObjectName("label_4")self.label_5 = QtWidgets.QLabel(self.centralwidget)self.label_5.setGeometry(QtCore.QRect(900, 550, 111, 41))font = QtGui.QFont()font.setFamily("华文行楷")font.setPointSize(20)self.label_5.setFont(font)self.label_5.setObjectName("label_5")self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)self.pushButton_2.setGeometry(QtCore.QRect(870, 720, 141, 41))font = QtGui.QFont()font.setFamily("华文行楷")font.setPointSize(13)self.pushButton_2.setFont(font)self.pushButton_2.setObjectName("pushButton_2")self.layoutWidget = QtWidgets.QWidget(self.centralwidget)self.layoutWidget.setGeometry(QtCore.QRect(820, 670, 245, 28))self.layoutWidget.setObjectName("layoutWidget")self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.layoutWidget)self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)self.horizontalLayout_5.setObjectName("horizontalLayout_5")self.label_7 = QtWidgets.QLabel(self.layoutWidget)font = QtGui.QFont()font.setFamily("幼圆")font.setPointSize(14)self.label_7.setFont(font)self.label_7.setObjectName("label_7")self.horizontalLayout_5.addWidget(self.label_7)self.comboBox_2 = QtWidgets.QComboBox(self.layoutWidget)self.comboBox_2.setObjectName("comboBox_2")self.comboBox_2.addItem("")self.comboBox_2.addItem("")self.comboBox_2.addItem("")self.horizontalLayout_5.addWidget(self.comboBox_2)self.graphicsView = QtWidgets.QGraphicsView(self.centralwidget)self.graphicsView.setGeometry(QtCore.QRect(0, 0, 805, 805))self.graphicsView.setStyleSheet("")brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))brush.setStyle(QtCore.Qt.SolidPattern)self.graphicsView.setBackgroundBrush(brush)self.graphicsView.setObjectName("graphicsView")self.label_8 = QtWidgets.QLabel(self.centralwidget)self.label_8.setGeometry(QtCore.QRect(800, 40, 301, 151))font = QtGui.QFont()font.setFamily("Lucida Calligraphy")font.setPointSize(56)self.label_8.setFont(font)self.label_8.setObjectName("label_8")self.widget = QtWidgets.QWidget(self.centralwidget)self.widget.setGeometry(QtCore.QRect(820, 260, 255, 31))self.widget.setObjectName("widget")self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget)self.horizontalLayout.setContentsMargins(0, 0, 0, 0)self.horizontalLayout.setObjectName("horizontalLayout")self.label = QtWidgets.QLabel(self.widget)font = QtGui.QFont()font.setFamily("幼圆")font.setPointSize(15)self.label.setFont(font)self.label.setObjectName("label")self.horizontalLayout.addWidget(self.label)self.lineEdit = QtWidgets.QLineEdit(self.widget)self.lineEdit.setObjectName("lineEdit")self.horizontalLayout.addWidget(self.lineEdit)self.widget1 = QtWidgets.QWidget(self.centralwidget)self.widget1.setGeometry(QtCore.QRect(820, 310, 255, 31))self.widget1.setObjectName("widget1")self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.widget1)self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)self.horizontalLayout_2.setObjectName("horizontalLayout_2")self.label_2 = QtWidgets.QLabel(self.widget1)font = QtGui.QFont()font.setFamily("幼圆")font.setPointSize(15)font.setBold(False)font.setWeight(50)self.label_2.setFont(font)self.label_2.setObjectName("label_2")self.horizontalLayout_2.addWidget(self.label_2)self.lineEdit_2 = QtWidgets.QLineEdit(self.widget1)self.lineEdit_2.setObjectName("lineEdit_2")self.horizontalLayout_2.addWidget(self.lineEdit_2)self.widget2 = QtWidgets.QWidget(self.centralwidget)self.widget2.setGeometry(QtCore.QRect(820, 370, 240, 28))self.widget2.setObjectName("widget2")self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.widget2)self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)self.horizontalLayout_3.setObjectName("horizontalLayout_3")self.label_3 = QtWidgets.QLabel(self.widget2)font = QtGui.QFont()font.setFamily("幼圆")font.setPointSize(14)self.label_3.setFont(font)self.label_3.setObjectName("label_3")self.horizontalLayout_3.addWidget(self.label_3)self.comboBox = QtWidgets.QComboBox(self.widget2)self.comboBox.setObjectName("comboBox")self.comboBox.addItem("")self.comboBox.addItem("")self.comboBox.addItem("")self.horizontalLayout_3.addWidget(self.comboBox)self.widget3 = QtWidgets.QWidget(self.centralwidget)self.widget3.setGeometry(QtCore.QRect(820, 610, 241, 27))self.widget3.setObjectName("widget3")self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.widget3)self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)self.horizontalLayout_4.setObjectName("horizontalLayout_4")self.label_6 = QtWidgets.QLabel(self.widget3)font = QtGui.QFont()font.setFamily("幼圆")font.setPointSize(15)self.label_6.setFont(font)self.label_6.setObjectName("label_6")self.horizontalLayout_4.addWidget(self.label_6)self.horizontalSlider = QtWidgets.QSlider(self.widget3)self.horizontalSlider.setOrientation(QtCore.Qt.Horizontal)self.horizontalSlider.setObjectName("horizontalSlider")self.horizontalLayout_4.addWidget(self.horizontalSlider)MainWindow.setCentralWidget(self.centralwidget)self.menubar = QtWidgets.QMenuBar(MainWindow)self.menubar.setGeometry(QtCore.QRect(0, 0, 1089, 26))self.menubar.setObjectName("menubar")MainWindow.setMenuBar(self.menubar)self.statusbar = QtWidgets.QStatusBar(MainWindow)self.statusbar.setObjectName("statusbar")MainWindow.setStatusBar(self.statusbar)self.retranslateUi(MainWindow)QtCore.QMetaObject.connectSlotsByName(MainWindow)def retranslateUi(self, MainWindow):_translate = QtCore.QCoreApplication.translateMainWindow.setWindowTitle(_translate("MainWindow", "Maze"))self.pushButton.setText(_translate("MainWindow", "一键生成迷宫"))self.label_4.setText(_translate("MainWindow", "迷宫生成"))self.label_5.setText(_translate("MainWindow", "走迷宫"))self.pushButton_2.setText(_translate("MainWindow", "开始迷宫"))self.label_7.setText(_translate("MainWindow", "走迷宫算法"))self.comboBox_2.setItemText(0, _translate("MainWindow", "DFS"))self.comboBox_2.setItemText(1, _translate("MainWindow", "BFS"))self.comboBox_2.setItemText(2, _translate("MainWindow", "A*"))self.label_8.setText(_translate("MainWindow", "Maze"))self.label.setText(_translate("MainWindow", "迷宫行数目"))self.label_2.setText(_translate("MainWindow", "迷宫列数目"))self.label_3.setText(_translate("MainWindow", "迷宫生成算法"))self.comboBox.setItemText(0, _translate("MainWindow", "深度优先"))self.comboBox.setItemText(1, _translate("MainWindow", "Prim算法"))self.comboBox.setItemText(2, _translate("MainWindow", "Kruskal算法"))self.label_6.setText(_translate("MainWindow", "速度"))
class Board(QMainWindow, Ui_MainWindow):def __init__(self):super(Board, self).__init__()self.setupUi(self)self.graphicsView.scene=QtWidgets.QGraphicsScene(0,0,WIDTH,HEIGHT)maze=Maze()maze.setPos(0,0)self.graphicsView.scene.addItem(maze)self.graphicsView.setScene(self.graphicsView.scene)self.connecter()self.show()def connecter(self):self.pushButton.clicked.connect(self.draw)self.pushButton_2.clicked.connect(self.start)def start(self):global SPEED,FIND,ROUTE,ans,recordans=[]record=[]SPEED= int(self.horizontalSlider.value())FIND= int(self.comboBox_2.currentIndex())self.search()maze = Maze()maze.setPos(0, 0)self.update(maze)def draw(self):global COL_INTERVAL,ROW_INTERVAL,WIDTH,recordglobal COL_NUM,ROW_NUM,COL_LEN,ROW_LEN,GENERATE,maz,ansans=[]record=[]COL_NUM=int(self.lineEdit_2.text())ROW_NUM=int(self.lineEdit.text())if COL_NUM>=5 and ROW_NUM>=5:GENERATE = int(self.comboBox.currentIndex())self.updateParameter()maze = Maze()maze.setPos(0, 0)self.update(maze)else:print("长宽必须大于等于五")def generate(self):global mazgen=Gen()maz=np.ones((ROW_NUM+2,COL_NUM+2))if(GENERATE==0):gen.dfsg()if(GENERATE == 1):gen.primg()if (GENERATE == 2):gen.todog()def updateParameter(self):global COL_INTERVAL, ROW_INTERVAL, WIDTH,dx,dyglobal COL_NUM, ROW_NUM, COL_LEN, ROW_LENself.generate()ROW_NUM,COL_NUM=maz.shapeCOL_INTERVAL = int(0.1 * WIDTH / (COL_NUM-1))ROW_INTERVAL = int(0.1 * HEIGHT / (ROW_NUM-1))COL_LEN = int(0.9 * WIDTH / COL_NUM)ROW_LEN = int(0.9 * HEIGHT / ROW_NUM)dx = ROW_NUM - 2dy = COL_NUM - 1def search(self):global FIND,record,ansif (FIND== 0):record.append((1,0))dfs(1,0)ans=list(ans)if (FIND == 1):bfs((1,0))if (FIND == 2):Astar()def update(self,maze):self.graphicsView.scene.addItem(maze)self.graphicsView.setScene(self.graphicsView.scene)self.show()
class Gen():def dfsg(self):global mazk=DFSg(ROW_NUM,COL_NUM)k.generate_matrix_dfs()maz=k.matrixdef primg(self):global mazk =PRIMg(ROW_NUM, COL_NUM)k.generate_matrix_prim()maz = k.matrixdef todog(self):global mazk = KRUSKALg(ROW_NUM, COL_NUM)k.generate_matrix_kruskal()maz = k.matrixdef check(self,temp):passdef get_next(self,temp):global stackdir = [(1, 0), (0, 1), (-1, 0), (0, -1)]np.random.shuffle(dir)(x,y)=tempfor (dx,dy) in dir:if((dx+x)>0 and (dx+x)<ROW_NUM-1 and (dy+y)<COL_NUM-1 and (dy+y)>0):if((x+dx,y+dy) not in stack):print(dx+x,dy+y)return (dx+x,dy+y)return None
def Keep(temp):global ans,recordans=tuple(temp)
def Save(temp):global process, recordprocess = tuple(temp)
def dfs(x,y):global dx, dy,record,w# Save(record)# pp = processPaint()# pp.setPos(0, 0)# w.update(pp)# time.sleep(0.1)if x == dx and y == dy:Keep(record)returnfor (kx, ky) in [[1, 0], [-1, 0], [0, 1], [0, -1]]:if (check(kx + x, ky + y)):record.append((kx + x, ky + y))dfs(kx + x, ky + y)record.pop()
def bfs(t):global que,dx,dy,recordlis={}visited=[(1,0)]que=Queue()que.put(t)while que:temp=que.get()if temp[0]==dx and temp[1]==dy:breakfor (kx, ky) in [[1, 0], [-1, 0], [0, 1], [0, -1]]:x=kx + temp[0]y=ky + temp[1]if (x > 0 and y > 0 and x < ROW_NUM and y < COL_NUM and maz[x][y] == 0 and (x,y) not in visited):que.put((x, y))visited.append((x, y))lis[(x,y)]=(temp[0],temp[1])if (x==dx and y==dy):breakrecord.append((dx,dy))(x,y)=lis[(dx,dy)]record.append((x, y))while (x,y)!=(1,0):(x,y)=lis[x,y]record.append((x, y))Keep(record)
def Astar():start = (1, 0)final = (ROW_NUM - 2, COL_NUM - 1)front = PriorityQueue()front.put(start)father = {}father[start] = Nonesum_cost = {}sum_cost[start] = 0while front:current = front.get()if current == final:breakfor (dx, dy) in [[1, 0], [-1, 0], [0, 1], [0, -1]]:x = current[0] + dxy = current[1] + dyif isOK((x, y)):cost = sum_cost[current] + calcuCost(current, (x, y))if (x, y) not in sum_cost or cost < sum_cost[(x, y)]:sum_cost[(x, y)] = costpriority = cost + heuristic(start, (x, y))front.put((x, y), priority)father[(x, y)] = currentif (x, y) == final:breaktemp=finalwhile temp:record.append(temp)temp=father[temp]Keep(record)
def check(x, y):global maz,record,ROW_NUM,COL_NUMif (x >= 0 and y >= 0 and x < ROW_NUM and y < COL_NUM and maz[x][y] == 0 and (x, y) not in record):return Truereturn False
def heuristic(a,b):return abs(a[0]-b[0])+abs(a[1]-b[1])
def isOK(a):return (a[0]>0 and a[1]>0 and a[0]<ROW_NUM and a[1]<COL_NUM and maz[a[0]][a[1]]==0)
def calcuCost(a,b):return abs(a[0]-b[0])+abs(a[1]-b[1])
class Maze(QGraphicsItem):def __init__(self):super(Maze, self).__init__()def boundingRect(self):return QRectF(0, 0, 800, 800)def paint(self, painter, option, widget):global COL_INTERVAL, ROW_INTERVALglobal WIDTH, COL_NUM, ROW_NUMglobal COL_LEN, ROW_LEN, maz,ROUTEfor i in range(COL_NUM):for j in range(ROW_NUM):if(maz[i][j]!=0):painter.setPen(Qt.green)painter.setBrush(Qt.white)painter.drawRect(i*(COL_LEN+COL_INTERVAL),j*(ROW_LEN+ROW_INTERVAL),COL_LEN,ROW_LEN)if((i,j) in ans):painter.setPen(Qt.yellow)painter.setBrush(Qt.red)painter.drawEllipse(i * (COL_LEN + COL_INTERVAL)+COL_LEN/4, j * (ROW_LEN + ROW_INTERVAL)+ROW_LEN/4, COL_LEN/2, ROW_LEN/2)
class processPaint(QGraphicsItem):def __init__(self):super(processPaint, self).__init__()def boundingRect(self):return QRectF(0, 0, 800, 800)def paint(self, painter, option, widget):global COL_INTERVAL, ROW_INTERVALglobal WIDTH, COL_NUM, ROW_NUMglobal COL_LEN, ROW_LEN, maz,processfor i in range(COL_NUM):for j in range(ROW_NUM):if(maz[i][j]!=0):painter.setPen(Qt.green)painter.setBrush(Qt.white)painter.drawRect(i*(COL_LEN+COL_INTERVAL),j*(ROW_LEN+ROW_INTERVAL),COL_LEN,ROW_LEN)if((i,j) in record):painter.setPen(Qt.yellow)painter.setBrush(Qt.red)painter.drawEllipse(i * (COL_LEN + COL_INTERVAL)+COL_LEN/4, j * (ROW_LEN + ROW_INTERVAL)+ROW_LEN/4, COL_LEN/2, ROW_LEN/2)
def main():global wapp = QApplication(sys.argv)w=Board()w.show()sys.exit(app.exec_())
main()

数据结构作业总结_三种迷宫生成算法+三种走迷宫算法+pyqt5可视化(1)相关推荐

  1. 随机迷宫生成算法浅析

    摘要 本文对随机迷宫生成进行了初步的研究和分析,并给出了两种不同的生成算法.最终的算法结合了图的深度优先遍历.通过对比两种算法之间,可发现,在实际问题中,结合了离散数学的方法往往非更有效率且效果更佳. ...

  2. C#三大迷宫生成算法

    今天介绍一下很经典的三大迷宫算法的C#实现,即随机普利姆算法,深度优先算法和十字分割(也就是递归分割算法).实现参考了[ActionScript 3] 三大迷宫生成算法一文(生成的迷宫预览图也使用的该 ...

  3. 迷宫生成算法---深度优先算法(基于python)

    迷宫生成算法---深度优先算法 总体的目录 版权及协议声明 更加舒服的阅读方式 一. 深度优先算法的原理与思路 二.迷宫的制作 迷宫的总体的创建. 三.代码的实现 总体的目录 版权及协议声明 本文章遵 ...

  4. c语言 迷宫深度遍历 算法,图的遍历迷宫生成算法浅析

    1. 引言 在平常的游戏中,我们常常会碰到随机生成的地图.这里我们就来看看一个简单的随机迷宫是如何生成. 2. 迷宫描述随机生成一个m * n的迷宫,可用一个矩阵maze[m][n]来表示,如图:   ...

  5. [迷宫中的算法实践]迷宫生成算法——Prim算法

    普里姆算法(Prim算法),图论中的一种算法,可在加权连通图里搜索最小生成树.意即由此算法搜索到的边子集所构成的树中,不但包括了连通图里的所有顶点(英语:Vertex (graph theory)), ...

  6. 迷宫生成算法和迷宫寻路算法

    迷宫生成算法和迷宫寻路算法 大学二年级的时候,作为对栈这个数据结构的复习,我制作了一个迷宫生成算法的小程序,当时反响十分好,过了几天我又用自己已经学的DirectX技术制作了DirectX版的程序.这 ...

  7. 随机迷宫生成算法——深度优先算法

    迷宫是我们小时候经常玩的游戏,如何用代码来快速生成上面这种迷宫呢? 迷宫算法有三大算法:深度优先算法.prim算法和递归分割算法.这里用的是深度优先算法,在此说一下算法思路,希望对各位有所帮助. 首先 ...

  8. 随机迷宫生成算法——prime算法

    本以为Prime迷宫生成算法和图论的Prime算法有什么关联,貌似并没有. Prime迷宫生成算法的原理: (1)初始地图所有位置均设为墙 (2)任意插入一个墙体进墙队列 (3)判断此时墙体是否可以设 ...

  9. unity2d随机生成物体_平面测量路径生成的4种方式

    平面度(flatness),是属于形位公差中的一种,指物体表面具有的宏观凹凸高度相对理想平面的偏差.在传统的检测方法中,平面度的测量通常有:塞规/塞尺测量法.液平面法.激光平面干涉仪测量法(平晶干涉法 ...

  10. android迷宫生成算法,【Unity算法实现】简单回溯法随机生成 Tile Based 迷宫

    算法学习自 作者eastecho 在IndieNova上发表的文章 简单的使用回溯法生成 Tile Based 迷宫 , 我只是简单做了一下Unity的实现. 基础算法的简单说明 简单说明一下算法步骤 ...

最新文章

  1. 软件开发最重要的十件事
  2. 查找发布地图的 REST URL并查询相关信息
  3. 基于TCP协议的网络程序(基础学习)
  4. java 两个页面传递数据,请问Cookie怎么在两个页面间传递数据?
  5. 视差滚动不适合网页的5个原因
  6. Linux zip加密压缩
  7. qt——QFileDialog使用对话框选取本地文件
  8. 毕业设计(十七)---发表文章(3)之- 使用ckeditor上传图片(flash)
  9. 温伯格《技术领导之路》——如何弯腰更省力,怎样伸手更合理
  10. python @符号_注意!大佬提醒你python初学者这几个很难绕过的坑,附教程资料
  11. html5高仿mac桌面,WinDynamicDesktop(高仿macOS动态壁纸)
  12. Python 项目打包各种依赖包
  13. 王笑京:国家新一代智能交通框架与实施进展
  14. WGS84坐标系转换到J2000坐标系
  15. 移动内部疯传的11篇VoLTE学习笔记,看懂了你也是技术大神(二)
  16. linux安装mysql5.7(修改密码策略)
  17. 怎么用python画房子_python绘图作业:使用pygame库画房子
  18. 无套路,鬼灭之刃同人游戏
  19. 计算机组成原理中,数据总线与地址总线位数
  20. 网络唤醒的原理原来是这样的,GET!

热门文章

  1. 广告配音免费制作软件让你轻松完成广告配音
  2. linux集群常用文件拷贝命令
  3. matlab interp插值函数
  4. 世界上主要BIOS厂家介绍(Phoenix,AMI,Insyde,Byosoft)
  5. 想学plc但是没有计算机基础,没有电工基础可以学plc编程吗?能学懂PLC编程吗?...
  6. 灵信LED屏 二次开发C#
  7. eNSP华为模拟器使用——(11)eNSP模拟无线AC和AP
  8. 3Dmax转cad及批量出图
  9. python 拟合圆_OpenCV曲线拟合与圆拟合
  10. JButton与Button的区别