maze

How to generate a maze with more than one successful path?

守給你的承諾、 提交于 2019-11-27 19:21:54
问题 Which algorithm can be used to generate a maze with more than one successful path and if algorithm is modified version of some well known algorithm then explain or add a link . I am using 2D array A to store configuration of maze . Assume if the size of maze is n * n then more than one path should be there from A[0][0] to A[n-1][n-1] . 回答1: This algorithms should be able to generate mazes with distinct loop-free paths from start to goal: Starting with an empty maze (or a solid block of rock),

Data Structure to Represent a Maze

ε祈祈猫儿з 提交于 2019-11-27 11:46:09
问题 I'm writing a game of Dynamic maze in which after each time the structure of maze will change (Some doors will be closed and some doors will open. Something like Triwazard in HP4). Can anyone suggest me which data structure will be best suited to represent this? 回答1: Will the maze be a rectangular grid? Something else? It also depends on how much of the map will contain useful information (passes or objects). If it's a rectangular grid and most grid squares will contain SOMETHING, a good data

How to find the fastest route in a maze (in C) [duplicate]

南笙酒味 提交于 2019-11-27 07:25:56
问题 This question already has an answer here: Programming theory: Solve a maze 14 answers The maze is defined as a square matrix. For example: int maze[N][N] = { { 1, 1, 1, 1, 1, 1, 1 }, { 0, 1, 0, 1, 0, 0, 1 }, { 0, 1, 0, 1, 1, 1, 1 }, { 0, 1, 0, 0, 0, 1, 1 }, { 0, 1, 1, 1, 0, 1, 1 }, { 0, 0, 1, 0, 1, 1, 1 }, { 1, 1, 1, 1, 0, 1, 1 } }; You can walk only where there's a 1. You can take a step down, up, left, right. You start at the top-left corner and finish at down-right corner. The output

What's a good algorithm to generate a maze?

我们两清 提交于 2019-11-26 23:36:47
Say you want a simple maze on an N by M grid, with one path through, and a good number of dead ends, but that looks "right" (i.e. like someone made it by hand without too many little tiny dead ends and all that). Is there a known way to do this? rmmh From http://www.astrolog.org/labyrnth/algrithm.htm Recursive backtracker: This is somewhat related to the recursive backtracker solving method described below, and requires stack up to the size of the Maze. When carving, be as greedy as possible, and always carve into an unmade section if one is next to the current cell. Each time you move to a

ZOJ 1649 - Rescue BFS/优先队列

≯℡__Kan透↙ 提交于 2019-11-26 17:40:51
在HDOJ上提交通过以后,再在zoj上提交,结果得到了无数个WA,后来发现有一种情况我并没有考虑到 有几个关键的地方需要注意: 1. Angel的朋友不只有一个,可能有多个 2. guard的存在可能会破坏广度优先树 解决办法: BFS的做法:必须要保存guard与可行点‘.’的插入同步,因为guard的costTime不同,应该先不改变其坐标,costTime增加一以后,设为已被访问,‘x’变为‘.’或者‘#’,重新入队,此时,guard已被插入到队列的尾部,这样一来,guard与‘.’就可以同步了 View Code 1 #include <math.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include < string .h> 5 #include <memory.h> 6 7 char maze[ 210 ][ 210 ]; 8 int vis[ 210 ][ 210 ]; 9 int dx[] = {- 1 , 1 , 0 , 0 }; 10 int dy[] = { 0 , 0 , - 1 , 1 }; 11 int nNum, mNum, i, j, sx, sy; 12 13 struct Node 14 { 15 int x; 16 int y; 17 int step; 18 }; 19 20 int

UVA 705 - Slash Maze (Flood_Fill + DFS)

梦想的初衷 提交于 2019-11-26 17:40:37
分析: 1. 可以知道的是,給定的 slash Maze 中只存在 ‘/’ 和 ‘\’ ,將斜線或反斜線離散化為 3 * 3 單位的方格,比如 用數字 1 表示單位被覆蓋,數字 0 表示單位是空白,則 / 0 0 1 0 1 0 1 0 0 也可以用 2 * 2 的單元格表示圖像,但是需要特判,而這種方法不需要特判,而且相對容易實現 2. 對圖像的邊界使用 Flood Fill 染色為數字 2,因為邊界部分不可能構成環(想一想),排除不構成環的部分 3. 第 2 步以后,對 slash Maze 數字為 0 的空格使用 dfs 找出最大的環長度,也可以使用 flood fill 直接找出 1 /* 2 PROG: Slash Maze 3 ID : yewei 4 LANG: C++ 5 */ 6 #pragma warnning (disable : 4786) 7 8 #include <memory.h> 9 #include <cstdio> 10 #include <cstdlib> 11 #include <cstring> 12 #include <iostream> 13 14 using namespace std; 15 16 const int MAXN = 229 ; 17 const int dx[] = {- 1 , 1 , 0 , 0 }; 18

UVA 705 - Slash Maze (Flood_Fill + DFS)

☆樱花仙子☆ 提交于 2019-11-26 17:39:56
分析: 1. 可以知道的是,給定的 slash Maze 中只存在 ‘/’ 和 ‘\’ ,將斜線或反斜線離散化為 3 * 3 單位的方格,比如 用數字 1 表示單位被覆蓋,數字 0 表示單位是空白,則 / 0 0 1 0 1 0 1 0 0 也可以用 2 * 2 的單元格表示圖像,但是需要特判,而這種方法不需要特判,而且相對容易實現 2. 對圖像的邊界使用 Flood Fill 染色為數字 2,因為邊界部分不可能構成環(想一想),排除不構成環的部分 3. 第 2 步以后,對 slash Maze 數字為 0 的空格使用 dfs 找出最大的環長度,也可以使用 flood fill 直接找出 1 /* 2 PROG: Slash Maze 3 ID : yewei 4 LANG: C++ 5 */ 6 #pragma warnning (disable : 4786) 7 8 #include <memory.h> 9 #include <cstdio> 10 #include <cstdlib> 11 #include <cstring> 12 #include <iostream> 13 14 using namespace std; 15 16 const int MAXN = 229 ; 17 const int dx[] = {- 1 , 1 , 0 , 0 }; 18

Representing and solving a maze given an image

China☆狼群 提交于 2019-11-26 16:46:19
What is the best way to represent and solve a maze given an image? Given an JPEG image (as seen above), what's the best way to read it in, parse it into some data structure and solve the maze? My first instinct is to read the image in pixel by pixel and store it in a list (array) of boolean values: True for a white pixel, and False for a non-white pixel (the colours can be discarded). The issue with this method, is that the image may not be "pixel perfect". By that I simply mean that if there is a white pixel somewhere on a wall it may create an unintended path. Another method (which came to

What&#39;s a good algorithm to generate a maze?

旧巷老猫 提交于 2019-11-26 08:45:16
问题 Say you want a simple maze on an N by M grid, with one path through, and a good number of dead ends, but that looks \"right\" (i.e. like someone made it by hand without too many little tiny dead ends and all that). Is there a known way to do this? 回答1: From http://www.astrolog.org/labyrnth/algrithm.htm Recursive backtracker: This is somewhat related to the recursive backtracker solving method described below, and requires stack up to the size of the Maze. When carving, be as greedy as

Programming theory: Solve a maze

六眼飞鱼酱① 提交于 2019-11-26 06:11:05
问题 What are the possible ways to solve a maze? Ive got two ideas, but I think they are not very elegant. Base situation: We have a matrix, and the elements in this matrix are ordered in a way that it represents a maze, with one way in, and one out. My first idea was to send a robot through the maze, following one side, until it\'s out of the maze. I think this is a very slow solution. The second one passes through every successive item marked with 1, checks where it can go (up, right, down, left