According to my question Java algorithm filling cells like an `Android - Flow` game
Suppose i have four points(two pairs) how i can check is the exist combination of pathes between points that filling all game board?
Like an right image, but with four points ( two pairs ).
I need to check can i fill all game board with two arcs(path).
Now i stopped after filling the structure :
private static void buildGrid(int gridResolution) {
for (int i = 1; i < 3; i++) {
for (int j = 0; j < gridResolution; j++) {
Node node = new Node();
if (startPoint1.x == i && startPoint1.y == j) {
node.point = new PointM(new Point(i, j), 1);
startNode1 = node;
} else if (startPoint2.x == i && startPoint2.y == j) {
node.point = new PointM(new Point(i, j), 1);
startNode2 = node;
} else if (endPoint1.x == i && endPoint1.y == j) {
node.point = new PointM(new Point(i, j), 2);
endNode1 = node;
} else if (endPoint2.x == i && endPoint2.y == j) {
node.point = new PointM(new Point(i, j), 2);
endNode2 = node;
} else {
node.point = new PointM(new Point(i, j), 0);
}
nodes[i][j] = node;
Node leftNode = getLeftNode(i, j);
Node topNode = getTopNode(i, j);
if (leftNode != null) {
node.left = leftNode;
leftNode.right = node;
}
if (topNode != null) {
node.top = topNode;
topNode.bottom = node.top;
}
}
}
}
private static Node getTopNode(int i, int j) {
return nodes[i - 1][j];
}
private static Node getLeftNode(int i, int j) {
if (j - 1 > 0)
return nodes[i][j - 1];
else return null;
}
private static class Node {
public PointM point;
public Node left;
public Node right;
public Node top;
public Node bottom;
public boolean isChecked;
}
And i doesn't know what i need to do after that. I stuck on this moment. As best and will circumvent this table. Perhaps it is what the algorithm?
Personally, for building-grid purpose I'd invert your approach. So, instead of checking if for each pair a proper path exists, we will create grid which satisfies this condition.
So, the algorithm would look like this:
...
Then you will have grid where for each pair, there is a proper path.
Here is an example of this algorithm:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.