я получил проблему с моим лабиринтом решателя, когда я запустить решатель это дает ошибку в графической переменнойC# Maze решатель Графический
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;
}
я думаю, что проблема в том, что он открывает его много, и тогда аварии (бесконечность) Может ли кто-нибудь помочь мне с этой проблемой?
Можете ли вы включать ошибку? – Henrik
Я исправил эту ошибку, но теперь моя проблема в том, что я говорю, что я не могу решить свой лабиринт, но idk, почему – Pay4yourlife
Вы пытаетесь реализовать A * правильно? –