Genetic Algorithm Puzzle Solver and Dots and Boxes Minimax
Artificial Intelligence – University of Tehran – Department of Computer Engineering

Overview
This repository contains Genetic Algorithm Puzzle Solver and Dots and Boxes Minimax, a Python and Jupyter Notebook implementation of permutation-based jigsaw puzzle reconstruction and adversarial game search. This project was developed as the Second Computer Assignment for the Artificial Intelligence course at the University of Tehran.
The project follows an experimental pipeline including dataset loading, image-piece preprocessing, genetic representation, heuristic crossover, mutation, Minimax search, alpha-beta pruning, move ordering, compact verification experiments, visualization, and final analysis.
The original assignment also requests larger experiment grids for all images, several piece sizes, multiple generation counts, and repeated Dots and Boxes benchmarks. The repository provides executable scaffolds for those experiments, while the default notebook run keeps only compact reproducible validation outputs to remain practical for GitHub review.
Project Objectives
- ✅ Implement normalized SSD edge dissimilarity for adjacent image pieces.
- ✅ Represent jigsaw puzzle layouts as valid permutation chromosomes.
- ✅ Implement fitness evaluation, elitism, roulette selection, tournament selection, heuristic crossover, and swap mutation.
- ✅ Implement a Minimax agent for Dots and Boxes with heuristic evaluation, alpha-beta pruning, move ordering, and node-count instrumentation.
- ✅ Provide a standardized Jupyter Notebook, reusable Python modules, tests, and an exported HTML report.
Methodology
1️⃣ Dataset Loading and Inspection
The assignment images are stored under data/images/. The notebook inspects image dimensions and provides utilities for cropping images to dimensions divisible by a selected puzzle piece_size.
2️⃣ Genetic Algorithm for Puzzle Reconstruction
The jigsaw solver uses a permutation-based chromosome, where each gene identifies the image piece assigned to a grid position. The is the inverse of the average normalized edge SSD across all horizontal and vertical borders.