在没有无限递归的情况下,如何制作电力线?我目前正在做一个游戏,你把建筑物和电线之间,把电力从煤炭工厂转移到建筑物需要电力。是否有一种算法或特定的方法来规划电力线,以便它们之间和从其他建筑物之间传递电力。主要的问题是,这样做没有能源积累和指数增长。考虑到可以有任意数量的电力线连接到任何其他数量,这是困难的。有什么建议或帮助吗?
发布于 2022-02-15 01:43:43
private void GetTotalConnections(GameObject line, List<GameObject> checker) // HOLY SHIT IT WORKS HOLY SHIT IT WORKS HOLY SHIT IT WORKS
{
PowerLine temp = line.GetComponent<PowerLine>();
if (checker.Contains(line))
{
if (CheckIfConnectionsContains(checker, line.GetComponent<PowerLine>()) == true)
{
return;
}
}
for (int i = 0; i < temp.connectedLines.Count; i++)
{
if (checker.Contains(temp.connectedLines[i]) == false)
{
checker.Add(temp.connectedLines[i]);
GetTotalConnections(temp.connectedLines[i], checker);
}
else // if its already in the list, skip this entry since we already checked that it still had some new connections
{
continue;
}
}
}
private bool CheckIfConnectionsContains(List<GameObject> list, PowerLine line)
{
int count = 0;
for (int i = 0; i < line.connectedLines.Count; i++)
{
if (list.Contains(line.connectedLines[i]))
{
count++;
}
}
if (count == line.connectedLines.Count) // if every connection is already in the list
{
return true;
}
return false;
}
https://stackoverflow.com/questions/71088409
复制相似问题