ArtInLines / Sliding-Puzzle-in-C

Implementation of the Sliding Puzzle (also called 15-puzzle) including AI solver, writtn in C.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Version 1.0

This README certainly needs more additions to work as a documentation. Much of the code could also still be revised and improved. However, both the main program and the performance test work without any apparent bugs currently. Thus, this will be considered Version 1.0 right now.

New versions were started to be developed in different branches, but it's rather unlikely that they will ever be finished.

This is also the first project I wrote in C (outside of small homeworks for uni), so the code could probably be improved greatly with better knowledge of C.

Sliding Puzzle

A sliding puzzle in this context defines a n x m-sized board filled with unordered numbers and one empty field. Only numbers adjacent to the empty spot can be moved to that place, effectively exchanging the position of the empty field and the moved number. The goal is to sort the numbers (reading from left to right and top to bottm) in the correct order in the least moves possible.

Instead of numbers, pictres or others can be used instead, but for our digital representation integers from 1 to nm-1* shall be used.

This program is meant to do several things. Using the command line, the user is meant to decide whether they want to play a sliding puzzle themselves or whether they want the computer to solve one. During any point of time of playing a sliding puzzle, the player should have the possibility of letting the computer finish the game for them.

As a last, potential feature, the player should input puzzles themselves, either by giving the computer a puzzle-size and a minimum of moves or by actually inputting the initial puzzle state.

Board Representation:

Board size is stored as m x n, where m is the column size and n is the row size.

Example board for 4 x 3, where each value x is equivalent to its index i (stored linearly in memory)

0 1 2 3

4 5 6 7

8 9 10 11

The position of any value x with the index i is the following:

  • Column: (int) i / m
  • Row: i % m

The only valid solution in the current implementation is one, where the empty field is in the last position of the board.

About

Implementation of the Sliding Puzzle (also called 15-puzzle) including AI solver, writtn in C.


Languages

Language:C 98.6%Language:Makefile 1.4%