Question: Write a C program to simulate, not solve, a modified version of the sliding tile puzzle. The sliding tile puzzle is a puzzle which consists

Write a C program to simulate, not solve, a modified version of the sliding tile puzzle. The sliding tile puzzle is a puzzle which consists of a grid-like board where each slot is filled with a tile, except for one, which is empty. Tiles cannot be lifted up from the board; the only way a tile can move is by sliding it into the empty slot, which then makes the tile's previous slotempty. This implies that only tiles which are adjacent to the empty slot in one of the four cardinal directions may slide into it. The puzzle has 24 tiles each identified by one of six colors. The following is a sample configuration appropriately named "Spiral of Colors": Write a C program which, after performing a sequence of tile slides on a puzzle with randomely scatterd tiles, prints the resultant puzzle to the console. In the ASCII representation, the tiles are denoted by the first letter of the corresponding color name. For example, the following shows the rudimentary ASCII representation for the Spiral of Colors configuration: +-+-+-+-+-+ |RG|GG|G| +-+-+-+-+-+

|R|Y|WW0|

+-+-+-+-+-+ |RY|WW|0| +-+-+-+-+-+

+-+-+-+-+-+

BBBB | +-+-+-+-+-+

Non-Standard Puzzle Variation

A non standard puzzle variation has one or more impassable tile (i.e., tile which does not slide). In the ASCII output, the letter corresponding to an impassable tile is given in lower case, while a standard tile (i.e., a tile which slides freely) is given in upper case.

Move Notation

Move instructions are given based on the direction of the possible tile movements: Up, Down, Left, or Right. For example, starting with the "Spiral of Colors" configuration, the two possible movemments are Down, and Right.

The letters U, D, L, or R indicate a tile slide in the corresponding direction. Uppercase and lowercase letters are treated as equivalent. For example, starting with the Spiral of Colors configuration, after applying the four consecutive moves "RRRR", the puzzle would be as follows:

+

=

+

=

2

+-+-+-+-+-+ RGGGG +-+-+-+-+-+ RYWW0 +-+-+-+-+-+ RYWW0 +-+-+-+-+-+ RYY 0101 +-+-+-+-+-+

| +-+-+-+-+-+

Y

Invalid move instructions should be ignored. For instance, starting with the Spiral of Colors configuration, the moves "LRRRUR" would achieve the same outcome as the moves "RRRR" because the first and fifth moves are invalid and should be ignored.

Input/Output and Program Termination

The simulator must accept the name of an input text file through a command-line argument. The first 5 lines in the text file represent the initial jumbled state of the board, consisting of letters, and exactly one space. The remaining lines of the file contain a sequence of move instructions where each instruction is liberally preceded or succeeded by whitespace.

After parsing the sequence of moves, the simulator should apply the moves in the order given starting with the initial jumbled state of the board. After all the moves have been applied, the program should

le puzzle to standard output. Lastly, if the puzzle, after applying all the moves, is in the Spiral of Color configuration, the simulator should print "Spiral!" to standard output. The simulator will then exit.

Deliverables

A file named slider.c containing the ANSI C source code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!