Starting from:
$35

$29

Computer Programming Homework #3 Solution

Description: In this homework, you will implement a puzzle game in the C language.

    1. The number puzzle (as seen in the following Picture) is a well known game where a board of N by N spaces is filled with squares carrying numbers from 1 to N*N-1 (one space will always be empty). The user can move the existing numbers in horizontal or vertical directions towards the empty space).












The aim of the game is to order the numbers (see Fig. a below). The player can move the squares starting from any sqaure towards the empty space. For example, when the square with number 14 is moved twords left (showin in Fig. b below) we obtain the board in Fig. c. When another downward move is applied on sqaure labeled 2 on the the resulting board, we will obtain the board shown in Fib. d.





















2.  Your puzzle will be N x N size (N is a defined constant).

    3. You will write a function that gives a board with randomly placed squares (numbers). You can use the random number generator provided in stdlib.h.

    4. You will write a function that prints the current puzzle on the console. You are expected to format the puzzle properly. The printed board has to be bordered with *s and numbers appropriately centered.

    5. You will write a function that performs the desired move on the puzzle board. The movement parameters are

        a. The direction of the movement: towards {left, right, up, down} enumerated type.

        b. Movement start location: Movement will start at this location (you will need two parameters for this).

Of course, if the move cannot be performed, your function should return an appropriate value indicating so.

    6. You will write a function that checks if the puzzle is solved/correct. It should return a logical value.

    7. Finally, your main function will start a random puzzle and print it. It will ask the user to enter the desired movement (two parameters for location, one parameter for direction). After movement is entered, the board will be updated and printed. If the board is solved, success message will be printed and the program will be terminated with an appropriate message. Otherwise, movement entry will be repeated until either the board is solved or user gives up.

    8. You can assume that there will be at most 99 numbers. This is to help you with printing your puzzle on the console.

    9. There should be no global variables in your program. You are expected to keep track of your puzzle with a multidimensional array. You must use enumerated types and switch statements when needed.

General Rules:

    1. Obey and do not break the function prototypes that are shown on each part, otherwise, you will get zero from the related part.

    2. The program must be developed on Linux based OS and must be compiled with GCC compiler, any problem which rises due to using another OS or compiler won’t be tolerated.

    3. Note that if any part of your program is not working as expected, then you can get zero from the related part, even it’s working in some way.

What to hand in: A student with number 20180000001 should hand in a file named 20180000001.c for this homework.

More products