Question: In Miranda functional programming: The game called Minefield presents the user with a 1 0 x 1 0 grid of cells that are initially blank.

In Miranda functional programming:
The game called Minefield presents the user with a 10x10 grid of cells that are initially blank. Five (5) of these cells contain hidden mines. The user is invited to enter (x,y) coordinates (such that both x and y are between 1 and 10 inclusive) for cells that she wishes to visit. The user is given one point for every cell that is visited that does not contain a mine. As soon as the user visits a cell that contains a mine, or visits a cell that has already been visited, the game is over and the program prints the users score to the screen.
You are given the following type synonym definition for the game board:
>board ==[[cell]]
1.Give an algebraic type definition for the type cell.
2. Give the definition (including its type) of the function init_board which takes as its argument a (possibly infinite) list of (x,y) coordinates representing the positions of the mines. Your function should generate a value of type board containing 95 empty cells and 5 cells containing mines in the appropriate positions.
3. Give the definitions (including types) of the following two functions:
usermove. This function takes two arguments: the board and a single (x,y) coordinate. It returns a two-tuple containing (i) a boolean according to whether the user has hit a mine or a previously visited cell, and (ii) a new board, suitably updated to indicate which cells have been visited.
showboard. this function takes a single argument: the board. It returns a list of characters with newlines embedded appropriately in order to display the board on the screen. Previously-visited cells should be shown as the character X and unvisited cells should be shown as the space character. Mines should be shown as spaces (i.e. hidden from the user).
4. Assuming the existence of a function random which produces a potentially-infinite list of random (x,y) coordinates, give the definition for the main function for the above game. This function should provide a loop so that before each move the screen is cleared and the current state of the board is displayed on the screen. The user is then invited to enter a new (x,y) coordinate pair, and this is checked with the function usermove. Loop again if no mine (or previously visited cell) is hit: otherwise, terminate and print out the users score.

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 Programming Questions!