maze

Finding all maze solutions with Python

我的未来我决定 提交于 2021-02-08 09:38:06
问题 I am trying to find (using Python) all possible solutions to a maze. I have a DFS script that returns one solution. I am trying to adapt it but I'm really having a hard time wrapping my head around the whole recursion thing. Here's the code I have, which works for finding one possible solution using DFS: Any tips or help would be much appreciated! (The "lett" in the array can be ignored/considered regular "path") def DFS(x,y,Map): if (Map[x][y]=="exit"): #check if we're at the exit return [(x

How to implement barriers to stop the player moving through walls

断了今生、忘了曾经 提交于 2021-01-31 07:25:21
问题 Quick note. This is for my A-Level NEA Programming Project. There are two main sections - One where a maze is generated and the user must navigate through it in a given time period, the time period is not currently implemented, and a second section where the user has to answer educational physics questions in order to get the best score. Questions are imported from a text file stored locally on my system. The user's score is then exported to a local text file along with the date completed. So

How to implement barriers to stop the player moving through walls

让人想犯罪 __ 提交于 2021-01-31 07:24:06
问题 Quick note. This is for my A-Level NEA Programming Project. There are two main sections - One where a maze is generated and the user must navigate through it in a given time period, the time period is not currently implemented, and a second section where the user has to answer educational physics questions in order to get the best score. Questions are imported from a text file stored locally on my system. The user's score is then exported to a local text file along with the date completed. So

Why does my implementation of randomized Prim's Algorithm in Java just generate a full grid?

自作多情 提交于 2021-01-29 17:41:50
问题 I attempted to follow this pseudocode on wikipedia https://en.wikipedia.org/wiki/Maze_generation_algorithmRandomized_Prim's_algorithm but my code just generates a full grid. I seem to be missing something in my understanding of what the algorithm does. Can someone help explain what I'm doing wrong? I've looked at a few sources but I can't wrap my head around it public class MazeGen { private int dimension, nodeCounter; private Node[][] nodes; private List<Edge> walls; public static void main

Get coordinates of “treasure” (turtles) in Maze Game that uses Python tkinter and turtle

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 14:50:44
问题 I am using Python 3 to make a maze using tkinter and turtle graphics. Most of the code works, except I cannot figure out how to "destroy" the "gold" in the game. Specifically, calling player.collision() , it says Question object has no attribute xcor even though I got this from a tutorial about a turtle Python maze game. I figured it would work the same as it did in that context, but with tkinter, everything seems to change. The problem occurs under player.collision() and the while loop at

Maze generation - recursive division (how it works?)

房东的猫 提交于 2021-01-29 04:50:24
问题 I would like to learn how to generate a perfect maze. I am trying to understand Recursive Division Algorithm. I can't understand how to implement this algorithm. This is my code: bool maze[20][20]; void initMaze() { for(int i = 0; i < 20; i++) for(int j = 0; j < 20; j++) maze[i][j] = false; for(int i = 0; i < 20; i++) maze[0][i] = true; for(int i = 0; i < 20; i++) maze[19][i] = true; for(int i = 0; i < 20; i++) maze[i][0] = true; for(int i = 0; i < 20; i++) maze[i][19] = true; } int randNum

Depth First Search to find shortest path?

最后都变了- 提交于 2021-01-28 06:08:44
问题 I know this is usually done with breadth first, but we are asked to do it with both, I already accomplished breadth first.... I feel like this is a pretty typical example of using a depth first search, so I was hoping I could get some help here... I am attempting to find the shortest path through a maze using depth first search, but as of right now I cannot wrap my head around how exactly to do it. This is my code so far: void maze::findPathRecursive(graph &g, int position, int goal) { if

Convert a simple mono drawing image to a 2d text array

南楼画角 提交于 2020-08-20 07:46:05
问题 I am trying to develop an algorithm that converts simple mono line images ie Maze, to a text 2d array. For example, the image below, it would be converted to the following text array. [|------------ |] [| | |] [| |] [| |------| ---- |] [| | | |] [| | --- |] [|--- | | |] [| |--- | |] [| | | |] [| --------------- |] [| |] [| -------------------|] and finally, like this, where 0=obstacle and 1=free passage [0000000000000111111110] [0111110111111111111110] [0111111111111111111110]

基于python的pygame的游戏之迷宫小游戏

依然范特西╮ 提交于 2020-04-07 21:32:42
开发工具:vscode、pycharm 一、游戏简介 二、开发流程 三、代码实现 四、运行截图 五、总结反思 一、游戏简介 此迷宫主要通过上下左右键来控制行走,起点在左上角,终点在右下角 ,走到终点即为成功。 界面显示迷宫,步数,及撞墙提醒。 迷宫地图为随机生成。 二、开发流程 1、明确游戏功能: 创建地图 控制人物移动 步数统计 遇到阻碍提示 游戏结束刷新页面进行下一关(未实现) 2、分工情况:两个小组完成 3、实现迷宫地图,自动生成地图 三、代码实现 (1)设置迷宫大小 # 设置迷宫的大小 global room_m, room_n, room_size room_m = 40 room_n = 25 room_size = 19 # 每个小房间的大小 steps = 0 # 设置屏幕宽度和高度为全局变量 global screen_width screen_width = 800 global screen_height screen_height = 500 (2)画迷宫 def draw_room(screen, begin_point, walls, size, r_color): n = 0 # 一个小房间的四面墙 for wall in walls: x = begin_point[0] # 迷宫起点的 x 坐标 y = begin_point[1] # 迷宫起点的