Nurikabe Genetic Algorithm

Project Details

  • Category : AI, Genetic Algorithms
  • Language : Python
  • Professor: Dr. Abbot
  • Collaboration: 2 People

This is a Python based solver for the Japanese puzzle game called Nurikabe. The puzzle is to create islands (highlighted squares) based on the given size also known as a "clue", separated by a single ocean. The rules to solving the puzzle are such that:

  • Each island contains exactly one clue.
  • The number of squares in each island equals the value of the clue.
  • All islands are isolated from each other horizontally and vertically.
  • There are no oceans of 2x2 or larger.
  • When completed, all oceans form a continuous path.

There have been many documentation and methods for solving this puzzle using ant colony algorithm, however, not much on using genetic algorithm. Under careful instruction by Dr. Abbot, me (Spencer Young) and Stanley Do, we worked together outside of regular curriculum to create a genetic algorithm solver for Nurikabe.
It currently solves 5x5 Nurikabe problems in about 1 second! Larger puzzles can still be solved by larger degrees in time depending on the puzzle.
The solver uses all the traditional properties of genetic algorithms, such as:
  • Population
  • Mating Pool
  • Elitism
  • Mutation
  • Breeding

  • Link to viewable code: Nurikabe GA Github
  • Here is the genetic algorithm solving a 5x5 nurikabe problem in just seconds. the example problem shown below is:
    [ 1 , 0 , 0 , 0 , 0 ]
    [ 0 , 0 , 0 , 0 , 0 ]
    [ 7 , 0 , 0 , 0 , 0 ]
    [ 0 , 0 , 0 , 1 , 0 ]
    [ 0 , 0 , 0 , 0 , 0 ]

  • "Spencer was in my Fall 2019 AI class. He brought the same enthusiasm to the class that you can see on this website. It was a pleasure having him in the class. When the semester was over, Spencer and a friend spent the break between the Fall and Spring semesters developing an advanced Genetic Algorithm approach to Nurikabe, a famously difficult--in fact NP-complete--Japanese puzzle. Their work has lead to a significantly faster and more powerful solver."

    Russ Abbott
    Professor, Computer Science
    California State University, Los Angeles