【问题标题】:Android Flow game filling algorithmAndroid Flow游戏填充算法
【发布时间】:2014-07-24 11:33:37
【问题描述】:

根据我的问题Java algorithm filling cells like an `Android - Flow` game

假设我有四个点(两对),我如何检查是否存在填充所有游戏板的点之间的路径组合?

类似于右图,但有四个点(两对)。

我需要检查是否可以用两条弧线(路径)填充所有游戏板。

现在我在填充结构后停止了:

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;
}

我不知道在那之后我需要做什么。我停留在这一刻。最好并且会绕过这个表。也许是什么算法?

【问题讨论】:

  • 如果你能解释你的反对意见,我将不胜感激......
  • 请发布您遇到问题的具体代码。
  • @AndrewArnold 我在问题顶部提供了一个代码链接。
  • 不,您提供了另一个问题的链接。你需要把相关代码放在这个问题中。
  • @AndrewArnold 上帝...这只是复制粘贴操作...

标签: java android algorithm


【解决方案1】:

就个人而言,出于构建网格的目的,我会反转您的方法。因此,我们将创建满足此条件的网格,而不是检查每一对是否存在正确的路径。

所以,算法应该是这样的:

  • 使用未标记的点创建第一条路径。然后标记所有路径点。在路径的起点和终点插入硬币。
  • 使用未标记的点创建第二条路径。然后标记所有路径点。在路径的起点和终点插入硬币。

...

  • 标记所有点后停止。

然后你就会有网格,每对都有一个正确的路径。

这里是这个算法的一个例子:

【讨论】:

    猜你喜欢
    • 2014-09-15
    • 1970-01-01
    • 1970-01-01
    • 2015-10-24
    • 2011-03-26
    • 1970-01-01
    • 2023-02-17
    • 2021-03-12
    • 2011-10-13
    相关资源
    最近更新 更多