Snakes and Ladders
This is a software development task and an implementation task.
This task is to be solved by using a high-level language of your choice. You should state the name of the language used at the start of your solution.
A manufacturer of games has decided to design a new snakes and ladders board consisting of 100 squares. The manufacturer has asked a systems analyst to design a simulation of the game using different designs. Also, the systems analyst has been told that there must be exactly 10 snakes and 10 ladders. The number of squares that a snake sends a player back must lie between 10 and 30. The number of squares that a ladder sends a player forward must lie between 10 and 30.
The systems analyst has decided to represent the board by using a one-dimensional array with 100 cells numbered from 1 to 100. Initially each cell is to be set to zero.
When the game starts the user is asked to input the positions of the snakes. This is to be done by entering, for each snake, the square on which its head is to be and the number of squares a player must go back when landing on a snake’s head. For each snake, the number of squares to go back is then to be stored in the cell representing the head of the snake, as a negative integer.
This is repeated for the ladders by inputting the squares for the feet of the ladders and the number of squares a player must go forward when landing on the foot of a ladder. For each ladder, the number of squares to go forward should be stored as a positive integer in the cell representing the foot of the ladder.
Part of the array may look similar to that in Fig. 3.1. This indicates that there is a snake’s head in cell 51 and its tail is in cell 41. The bottom of a ladder is in cell 40 and its top is in cell 52. The remaining squares do not contain any snakes or ladders.
You should annotate all your code and use meaningful names throughout.
(a) Initialise Board
Create annotated code that initialises the board ready for the user input. 
Create an interface that allows the user to input the data as described above. Your code should validate the input and store the data as described above. You need only check for values that satisfy the criteria given above. 
The rules of this game of Snakes and Ladders are
- On each turn, a player moves forward the number of squares shown when a 6-sided die is thrown.
- If a player lands on the head of a snake, the player must move to the tail of the snake.
- If a player lands on the foot of a ladder, the player must move to the top of the ladder.
- If a move would result in the player going off the board, no move is made. You need only simulate the moves of a single player for the rest of this task.
(c) Simulate the game
Create annotated code, in a high-level language, that simulates a game of snakes and ladders and outputs the total number of throws. 
(d) Averaging Games
Modify your solution so that it asks a user to input the number of games to be played. Your solution should then play that number of games and output the average number of ‘throws’ per game. 
(e) Custom Games
The user now wishes to be able to enter the number of snakes and the number of ladders before entering their details. The number of each has to be in the range 5 to 10.
Modify your solution so that the user can enter the number of snakes and the number of ladders and their details. 
(f) Input Restrictions
The systems analyst now specifies the following restrictions on data entry.
- A square can only contain one of
- the top of a ladder the foot of a ladder the head of a snake the tail of a snake
- No ladder goes off the board
- No snake goes off the board
Modify your program to ensure it handles these restrictions. Annotate your modifications to show how you have solved this task. You should provide sample runs to show the results of using one set of valid data and one set of invalid data for each restriction. 
This task was worth 43 Marks and should take approximately 22.5 hours. It was a software development task and an implementation task that orginally appeared in OCR 2507 Task 3 Jun 2005. All rights and copyright to OCR. Please refer to the OCR Copyright Statement for further information.