Background:

In this assignment, you are required to write a program for the game Minesweeper. The game starts with a grid of unmarked squares. The game is played by asking the user to either step on one of these squares to reveal its content or flag that square as a mine. If a square containing a mine is revealed, the player loses the game otherwise a number is displayed in the square, indicating how many adjacent squares contain mines. If no mines are adjacent, then all adjacent squares will be revealed. The player uses the numbers displayed in the squares to deduce the contents of other squares, and may either safely reveal each square or flag the squares containing a mine, as shown below: see image.

Note: The size of the board will never be greater than 10 x 10 and the number of mines squares will be less than the size 2.

Task 1: Create a menu

Create a menu with the following options which you will use for the remaining tasks.

1- Read board (from assignment one)
2- New board (from assignment one)
3- Mine Count (from assignment one)
4- Play
5- Brute force
6- Quit

Note: The board size in this assignment can take any value between 2 and 10 inclusive.

Task 2: Game logic

This task is about programming the game logic. You will need two new boards, userBoard and mineBoard. The game begins with an empty list of lists, userBoard that tracks all the users' play entries. The second board, mineBoard, contains all the mines and the mine count as completed in assignment 1.

Part A: Check Function

Write a function check(userBoard, mineBoard) that takes userBoard and mineBoard and checks if the user wins, loses or is still playing . If userBoard contains an 'x', when compared to mineBoard, the player loses. To determine if a player wins we need to check if all empty squares have been revealed in the userBoard. If neither of the two cases above happened, then the user still playing. The function should return -1 if the user loses, 1 if the user wins and 0 if still playing.

Part B: Play

In this task you are required to write a function play(userBoard, mineBoard,row,col) that would take the row and col as input from the user and update userBoard with what is present at that location, a number 0-8 or an 'x'. Use check(userBoard, mineBoard) from Part A to update the user of their play progress.

Bonus: If the revealed square has 0 mines surrounding it then the function will recursively call itself for all the neighbouring squares. By doing so an entire region of contiguous empty squares will be revealed.

Example 1:
What would you like to do?
1- Read board
2- New board
3- Mine count
4- Play
5- Brute force
6- Quit
?2
board size from 2 to 10: 2
number of mines less than size^2: 1

0| | |
1| | |
_|0|1|
What would you like to do?
1- Read board
2- New board
3- Mine count
4- Play
5- Brute force
6- Quit
?4

row: 0
col: 0

0|1| |
1| | |
_|0|1|
row: 0
col: 1

0|1|1|
1| | |
_|0|1|
row: 1
col: 0

0|1|1|
1|1| |
_|0|1|
you win

0|1|1|
1|1|x|
_|0|1|

Example 2:

What would you like to do?
1- Read board
2- New board
3- Mine count
4- Play
5- Brute force
6- Quit
?2
board size from 2 to 10: 3
number of mines less than size^2: 3

0| | | |
1| | | |
2| | | |
_|0|1|2|
What would you like to do?
1- Read board
2- New board
3- Mine count
4- Play
5- Brute force
6- Quit
?4
row: 0
col: 0

0|x| | |
1| | | |
2| | | |
_|0|1|2|
you lose

0|x|1|0|
1|2|3|2|
2|1|x|x|
_|0|1|2|

Task 3: Brute-force

This task is about applying the brute-force approach to find a solution for minesweeper.

Part A: Chosen approach

In a separate word or pdf document, prepare a written discussion of the manner in which you intend to apply brute-force to this problem. Be sure to respond to the following in your discussion

1. how each individual possible solution is represented
2. the complexity of your brute force algorithm
3. how you can be certain it will give you the correct solution

Part B: Implementation

Prepare a python function bruteForce(mineBoard) which has mineBoard as input. The function will generate all possible solutions based on extracting the number of mines and size of the board from mineBoard and then starting with an empty board, will each time generate and check if there is a correct answer. The function will display each possibility until the first correct solution is found.

Example 1
What would you like to do?
1- Read board
2- New board
3- Mine count
4- Play
5- Brute force
6- Quit
?2
board size from 2 to 10: 3
number of mines less than size^2: 5

0| | | |
1| | | |
2| | | |
_|0|1|2|
What would you like to do?
1- Read board
2- New board
3- Mine count
4- Play
5- Brute force
6- Quit
?5
==>

0|x|x|x|
1|x|x| |
2| | | |
|0|1|2|
> Incorrect
==>

0|x|x|x|
1|x| |x|
2| | | |
_|0|1|2|
> Incorrect
==>

0|x|x|x|
1|x| | |
2|x| | |
_|0|1|2|
> Incorrect
==>

0|x|x|x|
1|x| | |
2| |x| |
_|0|1|2|
> Incorrect
==>

0|x|x|x|
1|x| | |
2| | |x|
_|0|1|2|
> Incorrect
==>

0|x|x|x|
1| |x|x|
2| | | |
_|0|1|2|
> Incorrect
==>

0|x|x|x|
1| |x| |
2|x| | |
_|0|1|2|
> correct
What would you like to do?
1- Read board
2- New board
3- Mine count
4- Play
5- Brute force
6- Quit
?3

0|x|x|x|
1|4|x|3|
2|x|2|1|
_|0|1|2|

Example 2
What would you like to do?
1- Read board
2- New board
3- Mine count
4- Play
5- Brute force
6- Quit
?2
board size from 2 to 10: 2
number of mines less than size^2: 2

0| | |
1| | |
_|0|1|
What would you like to do?
1- Read board
2- New board
3- Mine count
4- Play
5- Brute force
6- Quit
?5
==>

0|x|x|
1| | |
_|0|1|
> Incorrect
==>

0|x| |
1|x| |
_|0|1|
> Incorrect
==>

0|x| |
1| |x|
_|0|1|
> Incorrect
==>

0| |x|
1|x| |
_|0|1|
> Incorrect
==>

0| |x|
1| |x|
_|0|1|
> correct
What would you like to do?
1- Read board
2- New board
3- Mine count
4- Play
5- Brute force
6- Quit
?3

0|2|x|
1|2|x|
_|0|1|
What would you like to do?
1- Read board
2- New board
3- Mine count
4- Play
5- Brute force
6- Quit
?

Task 4: Decomposition, Variable names and Code Documentation

Marks will be allocated for good use of variable names, code documentations and proper decomposition.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.