Algorithm for solving Flow Free Game

后端 未结 6 641
故里飘歌
故里飘歌 2020-12-24 02:57

I recently started playing Flow Free Game.

\"\"

Connect matching colors with pipe to creat

6条回答
  •  暖寄归人
    2020-12-24 03:37

    Reduction to SAT

    Basic idea

    1. Reduce the problem to SAT
    2. Use a modern SAT solver to solve the problem
    3. Profit

    Complexity

    The problem is obviously in NP: If you guess a board constellation, it is easy (poly-time) to check whether it solves the problem.

    Whether it is NP-hard (meaning as hard as every other problem in NP, e.g. SAT), is not clear. Surely modern SAT solvers will not care and solve large instances in a breeze anyway (I guess up to 100x100).

    Literature on Number Link

    Here I just copy Nuclearman's comment to the OP:

    Searching for "SAT formulation of numberlink" and "NP-completeness of numberlink" leads to a couple references. Unsurprisingly, the two most interesting ones are in Japanese. The first is the actual paper proof of NP-completeness. The second describes how to solve NumberLink using the SAT solver, Sugar. –

    Hint for reduction to SAT

    There are several possibilities to encode the problem. I'll give one that I could make up quickly.

    Remark

    j_random_hacker noted that free-standing cycles are not allowed. The following encoding does allow them. This problem makes the SAT encoding a bit less attractive. The simplest method I could think of to forbid free-standing loops would introduce O(n^2) new variables, where n is the number of tiles on the board (count distance from next sink for each tile) unless one uses log encoding for this, which would bring it down to O(n*log n), possible making the problem harder for the solver.

    Variables

    One variable per tile, piece type and color. Example if some variable X-Y-T-C is true it encodes that the tile at position X/Y is of type T and has color C. You don't need the empty tile type since this cannot happen in a solution.

    Set initial variables

    Set the variables for the sink/sources and say no other tile can be sink/source.

    Constraints

    1. For every position, exactly one color/piece combination is true (cardinality constraint).
    2. For every variable (position, type, color), the four adjacent tiles have to be compatible (if the color matches).

    I might have missed something. But it should be easily fixed.

提交回复
热议问题