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 x grid of cells that are initially blank. Five of these cells contain hidden mines. The user is invited to enter xy coordinates such that both x and y are between and 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
Give an algebraic type definition for the type cell.
Give the definition including its type of the function initboard which takes as its argument a possibly infinite list of xy coordinates representing the positions of the mines. Your function should generate a value of type board containing empty cells and cells containing mines in the appropriate positions.
Give the definitions including types of the following two functions:
usermove. This function takes two arguments: the board and a single xy coordinate. It returns a twotuple 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. Previouslyvisited cells should be shown as the character X and unvisited cells should be shown as the space character. Mines should be shown as spaces ie hidden from the user
Assuming the existence of a function random which produces a potentiallyinfinite list of random xy 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 xy 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
