Overview

In this project, you will:

  • Practice basic C++ syntax including branching structures
  • Write a program that calls multiple functions
  • Manage a two-dimensional array
  • Use simple file input/output

Background

The fifteen (15 or 16 puzzle) is a common sliding puzzle that you may remember from your youth. It involves a frame of numbered square tiles in random order with one tile missing. The object of the puzzle is to place the tiles in order by making sliding moves that use the empty space.

Figure 1. Solved 15 Puzzle: see image.

For this effort, we are going to create a game board that the user can manipulate in order to get a board that is out of order into a correct order. Additionally, the game will indicate when the game is "solved" by putting the tiles into the correct location.

The game board will be represented by a two-dimensional grid. The actual implementation of how you want to create the grid is up to your design decisions, but you must meet all requirements listed below for full points.

The user will be able to "slide" any tile to an empty location. If the user tries to slide the tile into a location that is already populated or off of the board, the system will indicate that it is not possible. While we can make the grid of any size, we will start with a standard 4 by 4.

Figure 2. Sample Grid: see image.

Assignment Description

Your assignment is to develop the fifteen game (using text) where the user tries to put each of the tiles into order. On each turn, the user can slide any tile adjacent to a blank into the blank location.

The game continues until all fifteen tiles are in order as shown in figure 1 above. It should then prompt the user for another game.

Requirements

This is a list of the requirements of this application. For this project, it is up to you exactly how you want to implement it. For you to earn all the points, however, you will need to meet all the defined requirements.

  • You must follow the coding standard as defined in the CMSC 202 coding standards (found on Blackboard under course materials). This includes comments as required.
  • The project must be turned in on time by the deadline listed above.
  • The project must be completed in C++. You may not use any libraries or data structures that we have not learned in class. These are the only libraries that you are allowed to use in this project < iostream>, < ctime>, < fstream>, < iomanip>, < cmath>, and < cstdlib>. You may NOT use < string>. You should only use namespace std.
  • You must use a variety of functions (at least 5) including passing parameters to those functions and returning information from those functions. At least one time, an array (of any size) must be passed to a function (although you may do this more than once).
  • All user input must be validated. For example, if a menu allows for 1, 2, or 3 to be entered and the user enters a 4, it will re-prompt the user. However, the user is expected to always enter the correct data type. i.e. If the user is asked to enter an integer, they will. If they are asked to enter a character, they will. You do not need to worry about checking for correct data types.
  • You must use at least one multi-dimensional array in this project.
  • When the game is initially started, it should prompt the user if they want to load the "default" puzzle or a puzzle from a file. The default puzzle which can be used for initial testing should look like this: see image.
  • Input files start in row 0 and iterate through the columns then move to row 1 and iterate through the columns all the way to row 4. Each line will have data for exactly one cell. There are three test puzzle files (all are solvable) named proj1_test1.txt, proj1_test2.txt, and proj1_test3.txt. We may use different test files and the name of the file should not appear in your code at all. see image.
  • On a player's turn, the player enters a row and column number. The row and column must start at 1 (unlike the values in the array itself).
  • The board will show each of the integers (1-15) or a 0 (representing the blank).
  • A tile may only slide into a blank. If a tile is attempted to be slid into a space that already has a value, it will not move there. Additionally, if the tile would leave the board, it will not move either. In both cases, the user should be notified of the illegal move.
  • After each slide, the game should check to see if all 15 tiles are in order and the blank is in the bottom right hand corner. If the win condition is met, the game should indicate that the game was won and to re-prompt the user to play again.
  • A solved board looks like this: see image.
  • Exit and include a thank you message for the user.
  • Specific coding requirements include:
    • Must use at least 5 different functions.
    • Must be able to read a puzzle in the form of a file
    • Must use at least one multidimensional array
    • Must pass at least one array to a function
    • Must not use any global variables (constants are good!)
    • Must use at least one switch statement.
    • Must use input validation (assume the data is the correct type).
    • Must use at least one do..while loop.
    • Must use constants as needed.

Recommendations

You are free to implement this with your own functions. While not required, these are some functions that you may want to include:

  • Start the Game - Sets up the board based on a file or makes the default scenario (with just two out of order for initial testing).
  • Select Tile - user chooses the row and column of the tile to slide into the blank.
  • Swap Tile - swaps the value of the chosen tile and the blank
  • Check Direction - After the user chooses a tile, checks to see if any of the adjacent tiles are empty. If so, swaps them.
  • Print the Board - used to display the entire board formatted with the row and columns visible.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.