This project aims to solve levels of the strategy game Bloxorz using a SAT solver, specifically Gophersat. The objective is to model the game's rules as logical constraints and then use Gophersat to determine an optimal solution under the constraint of a maximum number of movements
Bloxorz is a game where the player controls a rectangular block that must be moved on a grid to reach a hole. Each move must comply with specific constraints:
โ The block cannot fall off the grid.
โ
The block must end up vertically aligned in the hole to win.
๐ Certain grid tiles may have switches or obstacles.
This project models these constraints as a SAT problem and uses the Gophersat solver to find a valid solution.
Example : Level 3 of the original game (solution in 19 moves found by the solver)
-
Modeling Bloxorz Rules ๐งฉ
- Representation of the grid and block.
- Encoding movement rules and valid states as logical clauses in conjunctive normal form (CNF).
-
Using Gophersat โก
- Generating a DIMACS file (
*.cnf) containing SAT clauses. - Calling the Gophersat solver to solve the planning problem.
- Analyzing and interpreting the solution to generate the block's movements.
- Generating a DIMACS file (
-
Simple User Interface ๐จ
- Loading predefined levels.
- Visualizing the solution sequences.
- Python (>= 3.8)
- The following Python libraries:
subprocess(to call Gophersat)numpy(to handle grids)pillow&tkinter(optional, for graphical interface)
- SAT Solver: Gophersat
-
Clone this repository:
git clone https://github.com/M-Nad/Bloxorz_solver.git cd Bloxorz_solver -
Install the dependencies:
pip install -r requirements.txt
-
Download the Gophersat binary and place it in the project directory.
Specify thePATH_TO_SOLVERvariable in the filebloxorz_solver.py.
-
Define a Bloxorz level in a JSON file (see the example in
levels/level_1.json, or Example Levels section). -
Run the main script:
python bloxorz_solver.py --level levels/level_1.json
๐ก Tip: Use the graphical display instead of the console:
python bloxorz_solver.py -l levels/level_1.json -g
๐ Note: Specify the path to the SAT solver (if not previously done):
python bloxorz_solver.py -l levels/level_1.json -s path_to_solver
-
The script generates a DIMACS file and uses Gophersat to solve the level. The solution is displayed as a sequence of moves.
bloxorz-sat-solver/
โโโ levels/ # Level definition files
โโโ solver/ # Modules for constraint generation and Gophersat calls
โโโ examples/ # Examples of generated solutions
โโโ bloxorz_solver.py # Main script
โโโ requirements.txt # Python dependencies
โโโ README.md # Project documentation
Example JSON file for a simple level:
{
"grid": [
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 1, 1, 1, 0]
],
"start": [1, 1],
"end": [5, 7]
}๐ฏ The solver yields a 7 moves solution :
RIGHT, DOWN, RIGHT, RIGHT, RIGHT, DOWN, DOWN
Example JSON file for a more complex level:
{
"grid": [
[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0],
[1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1],
[1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1],
[1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1],
[0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]
],
"start": [3, 1],
"end": [3, 13],
"controls": {
"buttons": [
{
"position": [4, 9],
"switch_type": "DUAL",
"activation": "stand_only",
"controls": [
[6, 3]
]
}
],
"controlled_cells": [
{"position": [6, 3], "state": 0}
]
}
}๐ฏ The solver yields a 44 moves solution :
DOWN, LEFT, UP, RIGHT, RIGHT, RIGHT, RIGHT, RIGHT, DOWN, RIGHT, LEFT, UP, LEFT, LEFT, LEFT, LEFT, LEFT, DOWN, RIGHT, DOWN, RIGHT, DOWN, RIGHT, RIGHT, RIGHT, UP, UP, RIGHT, DOWN, LEFT, UP, RIGHT, UP, UP, RIGHT, RIGHT, RIGHT, DOWN, RIGHT, DOWN, RIGHT, DOWN, LEFT, UP
- Marius NADALIN
- Antoine DIEU


