Shirokuro Solver
CS491 Project
Alexandre Lomovtsev
Supervised by Professor Russell Abbott
2009
Goals of this project
•
Develop a strategy for solving Shirokuro puzzles.
•
Create the solver-program by means of the
Constraint Programming (CP).
What is “Shirokuro”?
“Shirokuro is a single-played game ” (in Japanese means
"white-and-black“). The goal of the game is to fill in every
empty grid space with either a white circle or a black
circle in such a way that:
(1) no two-by-two regions of the grid contains four circles of
the same color;
(2) every white circle is connected to every other white circle
through a chain of only white circles that runs horizontally
and/or vertically;
(3) every black circle is connected to every other black circle
through a chain of only black circles that runs horizontally
and/or vertically.
Shirokuro example
Constraint Programming
What is CP?
“Constraint programming represents one of the closest
approaches computer science has yet made to the Holy
Grail of programming: the user states the problem, the
computer solves it.”
Eugene C. Freuder, Constraints, April 1997
How does it work?
Step1 – stating constraints about the problem variables
Step2 – finding solution satisfying all the constraints
Tools
►
Programming Language
Java 6 Standard Edition
►
Development Tool
Eclipse (Version: 3.4.0)
►
Additional Resources
Choco - constraint programming system
Why use Choco?
Choco is an open source Java library developed for the
constraint programming.
Choco was successfully used in solving a well known
puzzles as Sudoku, Magic square, Queens problem, and
many other.
Choco can be used as a black box that accepts a
problem and returns a solution.
Choco is extensible.
Choco: creating Model
Model = Variables + Constraints
Variables in Choco can have different types:
• integer,
• real,
• set.
Variable properties:
• name,
• domain,
• options.
Constraints – specify conditions to be held on variables
to the model.
Shirokuro’s Model (1)
Variables
• Model contains N*N variables, where N is the field size;
• Variables’ domains:
{0,1} for empty cells,
{0,0} and {1,1} for cells containing white and black
circles, respectfully.
Shirokuro’s Model (2)
Constraints: no single cells
Shirokuro’s Model (3)
Constraints: no 2x2 clusters of the same color circles
Shirokuro’s Model (4)
Constraints: no “diamond” clusters
Shirokuro’s Model (4)
Constraints: no alternating colors along the perimeter
Puzzle Solving Strategy (1)
Build the perimeter and fill in the “obvious” cells
Puzzle Solving Strategy (2)
Create a Model and Read a Model to the Solver
Verify solutions found by the Solver
“Solution 1” contains a group of isolated
dots and will not be accepted by verifying
method.
DEMO
Advanced Constraints
No isolation by forming a loop or an arch.
Connectivity constraint vs. no-single-cell
constraint.
This constraints are not implemented yet.
Plans for the future
Develop an advanced constraint for
preventing formation of isolated groups.
Modify algorithm for an arbitrary size and
shape of the field.
Improve functionality of the GUI with the
following operations:
• Save desired puzzles on the disk,
• Load previously saved puzzles,
• Browse a list of solutions,
• Browse saved puzzles.
Thank you
© Copyright 2026 Paperzz