Question: PYTHON3 PLS help to code the part 2 and 3 thanks. i did part 1 For this assignment you will construct a single python file

PYTHON3 PLS help to code the part 2 and 3 thanks.

PYTHON3 PLS

help to code the part 2 and 3 thanks.

i did part 1

For this assignment you will construct a single python file called minesweeper.py, that will operate a text-based version of the popular number-puzzle game Minesweeper.

The rules for the game are as follows:

The computer generates a 2D grid, and places several secret mines into it.

The player then guesses locations on the grid, trying to guess every location except the ones with mines.

If the player guesses a location that's already revealed, nothing happens.

If the player guesses a location that has a mine, the game is over and the player loses.

If the player guesses a location that does not have a mine, the computer reveals how many mines are in adjacent locations on the grid. This number is displayed on the grid at the location the user guessed.

If there are zero mines in adjacent locations the computer reveals a blank space, and then subsequently reveals all adjacent cells according to these rules as well. (I.e., If any of those locations are also adjacent to zero mines, they trigger a similar reaction to their adjacent cells.)

Once the user has revealed all locations except for the mines, they win!

Below, the game development is divided into parts to aid your process. Read through all of it before beginning. You are free to build the program in any order you see fit.

Part 1: Helper functions

It is recommended that you begin your game by writing and testing the following functions. You can create any additional helper functions you might need, but the functions listed here are required components in your solution for full marks. Your solution should not depend on any imported modules other than random (and optionally math).

initMines() - This function takes zero arguments and returns a grid (i.e. a 2D list) with randomly placed mines. The size of the grid should be a global constant called GRIDSIZE (where both the number of rows and columns equal GRIDSIZE). The grid will be filled with either empty strings ("") or mines ("x"). For each cell in the grid there should be a 1 in 10 chance of placing a mine. (If you would like, this too can be a global constant making it a 1 in MINECHANCE chance of placing a mine. For submission, please set this constant to 10).

initBoard() - This function takes zero arguments and returns a grid (ie. a 2D list) representing the player's game board. Initially all cells in the game board should be unrevealed ("#"). The size of the game board should be the same as the size of the grid of mines.

displayBoard() - This function takes a 2D grid representing the player's game board as argument and prints it to the screen. The printout of the board should include row and column labels (see examples below). You may assume that GRIDSIZE will always be a number in the range [2-10].

countHiddenCells() - This function takes a 2D grid representing the player's game board as argument and returns the number of cells in the board that are unrevealed ("#"). Initially this will be all of them, but as the game progresses this value should get smaller and smaller with each turn.

countMines() - This function takes a 2D grid representing the minefield as argument and returns the number of cells in the grid that contain mines. This value should not change once the minefield is initialized.

isMineAt() - This function takes as arguments, a 2D grid representing the minefield and two integers representing a row and column respectively, and returns True if the cell indicated by the row and column contains a mine in the grid, and False otherwise. This function should validate the inputted row and column values to ensure that they are on the gameboard, and return False if they are not.

countMinesAround() - This function takes as arguments, a 2D grid representing the minefield and two integers representing a row and column respectively, and returns the number of mines in adjacent cells. Adjacent cells are the 8 cells surrounding the provided cell, including diagonals, as illustrated in the figure to the right.

Part 2: Game loop

Next build the main() function and game loop.

The main() function should initialize two grids representing the minefield and player's gameboard respectively.

The game loop should repeat the following actions each round, until the user wins or loses:

Get the user's move

Check if they lost

If not, reveal the cell (see part 3)

Display the updated game board

The user should be prompted to input two integers in a single prompt, separated by a comma. (e.g. > 3,4)

You may not assume that the user will enter good input. Any input that does not consist of two integers separated by a comma should result in the prompt repeating. Integers that are too big or small for the gameboard, can either be rejected as bad input, or accepted as valid input, but then subsequently have no effect on the game.

If the user loses, the location of all mines should be revealed and displayed, accompanied by a "Game Over!" message.

If the user wins, a congratulatory "You Win!!" message should be displayed.

Part 3: Reveal()

Write a recursive method called reveal() that takes as arguments: the player's gameboard, the grid of mines, and the user's choice (row & column values). This function should reveal the selected cell on the user's gameboard according to the rules of the game as laid out in the instructions above. Some additional notes:

Cells that are revealed as being blank should be displayed as empty spaces (" ").

The function should do input validation on the provided row and column values to verify that they indicate a valid location on the board. (If not, the function should do nothing).

The function should not need to return anything since its work is done in mutating the player's gameboard.

/ .py 1 PART:1 4 import random 5 GRIDSIZE 6 6 MINECHANCE 1/10 7 choice [, x'l 8 prob# [1-MINEC ANCE, HINECHANCE] 9 def initMines(O 10 mines 11 fori in range(GRIDSIZE) 12 mines. append( random,choices (choice, prob, k GRIDSIZE)) 13 return mines 14 def initBoard) 15 board 1 16 for i in range(GRIDSIZE) 17 board.appendust for in range(GRZE) 18 return board 19 def disptayBoard(board): 28 printend 21 for i in range (GRIDSIZE)t 22 print(i 1, end) 23 print() 24 for i in range(GRIDSIZE) 25 print(1+1, end") 26 for j in range(GRIDSIZE)t Print(board [i](j), end-..) 27 28 print) 29 def countHiddenCells(board): 30 count 0 31 for 1 in range(GRIDSIZE) 32 for j in range(GREDSIZE) 34 count 1 35 return count 36 def countMines (nines)t 37 count 38 for i in range(GRIDSIZE) 39 for j in Fange(GRIDSIZE) 40 if mines[1] 111x 41 count 42 return count 44 CADST on DS def iMineAt (mines, 1, j)s and sio and Jrd and ainesta-1 t3-1x Fatse 48 def countkinesAround(mines, i, )1 A , L-1dRtDstZE and s-b-e and 3-1.GRtrstze and j-b.e. and minesti-11 tJ-11-"., 56 1-1 GRIDS1ZE and 4-1and 1 GRIDSIZE and and nines ts-1111x Ma row-1row-1row-1 col-1 cocol+1 row row row col-1 cocol+1 row+1row+1row+1 col-1 cocol+1

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