Download it at: https://dinoh-sandys.itch.io/8-puzzle-game-with-ai
This repository contains a Python implementation of the classic 8-puzzle game using the Pygame library. The 8-puzzle is a sliding puzzle that consists of a 3x3 grid with eight numbered tiles and one blank tile. The goal of the game is to rearrange the tiles to reach a specific target configuration.
1 2 3
4 5 6
7 8
- Interactive GUI-based gameplay
- Randomly generated valid game boards
- A* algorithm solver to find the optimal solution path
- Mouse controls for moving tiles
- Visual indication of the solved state and win message
- Python (version 3.6 or higher)
- Pygame library 2.3.0
- Clone the repository to your local machine.
- Install the required dependencies using
pip
or any package manager of your choice. - Run the
8-puzzle.py
script to start the 8-puzzle game. - Use the mouse to click on a tile adjacent to the empty space to move it into the empty space.
- Press the SPACE key to start the solver and find the solution path. The solver will automatically move the tiles to reach the goal state.
- Press the RETURN key to reset the game and generate a new random puzzle configuration.
- Press the ESCAPE key or close the game window to exit the game.
The implementation of the 8-puzzle game in this repository was created by dinoh__sandys. The A* algorithm solver is based on the work of Peter Hart
, Nils Nilsson
and Bertram Raphael
, available at https://en.wikipedia.org/wiki/A*_search_algorithm.
MIT License