All Projects → obijywk → grilops

obijywk / grilops

Licence: MIT License
a GRId LOgic Puzzle Solver library

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to grilops

optaplanner-quickstarts
OptaPlanner quick starts for AI optimization: many use cases shown in many different technologies.
Stars: ✭ 226 (+679.31%)
Mutual labels:  constraint-solver
haskell-z3
Haskell bindings to Microsoft's Z3 API (unofficial).
Stars: ✭ 48 (+65.52%)
Mutual labels:  z3
GoShapesPuzzle
A simple puzzle solver in Go
Stars: ✭ 25 (-13.79%)
Mutual labels:  puzzle-solver
z3-wasm
Scripts and Javascript Glue code to use Z3 in the browser using WASM
Stars: ✭ 11 (-62.07%)
Mutual labels:  z3
python-sudoku-generator-solver
Python based sudoku generator that can create unique Sudoku board based on 4 difficulty levels. This code also includes a brute force sudoku solver that is capable of solving even the most difficult sudoku puzzles!
Stars: ✭ 58 (+100%)
Mutual labels:  sudoku-solver
FunUtils
Some codes i wrote to help me with me with my daily errands ;)
Stars: ✭ 43 (+48.28%)
Mutual labels:  puzzle-solver
Udacity
This repo includes all the projects I have finished in the Udacity Nanodegree programs
Stars: ✭ 57 (+96.55%)
Mutual labels:  sudoku-solver
intrepid
Intrepyd Model Checker
Stars: ✭ 14 (-51.72%)
Mutual labels:  z3
Cassowary
High performance swift implement of constraint solving algorithm cassowary
Stars: ✭ 45 (+55.17%)
Mutual labels:  constraint-solver
z3 tutorial
Jupyter notebooks for tutorial on the Z3 SMT solver
Stars: ✭ 117 (+303.45%)
Mutual labels:  z3
memalloy
Memory consistency modelling using Alloy
Stars: ✭ 23 (-20.69%)
Mutual labels:  constraint-solver
TSNsched
Automated Schedule Generation for Time-Sensitive Networks (TSN).
Stars: ✭ 46 (+58.62%)
Mutual labels:  z3
vim-smt2
A VIM plugin that adds support for the SMT-LIB2 format (including Z3's extensions)
Stars: ✭ 35 (+20.69%)
Mutual labels:  z3
LocalSearchSolvers.jl
A Julia package to manage Constraint-Based Local Search (CBLS) solvers.
Stars: ✭ 18 (-37.93%)
Mutual labels:  constraint-solver
snap2
Advanced tooling for puzzle hunts: grid/crossword parser, crossword tool to fill in the grid when entering answers, heavy-duty pattern/anagram solver, and more
Stars: ✭ 14 (-51.72%)
Mutual labels:  puzzle-hunt
Resolvedor-de-Sudoku
Resolver Sudoku de genina.com
Stars: ✭ 17 (-41.38%)
Mutual labels:  sudoku-solver
sudoku-solver
A simple sudoku solver
Stars: ✭ 16 (-44.83%)
Mutual labels:  sudoku-solver
Decider
An Open Source .Net Constraint Programming Solver
Stars: ✭ 112 (+286.21%)
Mutual labels:  constraint-solver
go-sudoku
A web-based sudoku solver powered by OpenCV and Go
Stars: ✭ 17 (-41.38%)
Mutual labels:  sudoku-solver
mbeddr.formal
FASTEN: FormAl SpecificaTion ENvironment - a set of DSLs to experiment with rigorous systems and safety engineering.
Stars: ✭ 16 (-44.83%)
Mutual labels:  z3

grilops

a GRId LOgic Puzzle Solver library, using Python 3 and z3.

This package contains a collection of libraries and helper functions that are useful for solving and checking Nikoli-style logic puzzles using z3.

To get a feel for how to use this package to model and solve puzzles, try working through the tutorial IPython notebook, and refer to the examples and the API Documentation.

Installation

grilops requires Python 3.6 or later.

To install grilops for use in your own programs:

$ pip3 install grilops

To install the source code (to run the examples and/or work with the code):

$ git clone https://github.com/obijywk/grilops.git
$ cd grilops
$ pip3 install -e .

Basic Concepts and Usage

The symbols, geometry, and grids modules contain the core functionality needed for modeling most puzzles. For convenience, their attributes can be accessed directly from the top-level grilops module.

Symbols represent the marks that are determined and written into a grid by a solver while solving a puzzle. For example, the symbol set of a Sudoku puzzle would be the digits 1 through 9. The symbol set of a binary determination puzzle such as Nurikabe could contain two symbols, one representing a black cell and the other representing a white cell.

The geometry module defines Lattice classes that are used to manage the shapes of grids and relationships between cells. Rectangular and hexagonal grids are supported, as well as grids with empty spaces in them.

A symbol grid is used to keep track of the assignment of symbols to grid cells. Generally, setting up a program to solve a puzzle using grilops involves:

  • Constructing a symbol set
  • Constructing a lattice for the grid
  • Constructing a symbol grid in the shape of the lattice, limited to contain symbols from the symbol set
  • Adding puzzle-specific constraints to cells in the symbol grid
  • Checking for satisfying assignments of symbols to symbol grid cells

Grid cells are exposed as z3 constants, so built-in z3 operators can and should be used when adding puzzle-specific constraints. In addition, grilops provides several modules to help automate and abstract away the introduction of common kinds of constraints.

Loops

The grilops.loops module is helpful for adding constraints that ensure symbols connect to form closed loops. Some examples of puzzle types for which this is useful are Masyu and Slitherlink.

$ python3 examples/masyu.py             $ python3 examples/slitherlink.py 
 ┌───┐┌──┐                              ┌──┐                              
┌┘ ┌─┘└─┐│                              │┌┐│ ┌┐                           
└─┐│┌──┐││                              └┘│└┐││                           
  │││┌─┘││                                │ └┘│                           
┌─┘└┘│ ┌┘│                                └┐  │                           
│┌──┐│ │┌┘                              ┌──┘┌┐│                           
││┌─┘└─┘└┐                              └───┘└┘                           
│││ ┌───┐│                                                                
└┘│ │┌──┘│                              Unique solution
  └─┘└───┘

Unique solution

Regions

The grilops.regions module is helpful for adding constraints that ensure cells are grouped into orthogonally contiguous regions (polyominos) of variable shapes and sizes. Some examples of puzzle types for which this is useful are Nurikabe and Fillomino.

$ python3 examples/nurikabe.py          $ python3 examples/fillomino.py 
2 █   ██ 2                              8 8 3 3 101010105               
███  █2███                              8 8 8 3 1010105 5               
█2█ 7█ █ █                              3 3 8 10104 4 4 5               
█ ██████ █                              1 3 8 3 102 2 4 5               
██ █  3█3█                              2 2 8 3 3 1 3 2 2               
 █2████3██                              6 6 2 2 1 3 3 1 3               
2██4 █  █                               6 4 4 4 2 2 1 3 3               
██  █████                               6 4 2 2 4 3 3 4 4               
█1███ 2█4                               6 6 4 4 4 1 3 4 4               
                                                                        
Unique solution                         Unique solution

Shapes

The grilops.shapes module is helpful for adding constraints that ensure cells are grouped into orthogonally contiguous regions (polyominos) of fixed shapes and sizes. Some examples of puzzle types for which this is useful are Battleship and LITS.

$ python3 examples/battleship.py        $ python3 examples/lits.py
     ▴                                        IIII
◂▪▸  ▪ •                                   SS  L  
     ▾                                   LSS   L I
◂▪▪▸   •                                 L IIIILLI
                                         LL   L  I
 ▴    ◂▸                                  TTT L  I
 ▾ ▴                                    SS T LL  T
   ▾ •                                   SSLL   TT
                                            L T  T
Unique solution                         IIIILTTT

                                        Unique solution

Sightlines

The grilops.sightlines module is helpful for adding constraints that ensure properties hold along straight lines through the grid. These "sightlines" may terminate before reaching the edge of the grid if certain conditions are met (e.g. if a certain symbol, such as one representing a wall, is encountered). Some examples of puzzle types for which this is useful are Akari and Skyscraper.

$ python3 examples/akari.py             $ python3 examples/skyscraper.py 
█* █*    █                              23541                            
   *   █                                15432                            
*█*   █  *                              34215                            
 *█  █   █                              42153                            
   ███*                                 51324                            
   *███*                                                                 
█ * █* █*                               Unique solution
*  █*   █*
  █     * 
█ *   █* █

Unique solution
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].