## CSE 131 Module 3: Arrays

### Lab

#### Workspace Update

• Update by right-clicking (control-click on Mac) the main project in the package explorer, drag down to Team... and click Update.
• You should see a lab3 package in the labs source folder.

Note and warning: It is very easy to find a solution to this problem in the Internet. This course does not have as one of its goals making you an expert on finding solutions on the Internet. The goal is to teach you the basic concepts of computer science and programming.

You are not allowed to copy any code for your solution to this problem! The solution takes some 30 lines of code, so we are not asking you to write an air-traffic controller.

However, even these 30 lines may be difficult for you to write at first. So, get help from a TA or the professor, come to office and TA hours, but do this work on your own so that you learn the material.

Be assured that you will not do well on the exam if you do not understand this material.

### MineSweeper

• This assignment is described in the book, exercise 1.4.30, on page 118. Begin by reading that exercise to make sure you understand the task assigned to you for this lab.
You may find the exercise online here, as Creative Exercise 30.
• The file you will modify for this assignment is MineSweeper.java. It is already in the respository.
• That file already prompts for the number of columns, rows, and the probability of a bomb.
Do not change that part of the file. The file is very clear about where you are to insert your code.
• Create the output as prescribed in the book's exercise.
You must use the * and . characters as shown in the book. Otherwise, the visual version of this game (described below) will not work correctly.

Your output must include both the left and right parts of each line as described below.

The example given in the book is reproduced below:
```
* * . . .    * * 1 0 0
. . . . .    3 3 2 0 0
. * . . .    1 * 1 0 0

```
You must produce output that matches the form you see above:
• Each line's left part displays the locations of the bombs (denoted by *) and the non-bombs (denoted by .).
• Each line's right part reports a * where there is a bomb and the count of bombs that border that cell where there is not a bomb.

For example:

• The leftmost entry of the second row has no bomb. In the left part of the second row, a dot is shown. Its corresponding entry in the right part of the second row shows the number 3, which is the sum of the bombs found on that cell's eight neighbors. Becasue this cell is left-most in the grid, some of its neighbors do not exist, but they are thus assumed to have no bombs.
• The mine field's central entry also has no bomb and shows a 2 in the right part of the output. Those two bombs can be found in the upper-left and lower-left cells with respect to that center cell's eight neighbors.
The book provides a nice hint about an implementation that eliminates special cases around the edges of the field.
• Run MineSweeper as a Java Application and be sure your results look correct before you demo.
Test on very small (say, 3x2) mine fields at first. Enlarge the fields and test again, making certain the output is correct.

Are you sure your output is correct?

Make sure it includes both the left and right parts of each line as described above.

• When your program is complete (or, actualy, even prior to that), you can run a visual version of your game by running Game as a Java Application.
• Our Game program runs your MineSweeper code, but hijacks the output for its own use.
The output you produce is therefore the interface between:
• Your code that computes the maze, in particular, the location of bombs, and
• The class-provided code that runs the visual version of the game.
That class-provided code has tried to be tolerant of the output you might produce. If it is not working for you, let us know.
• It builds a visual board based on your output.
• It also shows the output you produced in the console window.
To play the visual version of the game:
• Right-click on squares where you think there is a bomb.
• Left-click on a square that has no bomb to show you the count of the number of bombs that border that square.

• You must commit all of your work to your repository. It's best to do this from the top-most level of your repository, which bears your name and student ID.
• You must demo the commited work to a TA. Make sure the TA knows that your demo is for credit at this point.
• Follow the directions below to have your demo for this work recorded.

When you done with this lab, you must be cleared by the TA to receive credit.
• Fill in the form below with the relevant information
• Have a TA check your work
• The TA should check your work and then fill in his or her name
• Click OK while the TA watches

If you worked in a team using a group– repository:
• Your work must be committed in that repository for this demo.
• Each team member must complete this form and have the TA authenticate.
For example, if there are two of you, then the form must be submitted twice, so that each person's last name and 6 digit ID is captured with the repository name.
• The repository name must be included on each of the submissions.

group– Enter the name of your group repository here
 Last name 1