C#迷宫求解图形
问题描述:
我买了我的迷宫求解一个问题,当我运行求解它在图形变量给出了一个错误C#迷宫求解图形
private bool solveMaze(int xPos, int yPos, bool[,] alreadySearched)
{
bool correctPath = false;
bool shouldCheck = true;
Bitmap map = (Bitmap)Mazebox.Image;
Graphics gfx = null;
gfx = Graphics.FromImage(map);
Brush b = new SolidBrush(Color.CornflowerBlue);
//out of index check
if (xPos >= XTILES || xPos < 0 || yPos >= YTILES || yPos < 0)
shouldCheck = false;
if (map.GetPixel(xPos , yPos) == Color.Green)
{
correctPath = true;
}
//Search the Tile
if (shouldCheck)
{
//mark tile as searched
alreadySearched[xPos, yPos] = true;
//Check right tile
correctPath = correctPath || solveMaze(xPos + 1, yPos, alreadySearched);
//Check down tile
correctPath = correctPath || solveMaze(xPos, yPos + 1, alreadySearched);
//check left tile
correctPath = correctPath || solveMaze(xPos - 1, yPos, alreadySearched);
//check up tile
correctPath = correctPath || solveMaze(xPos, yPos - 1, alreadySearched);
}
//make correct path gray
if (correctPath)
{
gfx.FillRectangle(b, xPos, yPos, 10, 10);
Mazebox.Image = map;
}
return correctPath;
}
我认为问题是,他打开它了很多,然后它坠毁(无穷大) 任何人都可以帮助我解决这个问题吗?
答
您从未使用过您的alreadySearched
字段。
可以通过插入
shouldCheck = shouldCheck && !alreadySearched[xPos, yPos];
+0
嗯,我现在做了,但现在我无法解决我的迷宫和idk为什么 – Pay4yourlife 2013-04-07 12:29:21
做到这一点,你可以包括错误? – Henrik 2013-04-07 12:29:48
我修复了这个错误,但现在我的问题是它说我不能解决我的迷宫,但idk为什么 – Pay4yourlife 2013-04-07 12:32:04
你尝试执行A *权? – 2013-04-07 12:52:25