# Algorithm | 代写Python | 代写assignment | lab代做 – MCD4710 Assignment 1

### MCD4710 Assignment 1

Algorithm | 代写Python | 代写assignment | lab代做 – 这是一个Python面向对象设计的practice, 考察Python的理解, 涵盖了Algorithm/Python等方面, 该题目是值得借鉴的lab代写的题目

``````MCD4710 Introduction to
Algorithms and Programming
``````

#### To demonstrate your understanding of:

• how to decompose code into functions in Python.
• how to read from text files using Python.
• how to manipulate lists using basic operations.
• brute-force approaches to problems

#### Submission Procedure

1. Create a single python file containing all your solutions with your name and student ID as comments.
2. Save your file into a zip file called YourStudentID.zip
4. Your assignment will not be accepted unless it is a readable zip file.
``````Important Notes:
``````
1. Please ensure that you have read and understood the universitys policies on plagiarism and collusion available at https://www.monashcollege.edu.au/ data/assets/pdf_file/0010/17101/dip-assessment- policy.pdf. You will be required to agree to these policies when you submit your assignment.
2. Your code will be checked against other students work and code available online by advanced plagiarism detection systems. Do not take the risk, make sure your work is your own.
3. Where it would simplify the problem you may not use built-in Python functions or libraries (e.g. using list.sort() or sorted()). Remember that this is an assignment focusing on algorithms and programming.
4. Your program will be checked against a number of test cases. Do not forget to include comments in your code explaining your algorithm. If your implementations have bugs, you may still get some marks based on how close your Algorithm is to the correct algorithm. This is made difficult if code is poorly documented.
5. For each task, you need to write a program that properly decomposes the problem. You will learn functions and decomposition in Week 3.
``````Marks: This assignment has a total of 50 marks and contributes to 8% of your final mark. Late submission will
have 10 % off the total assignment marks per day (including weekends) deducted from your assignment mark.
Assignments submitted 7 days after the due date will normally not be accepted
``````
##### Marking Criteria:

Total: 50 marks

``````A. representation and display (20 marks)
B. Mine Count (10 marks)
C. generating a board of size N x N with random placement of mines (10 marks)
D. decomposition, variable names and documentation (10 marks)
``````
##### Assignment code interview

Each student will be interviewed during a lab session regarding their submission to gauge your personal understanding of your Assignment code. The purpose of this is to ensure that you have completed the code yourself and that you understand the code submitted. Your assignment mark will be scaled according to the responses provided.

##### Interview Rubric
``````0 The student cannot answer even the simplest of questions
There is no sign of preparation
They probably havent seen the code before
0.25 There is some evidence the student has seen the code
The answer to a least one question contained some correct points
But its clear they cannot engage in a knowledgeable discussion about the code
0.5 The student seems underprepared
Answers are long winded and only partly correct
They seem to be trying to work out the code as they read it
They seem to be trying to remember something they were told but now cant remember
However they clearly know something about the code
With prompting they fail to improve on a partial or incorrect answer
0.75 The student seems reasonably well prepared
Questions are answered correctly for the most part but the speed and/or confidence they are
1 The student is fully prepared
All questions were answered quickly and confidently
Its absolutely clear that the student has performed all of the coding themselves.
``````

#### 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:

than the size^2.

#### Task 1: Representation and display (20 marks)

The simplest representation of this problem would be to represent the board as a table, where x marks the squares with mines, – marks the squares that dont have any mines.

The integer values represents how many mines surround a specific square. The value can be from 0 to 8 because each square is surrounded by eight squares.

##### Part A: Initial setup (5 marks)

Write a python function readBoard(fileName) which takes the name of a file as input and produces a two- dimensional table ( board ) to represent this board as a list of lists. The following example demonstrates a 5x board.

x-x– -x— —x- —-x

##### Part B: Display (5 marks)

Extend your program to print the board on the screen using printBoard(board) function. This function prints the contents of the board to the screen. It will replace – with spaces as shown in the example. The board square will contain either x, -, or integer value between 0 to 8.

Example 1

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

Example 2

0| |1|0|0|0|0|1| | |x| 1| |1|0|0|0|0|1| | | | 2|1|1|0|0|0|0|1|2| | | 3|0|0|0|0|0|0|0|1| | | 4|1|1|1|0|0|0|0|1|1|1| 5| | |1|0|0|0|0|0|0|0| 6|1|1|1|0|0|1|1|1|0|0| 7|0|0|0|0|0|1| |1|0|0| 8|0|0|0|0|0|1|1|1|0|0| 9|0|0|0|0|0|0|0|0|0|0| |0|1|2|3|4|5|6|7|8|9|

##### Part C: File input/output (5 marks)

Extend your program so that you can do the following:

• Write a function saveBoard(fileName,board) that writes the current board state ( board ) in its original format to a fileName entered by the user. Note: if you read from the file you just wrote to, your board state will be unchanged.
##### Part D: Menu (5 marks)

Write a function menu( ) which allows the user to choose from a set of options to perform. An example of the menu is given below: What would you like to do? 1- Read board 2- Save board 3- Print board 4- Mine count 5- New board 6- Quit ? 0| | | | | | 1| | | | | | 2| | | | | | 3| | | | | | 4| | | | | | |0|1|2|3|4| What would you like to do? 1- Read board 2- Save board 3- Print board 4- Mine count 5- New board 6- Quit ? Please enter a valid filename: example.txt example.txt has been successfully read. What would you like to do? 1- Read board 2- Save board 3- Print board 4- Mine count 5- New board 6- Quit ? 0| | | | |x| 1| | | | | | 2|x| | | | | 3| | | | |x| 4| | |x|x| | |0|1|2|3|4| What would you like to do? 1- Read board 2- Save board 3- Print board 4- Mine count 5- New board 6- Quit ? Please enter a valid filename: example.txt example.txt has been successfully saved. What would you like to do? 1- Read board 2- Save board 3- Print board 4- Mine count 5- New board 6- Quit ? Thanks for playing, bye

#### Task 2: Mine Count: (10 marks)

This task is about finding the number of mines that surrounds each square.

``````0 1 1 2 x 2
1 1 x 2 2 x
2 2 2 3 2 2
3 1 x 2 x 1
4 1 1 2 1 1
0 1 2 3 4
``````

For the example above, the square [2, 2] has three squares surrounding it that contain mines, namely, [1, 1], [3, 1], and [3, 3]. Similarly, square [0, 4] has two neighbouring mines at [0, 3] and [1, 4]. Square [2, 2] has eight neighbouring squares that need to be checked, while square [0, 4] has only three.

You need to write a function mineCount(board) that returns a new list of lists with each square representing the count of neighbouring mines, while keeping the x for the squares that have a mine.

What would you like to do? 1- Read board 2- Save board 3- Print board 4- Mine count 5- New board 6- Quit ? Please enter a valid filename: example.txt example.txt has been successfully read. What would you like to do? 1- Read board 2- Save board 3- Print board 4- Mine count 5- New board 6- Quit ? 0| | | | | | 1| | |x| |x| 2| | | |x| | 3| |x| |x| | 4| | | | | | |0|1|2|3|4| What would you like to do? 1- Read board 2- Save board 3- Print board 4- Mine count 5- New board 6- Quit ?

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

#### Task 3: Generating random boards (10 marks)

In this task you will need to ask the user for the board size N. You will also ask the user to enter the number of mines they want placed on the board. You will use these values to generate a new board of size N x N in which the mines are randomly placed in the board. N should be any value between 5 and 10 inclusive. You should validate the input. The minimum number of mines allowed should be between 0 and N x N inclusive.