- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
首先让我为尺寸道歉我会尽量保持它尽可能小
在尝试完全按照维基百科上所说的那样构建 prim 的算法后,我发现它无法按照我构建的迷宫方式运行。所以我尝试做同样的想法来适应我的迷宫,但我看到了一个奇怪的错误,
当我的游戏开始时,它只是没有正确地 build 我的迷宫,我不知道为什么这是偶尔发生的事情
其他时候它工作得很好,所以我有一个public Dictionary<int, Dictionary<int, MazeCellState>> maze
当它开始时,它占据了迷宫,迷宫是所有的树篱,然后我继续像这样 build 路径
private static void buildPath()
{
List<KeyValuePair<Misc.Cord, Misc.Cord>> ends = new List<KeyValuePair<Misc.Cord, Misc.Cord>>();
ends.Add(new KeyValuePair<Misc.Cord, Misc.Cord>(new Misc.Cord() { X = 0, Y = 0 }, new Misc.Cord() { X = 0, Y = 0 }));
Misc.Cord currentPos = null;
while (ends.Count > 0)
{
int posKey = rand.Next(0, ends.Count);
Misc.Cord lastPos = ends[posKey].Key;
currentPos = ends[posKey].Value;
maze[currentPos.X][currentPos.Y] = MazeCellState.Path;
int currentCount = 0;
MovingState moveTo1 = (MovingState)rand.Next(0, 4);
MovingState moveTo2 = (MovingState)rand.Next(0, 4);
while (moveTo1.Equals(moveTo2))
{
moveTo1 = (MovingState)rand.Next(0, 4);
moveTo2 = (MovingState)rand.Next(0, 4);
}
// check left
if (currentPos.X - 2 > 0 && maze[currentPos.X - 2][currentPos.Y] != MazeCellState.Path && currentCount < 2 && (moveTo1 == MovingState.Left || moveTo2 == MovingState.Left))
{
if(!lastPos.Equals(new Misc.Cord() { X = currentPos.X - 2, Y = currentPos.Y }))
{
ends.Add(new KeyValuePair<Misc.Cord, Misc.Cord>(currentPos, new Misc.Cord() { X = currentPos.X - 2, Y = currentPos.Y }));
maze[currentPos.X - 1][currentPos.Y] = MazeCellState.Path;
currentCount++;
}
}
// check right
if (currentPos.X + 2 < maze.Count && maze[currentPos.X + 2][currentPos.Y] != MazeCellState.Path && currentCount < 2 && (moveTo1 == MovingState.Right || moveTo2 == MovingState.Right))
{
if (!lastPos.Equals(new Misc.Cord() { X = currentPos.X + 2, Y = currentPos.Y }))
{
ends.Add(new KeyValuePair<Misc.Cord, Misc.Cord>(currentPos, new Misc.Cord() { X = currentPos.X + 2, Y = currentPos.Y }));
maze[currentPos.X + 1][currentPos.Y] = MazeCellState.Path;
currentCount++;
}
}
// check Up
if (currentPos.Y - 2 > 0 && maze[currentPos.X][currentPos.Y - 2] != MazeCellState.Path && currentCount < 2 && (moveTo1 == MovingState.Up || moveTo2 == MovingState.Up))
{
if(!lastPos.Equals(new Misc.Cord() { X = currentPos.X, Y = currentPos.Y - 2}))
{
ends.Add(new KeyValuePair<Misc.Cord, Misc.Cord>(currentPos, new Misc.Cord() { X = currentPos.X, Y = currentPos.Y - 2 }));
maze[currentPos.X][currentPos.Y - 1] = MazeCellState.Path;
currentCount++;
}
}
// check Down
if (currentPos.Y + 2 < maze[0].Count && maze[currentPos.X][currentPos.Y + 2] != MazeCellState.Path && currentCount < 2 && (moveTo1 == MovingState.Down || moveTo2 == MovingState.Down))
{
if(!lastPos.Equals(new Misc.Cord() { X = currentPos.X, Y = currentPos.Y + 2}))
{
ends.Add(new KeyValuePair<Misc.Cord, Misc.Cord>(currentPos, new Misc.Cord() { X = currentPos.X, Y = currentPos.Y + 2 }));
maze[currentPos.X][currentPos.Y + 1] = MazeCellState.Path;
currentCount++;
}
}
ends.RemoveAt(posKey);
ends = reorderList(ends);
}
maze[0][1] = MazeCellState.Path;
}
我不确定为什么我偶尔会看到上面的图片,我的理论是它最终会自行恢复
一些快速说明,此时 MazeCellState 只能是 2 个选项之一,path 或 hedge 和 reorderList 将重新索引任何类型的列表迷宫大小根据屏幕分辨率计算,每个单元格为 64x64 PX,
GraphicsDevice.Viewport.Width * 5 / 64,
GraphicsDevice.Viewport.Height * 5 / 64
最佳答案
当您的字段是网格时,这确实是一种实现算法的困难方法。 Prim 的网格算法可以更容易地表达。我不会研究您的代码做错了什么,而是告诉您一个简单的方法。
创建您的网格,并使用从零开始的连续数字对所有单元格进行编号。每个细胞都有两个可以打破的边界墙;上和左,或下和右,或其他一些组合,只要您选择(左/右)之一和(上/下)之一就没关系。
现在选择任何单元格,然后选择它的一面墙。如果那堵墙另一侧的单元格有不同的数字(一个高一个低),打破那堵墙,然后在整个迷宫中,将所有出现的较高数字重新编号为较低的数字。如果您选择的单元格和另一侧已经具有相同编号的墙,请不要尝试另一面墙,而是按顺序移动到下一个单元格,重复每一行并向下(可能几乎一直循环) 直到你找到一个有你可以打破的墙的单元格。
如果你有 N 个单元格,你必须精确地重复这个破墙练习 N-1 次,直到最后一次所有单元格的编号都为零(因为每次你打破时,你都会从字段中删除较高的数字),并且你有一个完整的迷宫。
如果您想要一个迷宫,其路径通常是左右而不是上下,那么请将您随机选择的墙壁偏向该方向。这也适用于 3D 迷宫,您可能不需要很多梯子;只是不要选择打破那么多天花板/地板。
在我描述了这个算法之后,我 14 岁的儿子在 3D Turbo-Pascal 中实现了它,所以我知道这个算法和这个描述确实有效。这实际上是 Prim 算法的一个版本,除了所有弧具有相同成本的情况(或者所有左右弧都一样,所有上下弧都一样,等等)。它的巧妙之处在于编号的工作方式可以确定哪些单元格已经可以从其他单元格访问。
关于C# Maze Generation 我自己实现的Prim的算法Bug,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15787800/
作为内部研究项目的一部分,我们正在尝试从 Bugzilla 数据库中收集一些指标;我们已经找到了一个工具来帮助我们从中收集一些指标 ( BugzillaMetrics ) 但我们现在问自己应该收集哪些
我想向 Mantis Bug 跟踪器添加一个名为“On Hold”的自定义状态。根据我在网上找到的一些博客,我在 config_local.php 中添加了以下几行: $g_status_enum_s
我安装了Mantis BT,并在成功安装后重定向到登录页面。它说默认用户是“管理员”,但没有提供有关其密码的提示。 Documentation也未指定默认密码。有什么线索吗? 最佳答案 Aah ..明
我遇到了一些复杂的C++模板代码的编译错误,将其简化如下: struct MyOptions { static const size_t maxArray = 2; static co
我试图编译一些使用 Boost (1.49) 的代码,使用 trunk 中的 Clang(& libc++)。有问题的代码归结为以下内容: #include #include int main()
我在这里设置了一个 CSS 菜单: http://pans.saebermedia.com/ 问题是,我注意到 IE 无法正确显示菜单,现在我又开始使用装有 IE8 的计算机来修复它。我正在使用兼容模
我检查了 GCC buglist和 Clang buglist并且还没有看到任何相关内容。 This Wandbox link显示一些 C++11/C++14 代码为各种类型的 x 执行 declty
所以我有这个简洁的小 javascript 函数,我用它以很酷的命令提示符样式将文本打印到浏览器窗口。它接受一个字符串并以设定的时间间隔一次将一个字符打印到窗口。这是:(我已经删除了所有不必要的部分,
在我的 Galaxy Tab 2(三星)上启动我的应用程序时,我不断收到此错误消息。我正在开发的应用程序非常复杂,很难追踪此错误的来源。所以我开始逐个剥离我的应用程序,最后只剩下一个 map View
我正在使用 Workbench 在 Mathematica 中开发一个应用程序包,它开始变得复杂,包含多个版本和组件。我在一些 mathematica 文档(http://reference.wolf
我选择了四种免费工具用于基于 Web 的缺陷跟踪。它们是: 错误说明 螳螂 错误跟踪器 .NET 来自 Project Locker 软件的 Trac 考虑到以下因素,我正在尝试在这四种工具之间做出决
我正在尝试将 mysqlclient 安装到我的 Python 3.6 上。最初我想安装的是 MySQLdb,但是它说 MySQLdb 不能与 Python 3 一起使用(还是?)。所以我切换到mys
我正在尝试将 mysqlclient 安装到我的 Python 3.6。最初我要安装的是 MySQLdb,但是它说 MySQLdb 不能与 Python 3 一起使用(仍然?)。所以我切换到mysql
我正在尝试将 mysqlclient 安装到我的 Python 3.6。最初我要安装的是 MySQLdb,但是它说 MySQLdb 不能与 Python 3 一起使用(仍然?)。所以我切换到mysql
**摘要:**为了保障华为云GaussDB产品的可靠性,每一款产品发布前都要通过多轮严苛的测试用例。 说明:本文中的MySQL,如果不做特殊说明,指的是开源社区版MySQL。 华为云数据库新版本在发布
我有一个程序,它打开一个程序,然后将一个字符串复制并粘贴到该程序中,一段时间后,它使用带有 ctrl+c 的机器人将一个字符串从程序复制到剪贴板。然后我的程序检查复制的字符串是否包含单词,但不是检查最
所以我尝试为 cocos2d-x 构建项目。我目前在 cmd 中,当我键入 python android-build.py -p 19 cpp-tests 时,它开始制作项目,但随后出现构建失败的错误
我是开发物理模型的团队中唯一的软件工程师(大约 30,000 行代码)。团队的其他成员由开发代码库大约 20 年的科学家组成。我的工作流程是这样的: 科学家请求新功能 我实现 通过测试和验证,我在数字
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 提供事实和引用来回答它. 2年前关闭。 Improve this
当我运行 时,以下代码抛出 ExecutionEngineException发布 构建可执行文件(启动 exe 文件 )。这是错误还是正常行为? 包大小 = 1 的值类型: [StructLayout
我是一名优秀的程序员,十分优秀!