Bord game

#1

(3) Board-Game

Consider a board game played on a 10 by 10 grid. Each row and column of the grid – that is represented by a 10x10 matrix- are numbered from 0 to 9. A player represented by the system has to move from the start cell (0,0) to the end cell (9,9). Each cell can be either an ‘S’, ‘R’,‘L’ or ‘E’. ‘S’ and E’ represent the first and last cells, respectively. ‘R’ represents a regular cell, and ‘L’ means a luck cell, it randomly either advances the player several cells forward or retreats them several cells backward. The player moves one cell at a time in the direction shown in the following figure – the figure also shows the layout of the board:
S → → →
→ L →

L

L

``````					L
``````

→ → E

A player wins when they reach the end cell. At that point, the game ends. How could recursion be used to help get from the start cell to the end cell? The program should display the number of moves the player has made to win.

Recursive Algorithm
1- Write a program that plays the board game using recursion, where the 2D matrix is initialized with the values shown in the above layout using the values ‘S’,’E’,’R’ and ‘L’ as appropriate.
2- ensure that in each turn the responsible part of the program does the following:
a) determine the new position of the player by determining how many cells to advance or retreat. Remember; encountering a Regular cell will advance the position one cell forward, whereas encountering a Luck cell, will randomly result in an opportunity or trap, and the new position will be determined as follows:
Opportunity case: advances one row and 3 columns. e.g. position (1,2) will become (2,5)
Trap case: retreats one row and 2 columns. e.g. position (1,2) will become (0,0)
b) count the number of moves regardless of the number of cells they pass in any direction.
3- When the game ends, the program should display a success message and the number of steps made by the player.
4- Provide the necessary output as shown in the output file.
Terminating Conditions
Reaching the end cell to win.

note: assume that the luck cell will always result in a new position that is within the board boundaries.