CPSC 217 Assignment 3

Similar documents
CPSC 217 Assignment 3

CPSC 217 Assignment 4

CMSC 201 Spring 2018 Project 3 Minesweeper

Programming assignment A

Late Penalty: Late assignments will not be accepted.


CPSC 121: Models of Computation Assignment #5

Major Assignment: Pacman Game

Unit: Rational Number Lesson 3.1: What is a Rational Number? Objectives: Students will compare and order rational numbers.

Section Marks Pre-Midterm / 32. Logic / 29. Total / 100

Solving Minesweeper Using CSP

CS 210 Fundamentals of Programming I Spring 2015 Programming Assignment 4

CSCI 204 Introduction to Computer Science II

Repetition Through Recursion

Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018

CS2 Practical 1 CS2A 22/09/2004

CMPSCI 187 / Spring 2015 Hangman

Assignment #4 Minesweeper

CMSC 201 Spring 2018 Project 2 Battleship

: Principles of Imperative Computation. Fall Assignment 5: Interfaces, Backtracking Search, Hash Tables

CSCI 1301: Introduction to Computing and Programming Spring 2018 Project 3: Hangman 2.0 (A Word Guessing Game)

CMPSCI 120 Extra Credit #1 Professor William T. Verts

CS 051 Homework Laboratory #2

Decision Logic: if, if else, switch, Boolean conditions and variables

Computer Science E-119 Fall Problem Set 1. Due before lecture on Wednesday, September 26

CS 201 Advanced Object-Oriented Programming Lab 5 - Sudoku, Part 1 Due: March 3/4, 11:30 PM

15-780: Problem Set #2

The State Universtiy of New York, Korea Computer Science

Millionaire. Input. Output. Problem limit seconds

Paul's Online Math Notes. Online Notes / Algebra (Notes) / Systems of Equations / Augmented Matricies

Assignment 4. Aggregate Objects, Command-Line Arguments, ArrayLists. COMP-202B, Winter 2011, All Sections. Due: Tuesday, March 22, 2011 (13:00)

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

QUICK EXCEL TUTORIAL. The Very Basics

GRADE 3 SUPPLEMENT. Set C2 Geometry: Triangles & More. Includes. Skills & Concepts

Integers and Rational Numbers

Lab 1 Implementing a Simon Says Game

CE151 ASSIGNMENT

This homework has an opportunity for substantial extra credit, which is described at the end of this document.

Making Tables and Figures

Problem A: Collatz Conjecture

Honors Computer Science Python Mr. Clausen Programs 4A, 4B, 4C, 4D, 4E, 4F

CS 142 Style Guide Grading and Details

Answer Key Lesson 5: Area Problems

15100 Fall 2005 Final Project

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

Chapter 1 Section 1 Lesson: Solving Linear Equations

Agent Design Example Problems State Spaces. Searching: Intro. CPSC 322 Search 1. Textbook Searching: Intro CPSC 322 Search 1, Slide 1

Practical 2: Ray Tracing

Access Intermediate

CS 2110 Fall Instructions. 1 Installing the code. Homework 4 Paint Program. 0.1 Grading, Partners, Academic Integrity, Help

Assignment #1: /Survey and Karel the Robot Karel problems due: 1:30pm on Friday, October 7th

Mehran Sahami Handout #7 CS 106A September 24, 2014

STUDENT LESSON A12 Iterations

Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function

You can delete the default blank background by clicking on its Delete button.

CS 134 Programming Exercise 9:

POWERONE TEMPLATES A DOCUMENT DESCRIBING HOW TO CREATE TEMPLATES.

Honors Computer Science Python Mr. Clausen Program 7A, 7B

CS 2110 Summer 2011: Assignment 2 Boggle

Lab 1 Implementing a Simon Says Game

Using Flash Animation Basics

CMSC 201 Spring 2017 Project 1 Number Classifier

EXCEL BASICS: MICROSOFT OFFICE 2010

CS1 Lecture 5 Jan. 25, 2019

Assignment 5: MyString COP3330 Fall 2017

Pacific Northwest Region Programming Contest Division 2

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

Part 6b: The effect of scale on raster calculations mean local relief and slope

Decisions, Decisions. Testing, testing C H A P T E R 7

Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function

Homework 1. Hadachi&Lind October 25, Deadline for doing homework is 3 weeks starting from now due date is:

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms

Programming Project 1

1 Introduction to Using Excel Spreadsheets

Ce qui est important dans l'enseignement des mathématiques. Marian Small novembre 2017

EXCEL BASICS: MICROSOFT OFFICE 2007

Assignment 7: Due Wednesday May 11 at 6pm UPDATES on Monday May 9

Accounts and Passwords

Data Structure and Algorithm Homework #6 Due: 5pm, Friday, June 14, 2013 TA === Homework submission instructions ===

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab

Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018

University of Manitoba Open Programming Contest September 22, General Instructions:

Chapter 10 Working with Graphs and Charts

CompSci 105 S2 C - ASSIGNMENT TWO -

Assignment #6 Adventure

Lab 12: Lijnenspel revisited

Project 1: Scheme Pretty-Printer

Using Microsoft Excel

Plotting Points. By Francine Wolfe Professor Susan Rodger Duke University June 2010

Excel 2010 Functions. 4/18/2011 Archdiocese of Chicago Mike Riley

4 th Grade TEKS. I Can. Statements. Math. Mindy Thomas

Microsoft Excel 2010 Training. Excel 2010 Basics

Twelfth Annual Ohio Wesleyan University Programming Contest April 7, 2018 Rules: 1. There are six questions to be completed in four hours. 2.

MIT Programming Contest Team Contest 1 Problems 2008

CSE143X: Computer Programming I & II Programming Assignment #9 due: Monday, 11/27/17, 11:00 pm

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

To practice overall problem-solving skills, as well as general design of a program

VLOOKUP() takes three mandatory parameters and one default/optional parameter:

Create ruler guides. Create a ruler guide

Transcription:

CPSC 217 Assignment 3 Due: Monday November 23, 2015 at 12:00 noon Weight: 7% Sample Solution Length: 135 lines, including some comments (not including the provided code) Individual Work: All assignments in this course are to be completed individually. Students are advised to read the guidelines for avoiding plagiarism located on the course website. Students are also advised that electronic tools may be used to detect plagiarism. Late Penalty: Late assignments will not be accepted. Submission Instructions: Your program must be submitted both on paper and electronically. Your paper submission, consisting of a printed copy of your.py file, should be deposited in the appropriate assignment drop box on the second floor of the math sciences building. Your electronic submission should be submitted to the Assignment 3 drop box in D2L. You don t need to submit SimpleGraphics.py because we already have it. Description In this assignment you are going to implement portions of the classic game Minesweeper. While the game dates back to the 1960s, it can still be played today on a variety of websites. A brief description of the game appears in the following paragraph. A more complete description is available on Wikipedia. Minesweeper is a single player puzzle game. The player is presented with a rectangular game board that is broken down into a grid. Each location in the grid can either be a mine or an open space. At the beginning of the game, all of the locations are covered, so the player doesn t know which locations are mines and which locations are open spaces. The object of the game is to clear all of the open spaces (by left clicking on them) without clicking on a mine. When an open space is uncovered it reports the number of mines that are present in the 8 immediately adjacent spaces. This gives the player information that helps him or her successfully clear the remainder of the board. A square that the player has determined to be a mine can be marked as such by right clicking on it. By default, the game starts in easy mode which uses a board with 9 rows, 12 columns and 10 mines. Running the command "python mine_sweeper.py medium" will start a game with 10 rows, 20 columns and 35 mines. You can also start the game in its most difficult mode by replacing medium with hard. Be sure to test your program for each game mode.

I have written all of the user interface code (graphics and mouse) for the game. Your task is to write the functions that implement most of the game logic. These functions are described in the following sections. Note that you must follow the implementation instructions exactly. If your function has a different name, takes a different number of parameters, or returns a different value then my code will not be able to call it successfully, and the game will not work. Part 1: Creating the Board We will use a two dimensional list to represent the game board. Each element in the list will be a two character string. The first character in the string will either be a C, indicating that the board space is covered, a V, indicating that the board space is visible, an M, indicating that the space is covered and the player has marked the space as a mine, or a?, indicating that the space is covered and the player has marked the space as unknown. The second character in the string will either be a space which indicates that the space is empty, or a * which indicates that the space is a mine. Write a function named createboard (notice the use of a lowercase c and an uppercase B). Your function will take 3 parameters: The number of rows in the board, the number of columns in the board, and the number of mines that should be placed at random locations on the board. Your function should return a two-dimensional list where every element is a 2-character string. The first character should be C in every location. The second character should be an * for the number of mines indicated and a space in all other cases. The mines should appear at random positions within the board. Your function should return the two dimensional list as its only result. Hint: I think that the easiest way to write this function is to begin by creating a board where every space is covered and empty, represented by the string "C ". Then replace some occurrences of "C " with "C*", ensuring that you don t put two mines on top of each other. Run the Minesweeper game after implementing this function. While the game won t work yet, my automated tests will give you feedback on whether or not you have this function working. Do not proceed to Part 2 until this function passes all of my tests. My implementation of createboard is about 15 lines of code without any comments. Part 2: Checking for a Mine Every time the player left clicks on the board the game needs to check and see if that location holds a mine or an open space. If the space holds a mine then the player loses. Otherwise the game needs to reveal that space (and possibly additional adjacent spaces). Write a function named ismine. The ismine function will take 3 parameters: the game board, a row within the board, and a column within the board. The function should return True if the indicated location in the board holds a mine. Otherwise it should return False. This should be a really short function. My implementation is only 3 lines of code. My code will also test this function when the game starts.

Part 3: Adjacent Mines When a square is revealed (and it doesn t contain a mine) the game tells the player how many mines are located in its (up to) 8 nearest neighbours. Write a function named nummines that performs this task. Your function will take the game board, row, and column as its only parameters. It will return an integer between 0 and 8 as its only result. Make sure that your function correctly handles cases at the edge of the board. In particular, note that the corner spaces of the board only have 3 neighbours, and the non-corner edge spaces only have 5 neighbours. Also, don t count the space you are on only count the neighbours. My implementation of the nummines function is almost 30 lines of code without any comments, but a little bit of creative will allow you to create a more compact implementation. This function is also tested by my code when the game starts. Part 4: Checking for a Visible Space The user interface needs to know which spaces are covered and which spaces are visible in order to draw the board correctly. To facilitate this, you need to write a function named isvisible. This function will take the game board, a row and a column as its only three parameters. It will return True if the position indicated is visible. Otherwise it will return False indicating that the position is covered. Hint: A position is visible if the first character in the string at the row and column indicated is a V. Otherwise it is covered. Like ismine, this should be an approximately three line function. This is the last function that my code tests. One you have completed this function, the game board should draw and you should be able to reveal squares on it. However, the game won t be able to realize that you have won until you complete the haswon function described in the next section, and the game will be much easier to play once you complete the reveal function in the final part of the assignment. Part 5: Has the Player Won? I have provided an implementation of the haswon function that always returns False. You need to replace my implementation with a version that correctly determines whether or not the player has cleared all of the non-mine spaces from the board. This is actually easier to do by describing the situations where the user hasn t won. The user has not won if: There are any spaces on the board where the space has been marked as a mine but the space doesn t contain a mine There are any spaces on the board that are covered that do not contain a mine There are any spaces on the board that are marked as unknown, indicated by a? If none of these situations apply then you should conclude that the user has won. My implementation of haswon is 10 lines of code (without any comments). Once you have this function implemented the game should work in a minimalist way. Implement the last function in order to have a better version of the game (and to finish the assignment).

Part 6: Revealing the Rest of the Board In most implementations of Minesweeper clicking a location on the board that is adjacent to zero mines reveals all of the adjacent squares that can trivially to be determined not to contain a mine. While this functionality isn t necessary for the game, it makes it faster and more enjoyable to play. I have provided an implementation of the reveal function that only reveals one square without revealing the appropriate neighbours. Your task is to replace my implementation of the function with an implementation that provides the better behaviour. The better behaviour can be accomplished using the following algorithm. If you prefer, you are also welcome to use a different algorithm, or a recursive solution, provided that it generates correct results. Regardless of the algorithm used, your implementation of reveal must continue to take to the game board, row and column as its only parameters. The reveal function should not return a result. If the square in question has any mines in its immediately neighbouring squares then Reveal the current square and do nothing else Otherwise Create two new, empty, lists, one to hold row values and one to hold column values Add the row provided as a parameter to the row list Add the column provided as a parameter to the column list As long as there is at least one item in each list Remove an item, r, from the row list and the corresponding item, c, from the column list Make the location at row r and column c visible If location (r, c) is not adjacent to any mines For each of its (up to 8) neighbours If the neighbour is currently covered Add the neighbour s row to the row list and its column to the column list My implementation of this algorithm was approximately 40 lines of code including some blank lines and comments. You might be able to come up with a way to write it more compactly than I did. Additional Requirements: You must not modify any of the code that I have provided except for: o The body of haswon o The body of reveal o The order in which the tests are applied (if you choose to tackle the assignment in a different order then I have presented it in this write-up this is not recommended) All lines of code that you write must be inside functions (except for the function definitions themselves and any constant definitions). You must create and use the functions described previously in this document. Do not define one function inside of another function. You must make appropriate use of loops. In particular, your program should work for game boards of various sizes.

Include appropriate comments on each of your functions. All of your functions should begin with a comment that briefly describes the purpose of the function, along with every parameter and every return value. Your program must not use global variables (except for constant values that are never changed, and in this assignment you may not even find that you want any global constants). Your program must use good programming style. This includes things like appropriate variable names, good comments, minimizing the use of magic numbers, etc. Your program should begin with a comment that includes your name, student number, and a brief description of the program. Grading: This assignment will be graded on a combination of functionality and style. A base grade will be determined from the general level of functionality of the program (Does it create the board correctly? Does it correctly identify the number of mines adjacent to a square? Does it reveal the board correctly when a square with 0 mines adjacent to it is clicked?). The base grade will be recorded as a mark out of 12. Style will be graded on a subtractive scale from 0 to -3. For example, an assignment which receives a base grade of 12 (A), but has several stylistic problems resulting in a -2 adjustment will receive an overall grade of 10 (B+). Fractional grades will be rounded to the closest integer. Total Score Letter (Out of 12) Grade 12 A 11 A- 10 B+ 9 B 8 B- 7 C+ 6 C 5 C- 4 D+ 3 D 0-2 F