這並不是一個迷宮,但這個想法是相似的。在網格迷宮中擺脫斷開的矩形
我有這樣的:
的問題是,我用紅色圓圈。我需要一種方法來擺脫那些不屬於謎題其餘部分的矩形。
我創建了一個簡單的算法,該算法對於正方形的工作原理:
此工作的方式是二維陣列的每個元素表示一個頂點(圖節點)。每個圖形節點都有一個它連接到的頂點列表。通過從每個頂點到每個連接繪製線來繪製該圖。
private void removeDisconnectedSquare(int x, int y)
{
GraphNode topLeft = getNodeAt(x, y);
GraphNode topRight = getNodeAt(x + 1, y);
GraphNode bottomLeft = getNodeAt(x, y + 1);
GraphNode bottomRight = getNodeAt(x + 1, y + 1);
if(topLeft != null &&
topRight != null &&
bottomLeft != null &&
bottomRight != null &&
!hasNodeToLeft(topLeft) && hasNodeToRight(topLeft) &&
!hasNodeAbove(topLeft) && hasNodeBelow(topLeft) &&
hasNodeToLeft(topRight) && !hasNodeToRight(topRight) &&
!hasNodeAbove(topRight) && hasNodeBelow(topRight) &&
!hasNodeToLeft(bottomLeft) && hasNodeToRight(bottomLeft) &&
hasNodeAbove(bottomLeft) && !hasNodeBelow(bottomLeft) &&
hasNodeToLeft(bottomRight) && !hasNodeToRight(bottomRight) &&
hasNodeAbove(bottomRight) && !hasNodeBelow(bottomRight))
{
removeVertex(x, y);
removeVertex(x + 1, y);
removeVertex(x, y + 1);
removeVertex(x + 1, y + 1);
}
}
有沒有一種算法或方法可以檢測出verties的路徑是否不是verticies的大連接路徑的一部分?有時這會產生一條小路。
謝謝
這看起來像java代碼給我。你爲什麼給C++加上標籤? – 11684
糟糕,從另一個問題留下標籤。 – jmasterx
一個標準模板? 0.o – 11684