【发布时间】:2011-07-28 22:05:03
【问题描述】:
我正在尝试使用flood fill 算法在列表中查找所有相似的相邻对象,并将它们标记为删除。我尝试修改维基百科上的伪代码,但卡住了。
列表中的每个对象都有一个 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
}
【问题讨论】: