Programming assignment A

Similar documents
CMSC 201 Spring 2018 Project 3 Minesweeper

CPSC 217 Assignment 3

Lab 7 Unit testing and debugging

Lab 1 Implementing a Simon Says Game

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Lab 1 Implementing a Simon Says Game

Welcome to Lab! Feel free to get started until we start talking! The lab document is located on the course website:

CS354 gdb Tutorial Written by Chris Feilbach

Project 1 Balanced binary

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

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

Week 5, continued. This is CS50. Harvard University. Fall Cheng Gong

Intro. Scheme Basics. scm> 5 5. scm>

Lab 9: Pointers and arrays

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

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

Blocky: A Game of Falling Blocks

Smoother Graphics Taking Control of Painting the Screen

CSC D84 Assignment 2 Game Trees and Mini-Max

CMSC 201 Spring 2018 Project 2 Battleship

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

Tips from the experts: How to waste a lot of time on this assignment

Welcome to Lab! You do not need to keep the same partner from last lab. We will come around checking your prelabs after we introduce the lab

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CS Homework 11 p. 1. CS Homework 11

Taskbar: Working with Several Windows at Once

pset4: Sudoku October 2, 2011 pset4: Sudoku Tommy MacWilliam Distro Code ncurses Cursor Inputting Numbers Move Legality

Lab 4: Imperative & Debugging 12:00 PM, Feb 14, 2018

************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

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

Excel Basics: Working with Spreadsheets

15-122: Principles of Imperative Computation, Spring 2013

Rescuing Lost Files from CDs and DVDs

Lab 6 Vectors and functions

Programming Assignment #4 Arrays and Pointers

CS 051 Homework Laboratory #2

Programming Project 4: COOL Code Generation

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

In this chapter, I m going to show you how to create a working

CONTENTS: Arrays Strings. COMP-202 Unit 5: Loops in Practice

1-D Time-Domain Convolution. for (i=0; i < outputsize; i++) { y[i] = 0; for (j=0; j < kernelsize; j++) { y[i] += x[i - j] * h[j]; } }

CS 142 Style Guide Grading and Details

Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017

CS 426 Fall Machine Problem 1. Machine Problem 1. CS 426 Compiler Construction Fall Semester 2017

Lecture 1: Overview

Lab 1: Space Invaders. The Introduction

Introduction to Programming

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

Arrays array array length fixed array fixed length array fixed size array Array elements and subscripting

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

Notes on Non-Chronologic Backtracking, Implication Graphs, and Learning

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

G52CPP Lab Exercise: Hangman Requirements (v1.0)

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm

Introduction to Programming with JES

377 Student Guide to C++

How to approach a computational problem

Tips from the experts: How to waste a lot of time on this assignment

Assignment #4 Minesweeper

Software Design. Introduction. Software Design (Introduction) SERG

CMSC 201 Spring 2017 Homework 4 Lists (and Loops and Strings)

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #44. Multidimensional Array and pointers

The first thing we ll need is some numbers. I m going to use the set of times and drug concentration levels in a patient s bloodstream given below.

In either case, remember to delete each array that you allocate.

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

CS260 program assignment #3 (30 points, check the schedule for the due date)

2) Craigslist s homepage and about Craigslist Craigslist has many sections which are listed on their homepage:

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

Adding content to your Blackboard 9.1 class

Installing a Custom AutoCAD Toolbar (CUI interface)


Classwork 7: Craps. N. Duong & R. Rodriguez, Java Crash Course January 6, 2015

EPISODE 23: HOW TO GET STARTED WITH MAILCHIMP

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #29 Arrays in C

HOUR 4 Understanding Events

These are notes for the third lecture; if statements and loops.

Project 1 - Battleship Game

Due: Tuesday 29 November by 11:00pm Worth: 8%

The compiler is spewing error messages.

Laboratory 1: Eclipse and Karel the Robot

Practice Midterm Examination #1

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

Installing Ubuntu Server

Lab 0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio

CIS 121 Data Structures and Algorithms with Java Spring 2018

COMP 105 Homework: Type Systems

Exsys RuleBook Selector Tutorial. Copyright 2004 EXSYS Inc. All right reserved. Printed in the United States of America.

Lecture 9: July 14, How to Think About Debugging

Lab 1: Simon. The Introduction

Lab 4: Tracery Recursion in C with Linked Lists

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Today in CS161. Lecture #12 Arrays. Learning about arrays. Examples. Graphical. Being able to store more than one item using a variable

CS 283: Assignment 1 Geometric Modeling and Mesh Simplification

Assignment #1: and Karel the Robot Karel problems due: 3:15pm on Friday, October 4th due: 11:59pm on Sunday, October 6th

Notebook Assignments

How to Break Software by James Whittaker

6.189 Project 1. Readings. What to hand in. Project 1: The Game of Hangman. Get caught up on all the readings from this week!

ECE15: Lab #3. Problem 1. University of California San Diego ( 1) + x4. + x8 + (1)

Transcription:

Programming assignment A ASCII Minesweeper Official release on Feb 14 th at 1pm (Document may change before then without notice) Due 5pm Feb 25 th Minesweeper is computer game that was first written in 1989 by Robert Donner. The game became very popular when it was distributed with Windows 3.1. It still comes with all Windows computers. This project is worth approximately 6% of your class grade. Game description Note, this is a slightly modified version of a minesweeper description found on wikipedia http://en.wikipedia.org/wiki/minesweeper_%28computer_game%29. You might find it helpful to go to that page to learn more about minesweeper. The game screen consists of a rectangular field of squares. Each square can be cleared, or uncovered, by selecting it. If a square that contained a mine is selected, the game is over. If the square did not contain a mine, two things can happen. A number will appear indicating the amount of adjacent (including diagonally-adjacent) squares containing mines. In addition, if there is no mine adjacent to that space, then the game automatically clears those squares adjacent to the empty square (since they could not contain mines). Further, anytime a space is adjacent (including diagonals) to an uncovered space with 0 mines adjacent to it, that space is also uncovered. The game is won when all squares that do not contain a mine are cleared. In our version of the game the board is displayed as a text output. Here is a 5x5 board at different stages of completion. 0... 1... 2... 3... 4... 0 0001. 1 0012. 2 111.. 3... 4... 0 0001. 1 0012. 2 111.. 3.1111 4.1000 0 0001# 1 00122 2 111#1 3 #1111 4 11000 Start of game with all the spaces covered User selected 0,0. The game uncovered the space and all spaces adjacent to any uncovered zero. User selected 4,4. The game uncovered the space and all spaces adjacent to any uncovered zero. User selected 4,0. This was a mine, so the game is over and the full board is displayed (# are mines)

Code provided We have provided you with a main program and a few functions to give you a start on writing this program. The entirety of the code provided is available on the web. The main follows: main(int argc, char * argv[]) { string fname=""; // Initialization not needed, but makes me happy. int map[cols][rows]; int found[cols][rows]; int done=0; // 0=not done, 1=player lost, 2=player won Move playermove; int movecount=0; int mines; if(argc==2) fname=argv[1]; mines=generatemap(map,fname); // if file="", generate random map. // Else generate map defined by file. // return the number of mines clearfound(found); while(!done) { displaymap(map,found); playermove=getmove(); done=updatemap(map, found, playermove,mines); movecount++; } } printscore(done, movecount, map); Note that COLS and ROWS are previously declared as global constants. The program uses the following data structures: map[][] is a two dimensional array which specifies where the mines are as well as information about the number of adjacent mines found[][] is a two-dimensional array that is used in parallel with map[][]. If found[x][y]=1, this means that the location has been uncovered by the user and should be displayed. If it is equal to zero that means the user hasn t yet uncovered the space and when the map is displayed this space should be shown as a blank. playermove is a struct which simply has the row and column the user has selected to uncover. mines is the number of mines in the map. The following functions are either written for you, partially written, or you need to write them from scratch. generatemap() will either generate a map from a file (if the user specifies one from the command line) or will generate a random map. If it is a random map you should prompt the user for the number of mines he or she wishes to have. Assuming that number is possible, you map must have that many mines! generatemap() will also set the non-mine spaces equal to the number of mines adjacent to the space. If there is a mine in the space it will set the space s value equal to MINE (which is a global constant set to be 100). The part where it reads from a file written for you. In all cases, the number of mines on the map will be sent as the return value.

clearfound() sets the entire found array to be zero (so no spaces start uncovered). You need to write this function. displaymap() displays the uncovered parts of the map. We provide this function but you really should read it carefully so that you understand what it does and what it is expecting. You shouldn t change this function unless you need to for some optional feature. getmove() prompts the user for the row and column they wish to uncover. It needs to check to be sure that the space actually exists on the map (so the row and column numbers aren t too big or too small. getmove() should tell the user if they enter an invalid row or column and ask them to try again. Optional: you can give the user the option of quiting. If the user hits a mine (or quits) you should return a 1. If the user has uncovered all non-mine spaces, the function should return a 2. (They ve won). updatemap() figures out what spaces to uncover (and changes the found array as needed) based on what the user asked to uncover. This may include more than one space if the uncovered space was a zero. You need to write this function. printscore() should at the least print the entire map (uncovered) and tell the user if he or she won or lost. If you want to compute a score based upon the number of moves or something else, you are welcome to do so. Hints, help and clues Perhaps the most important thing is Start early. By Monday the 21 st you should have the vast majority of this done and just be debugging. Debugging will take much longer than it has in the past. You really only have the following tasks: Complete generatemap(). Note, as written this involves a call to a function called findminevalues() which would populate the non-mine spaces with the number of adjacent mines(0 to 8) Write clearfound() (this is pretty easy) Write getmove(). While this is harder than clearfound(), it is still not too bad. Write updatemap(). (This is the hardest part by far) Write printscore (also quite easy, although you need to display the whole uncovered map, which might be a bit of a pain). As noted, updatemap() is the hard part, with generatemap() being a bit tricky. Once you understand the code we ve given to you, generatemap() is really the only other difficult function. You really should work on the easy parts first. Hints and clues: This project can be quite intimidating. The trick is to think of it (and of most programming) as a group of functions. We ve already done the high-level design for you you just need to write the functions! o Read the code first. While the code isn t complete, you should be able to use the skills you ve gained in reading code to understand what is going on. Take your time and read o things carefully. Start with the easy ones. clearfound(), getmove() and printscore() are all pretty simple once you understand the big picture. For generatemap(), you will need to generate random numbers. You saw how to generate random numbers back when we used random numbers find an estimate of Pi. You don t need to worry about seeding the random number generator.

o Also, you need to be really careful when counting the adjacent mines that you don t go outside of the map array bounds. This can be tricky. For updatemap() it is strongly suggested you start by just uncovering the location specified by the user and returning a 1 if they have hit a mine. Once you have that (and all the rest of the program working) you can work on uncovering everything adjacent to an uncovered 0. Getting the uncover all spaces next to an uncovered zero feature working is quite difficult. o Once you get everything else working, you need to think about how to uncover all spaces next to an uncovered zero. The hard part is being sure that you have uncovered all the squares you should. There are a number of ways to do this, but perhaps the easiest is: If the player s move uncovered a zero, walk every square on the board. If that square is next to an uncovered zero, uncover it. Once you have done that with the whole board figure out if you uncovered any zeros during that walk. If you did, you will have to walk every square again. You continue until one walk of all of the squares resulted in no new squares being uncovered. Use the Wall flag when compiling. Really. Be very careful with your array bounds. Always be checking (with asserts or whatever else) that you aren t going to go past the array bounds. As a general rule, look over every access to an array and convince yourself that there is now way the array can go past its bounds. Debugging problems like this are very hard indeed. (When Prof. Brehob wrote this assignment, he spent the better part of an hour looking for array-bound related errors. And he has a lot of experience finding these things. If you have an error like this you can easily get stuck until you get help.) In general if something really wacky is going on, you probably have an array bound error. Even if the error appears unrelated to an array in any way. Rules for the project Your code is to be based upon the code we have provided. You are welcome to make changes to our program. The only really key thing is that you must be able to read the exact same input files the code we gave you can read. We would greatly prefer you use our displaymap() function, but if you wish to add a feature we don t support (see optional parts, below) then (and only then) you are allowed to make changes to displaymap(). As always this code is to be written on your own. We will be running an autocorrelator to look for those who have copied code from each other. You may not copy code from any source other than our texts. See the course web page for further clarification on collaboration. If in doubt, ask the instructor. You will hand in the project by placing your code in a directory called PA. The ONLY.cc files that should be in that directory is your code (it can be in multiple files if you wish). When in your PA directory, the command: g++ *.cc should generate a file named a.out which is your minesweeper game. Optional features User has a way of marking a mine. If they are wrong they lose, otherwise the mine is uncovered. This would probably by having the user specify that they are uncovering something (Say the user types U 0 0 to uncover 0 0. They lose if that space is a mine. Or the user might type ( M 0 0 ) to indicate they believe that 0 0 is a mine. They lose if it isn t a mine.) User has a way of saving the game and reloading it latter. Probably involves writing a file which describes the board as well as a file specifying which spaces have been uncovered. There must be a way to restart the game after saved, even if the program has been quit. Seed the random number generator. (look around for information on srand() and time().) Something else cool.

The first 2 items would likely be worth 10 points each depending on how well you implemented it. The 3 rd might be worth around 3 points. You can t get better than 110 points on the project. Further, small extra things (like allowing the user to quit early) will not be worth any points, although they may make the game better (and easier to debug). If you have any optional features you must create a file named optional.txt which describes these features. This file must be in your PA directory. Scoring: Program works, but you don t uncover all spaces next to an uncovered 0. 80 points Program works entirely. 100 points Program works and you did some optional things. Up to 110 points You can lose points (up to 20) for poorly written (or poorly commented) code. Further, if you turn it in after its due date/time, but before Tuesday March 8 th at 5pm you will lose 20 points. After that, you will get zero points.