š Feel free to check out my GitHub repo
š Add me on Linkedin: https://www.linkedin.com/in/chialin-cheng-3412731a1/
Developed an AI agent for Futoshiki puzzle solver, employing a backtracking search algorithm with forward checking and minimum remaining value heuristic, resulting in an 80.625% search space reduction and solving 7x7 puzzles within 1 second.
Futoshiki is a CSP (Constraint Satisfaction Problem) puzzle similar to Sudoku. The objective is to fill an nĆn grid with numbers 1 to n such that each number appears exactly once in each row and column, while satisfying additional inequality constraints between adjacent cells. This project implements an AI agent to efficiently solve Futoshiki puzzles of various sizes up to 7Ć7.
Backtracking Search: A systematic search algorithm that incrementally builds candidates to solve problems and abandons candidates ("backtracks") when they are found to not satisfy the constraints.
Minimum Remaining Value (MRV) Heuristic: A variable selection strategy that chooses the variable with the smallest remaining domain to assign next, helping to identify failures earlier.
Forward Checking: A constraint propagation technique that updates domain values of unassigned variables whenever a value is assigned to a variable, preventing future conflicts.
The combination of these techniques achieves significant optimization:
Theoretical worst-case complexity: O(n^(nĀ²))
Each additional constraint reduces search space by ~80.625%
For a 7Ć7 board: Reduced from 7^49 ā 10^41 possibilities to approximately 10^25 valid combinations
Board Initialization
Solution Search
Constraint Checking
The program can be executed in two ways:
python3 futoshiki.py <input_string>
python3 futoshiki.py
# This will read boards from futoshiki_start.txt and write solutions to output.txt
Input format example in futoshiki_start.txt:
0-0<0---0<2-0<--0-0-0
Where:
"0" represents empty cells
"-" represents no constraint between adjacent cells
"<" and ">" represent inequality constraints
The agent successfully demonstrates:
[Calculation for Result 5.]
Base Search Space (no constraints): 7^49 ā 10^41
Reduced Search Space with Different Numbers of Constraints:
With 1 constraint: ā 10^41 * (1/2) = 5 Ć 10^40
With 2 constraints: ā 10^41 * (1/2)^2 = 2.5 Ć 10^40
With 3 constraints: ā 10^41 * (1/2)^3 = 1.25 Ć 10^40
With 4 constraints: ā 10^41 * (1/2)^4 = 6.25 Ć 10^39
With 5 constraints: ā 10^41 * (1/2)^5 = 3.125 Ć 10^39
Optimization Percentage (reduction from original):
1 constraint: 50% reduction
2 constraints: 75% reduction
3 constraints: 87.5% reduction
4 constraints: 93.75% reduction
5 constraints: 96.875% reduction
Average Optimization: (50 + 75 + 87.5 + 93.75 + 96.875)/5 = 80.625%
There are no models linked
There are no datasets linked
There are no models linked
There are no datasets linked