Starting from:

$25

CSCI1730 -Project 2 - Game of Fifteen - Solved

Problem / Exercise
In this project you will be implementing the logic to complete a “game of fifteen” board game which has been generalized to an NxN board. You may need to look up the game and learn about it (https://en.wikipedia.org/wiki/15_puzzle).

You will be provided with a skeleton program, which has the framework of the game implemented already, in a file fifteen.c.

Before starting implementation, you should follow through the next sections of this document.

Compile and Run
As the next step, ensure that you can compile and run the file as it is. You will need to provide an integer, representing the dimension of the board, as a command line argument.

Test the functionality of the program (the user may type tile ‘0’ to exit the program).

Read over the code and comments in the file and then answer the questions in the next section.

Questions
For this assignment you must also answer a few questions. The answers to these questions should be placed in your README.

1.    Besides 4x4, what other dimensions does the framework allow?

2.    What data structure is used for representation of the game board?

3.    What function is called to greet the player?

4.    What functions do you need to implement?

Important Information
1.    The game must begin with the board’s tiles in reverse order, from largest to smallest going from left to right, top to bottom, with the empty space in the board’s bottom-right corner. A 3x3 example starting configuration is depicted below:

8 7 6

5 4 3

2       1 _

2.    Important: If the board contains an odd number of tiles (i.e. the height and width of the board are even), then the positions of tiles numbered 1 and 2 must be swapped, as in the 4x4 example below:

15 14 13 12

11 10 9 8

7 6 5 4

3       1 2 _

3.    In order to move a tile, there must be an adjacent blank space.

4.    Your program should not crash when provided with bogus tile numbers. You should check these inputs.

Hints
1.    Take “baby steps” - implement small pieces of functionality one at a time and test each new increment.

2.    A suggested ordering of procedures to implement: init, draw, move, won.

3.    Some design choices are left to you where not otherwise specified. Presumably the board should look something like:

15 14 13 12

11 10 9 8

7 6 5 4

3 1 2 _

4.    Remember that the positions of tiles 1 and 2 must be swapped for even dimensioned game boards.

5.    You may automate input to this game using input redirection. You will be provided with test files which contain sequences of valid moves to verify the operation of your program.

Other Requirements
There are several additional requirements for your project:

•    makefile included (see below for requirements).

•    Your code should include comments in the methods you implement. These comments should explain what your code is doing.

•    Your files must adhere strictly to the naming conventions set forth in this document.

•    Your code should compile and run without warnings or errors when the flags -Wall -pedantic are enabled.

•    Your code should perform basic error checking (e.g. invalid tile numbers, see elsewhere in this document). • README included (see elsewhere for requirements)

Naming
Your project should reside in a folder named LastName-FirstName-p2.

Your code should go in the file fifteen.c, the executable must be named fifteen. We should run your code by typing something like:

$ ./fifteen 3

Of course, command-line arguments other than 3 will also be tested.

Makefile
Your project must include a makefile. The requirement is that we should be able to compile your code by simply typing:

$ make

in your project directory. Please also include a “clean” command that removes any object file and the executable.

README
You must complete a README file to submit with your project. This file must include: • Your Name and UGA ID (811#)

•    Instructions on how to compile and run your program.

•    The answers to the questions listed above.


More products