Skip to content

Improve Nurikabe example #10

@Skynet0

Description

@Skynet0

The Nurikabe solver is, quite slow when given harder puzzles that have more initial freedom:

E.g. https://puzz.link/p?nurikabe/10/10/p2q8j7m2h7zh4h8m4j2q6p

HEIGHT, WIDTH = 10, 10
GIVENS = {
    (1, 0): 2,
    (2, 2): 8,
    (2, 7): 7,
    (3, 5): 2,
    (3, 8): 7,
    (6, 1): 4,
    (6, 4): 8,
    (7, 2): 4,
    (7, 7): 2,
    (8, 9): 6
}

I've made some (unpushed) improvements that vastly improve performance on this style of puzzle, by hinting the solver - if cells can be trivially shaded according to givens, then we can require those cells to be shaded, and arbitrarily root the sea at one of those. I also replaced some Implies with == where appropriate, which appear to have made improvements as well. This improves the solve time of the above puzzle from ~10 minutes to ~20 seconds.

However, the solver still struggles on ugly puzzles like
https://puzz.link/p?nurikabe/10/10/5ibj4zp7i9j6zz3i8ja

HEIGHT, WIDTH = 10, 10
GIVENS = {
  (0, 0): 5,
  (0, 4): 11,
  (0, 9): 4,
  (4, 0): 7,
  (4, 4): 9,
  (4, 9): 6,
  (9, 0): 3,
  (9, 4): 8,
  (9, 9): 10
}

I tried fixing the root of the sea at a small set of blocks (if you have two givens close together, then there must be some cells shaded between them), but that hasn't helped much (still 9000 seconds to solve and 2000 seconds to prove unique). I don't know if there's anything else that can feasibly be done, but I'd like to hear your thoughts on whether it's possible to make sparse Nurikabe faster. I did forget to try constraining the sea size as well, but I don't know how much of an effect that will have. (And I'd rather not rely on this - some Nurikabe use ? to indicate a region of unknown size!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions