Course:CPSC312-2017-15Puzzle

From UBC Wiki

15 Puzzle

Authors: Chris, Patience

What is the problem?

State the general problem. If applicable, tell us what information you will use, e.g., a link to some website that provides the information you used. What will you do?"

We will use Haskell to build a command-line version of the 15 Puzzle game. The rules of the game are as follows: Given a 4 by 4 board with 15 tiles (each tile is distinct and has a number between 1 and 15) and one empty space. The goal is to move the tiles on the board, one at a time, into ascending order, starting with 1 in the top-left corner and 15 in the second-to-last space in the bottom row (and the empty space in the bottom right corner).

More information here: https://en.wikipedia.org/wiki/15_puzzle

What is the something extra?

What is the in-depth aspect you will do? If the problem is related to some other group's project, tell us how they fit together. If in doubt, include the information."

We will make sure that each game board we generate is different and solvable.

What did we learn from doing this?

(This should be written after you have done the work.) What is the bottom-line? Is logic programming suitable for (part-of) the task? Make sure you include the evidence for your claims.

Haskell is definitely suitable for programming simple logic games like this one. Checking win conditions and move constraints is made quite simple by features such as pattern matching. It is slightly inconvenient manipulating lists/matrices in Haskell, since they are immutable, which makes things like updating the game board a little more challenging. Generating the random board was simple, but a little bit trickier since random values must be wrapped in an IO monad.

Code: https://github.com/csatterfield/15-puzzle