Another C programming problem I don't understand, any help please ?
Question 2: Die Tipping NB: Die is the singular of dice
A normal die is a cube where the faces are numbered 1 through 6 and the numbers are arranged so that
opposite faces add up to 7. In this question we will move a die on an 11 by 11 grid. Each square on this
grid is the same size as the faces of the die; i.e. the die fits exactly onto each square on the grid.
Imagine the die is placed on the grid so that the number 1 is uppermost and 6 is touching the grid. The
die is now rotated so that 2 is towards the top of the grid and 5 is towards the bottom. This question uses
a die that has 3 on the left and 4 on the right. We will call this the default orientation of the die.
A move is made by tipping the die over one of the edges of the face that touches the grid. This will move
the die one square on the grid and change the face that touches the grid. If the die is tipped off the left
side of the grid it should be placed at the corresponding position (i.e. with the same y co-ordinate) on the
right side of the grid, and vice versa. Similarly for the top and bottom of the grid (with the x co-ordinate
staying the same).
For example, suppose the die is in its default orientation in the middle of the grid. It now tips over the
edge towards the bottom of the grid. The die moves one square closer to the bottom of the grid, and 5
now touches the grid. 1 is now towards the bottom of the grid, 6 the top, 2 will be uppermost and 3 and
4 will remain on the left and right respectively.
The die also has a heading, which is the direction on the grid it last moved.
The rules for moving the die are as follows:
1. Each square on the grid contains a number (1, 2, 3, 4, 5 or 6). Add the number on the current square
to the value that is uppermost on the die. If this sum is greater than 6, subtract 6 from the sum.
2. Replace the number on the grid with this new value.
3. Depending on this value perform one of the following actions:
• 1 or 6 move
one square according to the heading;
• 2 move
one square in the direction 90° clockwise to the heading;
• 3 or 4 move
one square in the opposite direction to the heading;
• 5 move
one square in the direction 90° anti-clockwise to the heading.
Write a program that models the die moving on the grid.
Your program should first read in a 3!3 grid, which will be in the form of three lines
of three integers (between 1 and 6 inclusive). This 3!3 grid should be used as the
centre section of the 11!11 grid for the simulation. The remaining squares of the grid
will start with the value 1.
In each case the die begins in the centre of the 11!11 grid, in the default orientation,
with a heading towards the top of the grid.
Until your program terminates you should repeatedly input an integer, and then:
• If you receive a positive integer n (1 " n " 100) you should make n moves.
• If you receive the number 0 your program should terminate immediately.
• Ignore any other input.
After each positive integer you should output the 3!3 grid surrounding the die. For
each square on this grid that is outside the 11!11 grid you should output an X.
Sample Run example :
1 3 5
1 6 5
1 1 5