flood fill 알고리즘을 사용하여 목록에서 비슷한 인접 개체를 모두 찾아서 삭제하도록 표시하려고합니다. Wikipedia에서 의사 코드를 적용하려고 시도했지만 막히게되었습니다.홍수 채우기 알고리즘의 변형을 구현합니다.
목록의 각 객체에는 int X 값, int Y 값, Name 및 삭제 표시를위한 bool이 있습니다. 나는 그 이름에 매치하고 싶다.
프로그램이 try-catch없이 중단되고 프로그램이 종료됩니다. 오류 메시지를 리턴하지 않습니다. 여기 지금까지 제가 직접적으로 위에있는 객체를 찾으려고했습니다.
//Find neighbouring bubbles
gameGrid.DetectNeighbours2(gameGrid.planets.Last(), gameGrid.planets.Last().name);
//Flood fill algorithm to detect all connected planets
internal void DetectNeighbours(Planet p, Planet.Name planetName)
{
try
{
if (p.planet != planetName)
return;
p.deletable = true;
DetectNeighbours(GetTopNode(p), planetName);
}
catch (Exception err)
{
Debug.WriteLine(err.Message);
}
}
internal Planet GetTopNode(Planet b)
{
foreach (Planet gridPlanet in planets)
{
if (gridPlanet .Y == b.Y - 50)
return gridPlanet ;
}
return b; //Don't think this is right, but couldn't think of alternative
}
필자는 그 비교'p.planet! = planetName'이 순전히 위에서 발견 된 행성이없는 경우를 감지하기 위해 추가되었다는 것을 알고 있습니까? 그런 다음이 대답은 올바른 방법 중 하나입니다. – unkulunkulu
첫 번째 사례 이후에 추가 된 내용이 안전하다는 것이 맞습니다. – unkulunkulu
감사합니다. 그렇게하는 것이 더 합리적이며 더 깨끗하게 보입니다. @David, 정확히 – David