7.5

### Homework 12

Programming Language ISL+

Due Date: Monday April 13, 9pm AOE.

Purpose: To do exercises involving accumulators; to continue the project started in Homework 10.

Important: As with Homeworks 10 and 11, we will not accept late submissions of this homework (not with penalty, and not without penalty), so that we can finalize the semester and move on to course grades. Thus you must submit by 9pm AOE.

• This assignment is to be completed with your homework partner. As before, it suffices for one partner to submit the homework via the handin server (whatever is submitted last counts for the pair).

• You must submit a single .rkt file containing your responses to all exercises via the Handin Server. We do not accept email submissions.

• You must use the programming language specified at the top of this page.

• Your code must conform to the guidelines outlined in the style guide on the course website. The style guide will be updated as the semester progresses, so revisit it before submitting each assignment.

• Unless otherwise stated, for all programming problems you must provide (i) a signature, (ii) a purpose statement, (iii) sufficiently many check-expects (not for big-bang programs), and (iv) the code, in the language specified at the top of this page.

• Be sure to look at the feedback for previous assignments before submitting, as we will be grading you more strictly on things we have pointed out before.

Exercise 1 Design a function fold-equal-neighbors that takes a list lox of X and an equality comparison function for X and returns lox but with any sequence of consecutive equal elements "folded" into a single occurrence. For instance, given

X = (list "A" "B" "A" "A" "A" "C" "D" "D")

and the string=? comparison function, your function should return

(list "A" "B" "A" "C" "D")

Hint: use an accumulator that tracks ... what?

Exercise 2 Consider the following data design:
 ; A ParString is a String over the alphabet {"(",")"} ; representing an expression consisting of parentheses only. (define PS-0 "") (define PS-1 "()") (define PS-2 "(())") (define PS-3 "()()") (define PS-4 "())(") (define PS-5 "()(") (define PS-6 "())") (define PS-7 ")(")

Design a function balanced-paren? that takes a ParString and returns true iff the string represents an expression with correctly nested parentheses. This means that parentheses occur in pairs across the expression (no unaccounted-for "(" or ")"), and a closing parenthesis can only occur when there is a pending open parenthesis. For example, the expressions represented by ParStrings PS-0 through PS-3 are correctly nested, while the others are not.

Include at least ten meaningful check-expects (eight of which can be the examples from above, but feel free to use others).

Hint: use an accumulator that tracks ... what? Also, consider the explode function, which turns the string into a list of length-1 strings, making it easier to process the expression.

The purpose of the remaining exercises is to complete the project. Exercise 3 from Homework 11 applies: review the solutions to previous project-related homeworks, and adjust your solutions if you like. We will grade HW 12 based on whatever we receive.

Exercise 3 Design the to-draw handler for your program. Recall that the game should draw (a) the grid of cells, (b) text describing how many mines exist in the grid, (c) text describing how many cells have been flagged, and (d) text about the current status of the mouse (whether it is revealing cells or flagging them). Here are some things to keep in mind:

• Tests for large image functions like this can get messy very quickly so we recommend that you reference your helper functions in the check-expects. This can make the tests much shorter and more manageable.

• A hidden cell should always appear the same no matter what is underneath. The same is true of a flagged cell (although it should be clear which cells are flagged vs hidden).

• A visible cell has three possible contents: a mine (in which case you should show an image of a mine or explosion of some kind), a positive number (in which case you should display that number on the cell), or zero (in which case you should display a blank cell).

• The three pieces of text you need to display should be shown in a one of three colors: If the game is in progress, the text should be black. If the game has been won, the text should be green. If the game has been lost, the text should be red. Recall that you wrote functions to determine whether the game has ended in Homework 10.

Exercise 4 Finally, make sure everything is put together correctly. Replace any stubs that you may still have by the functions you implemented, re-run your check-expects, and perform system tests. This means: now that every required function exists and has been tested in isolation (this is called unit-testing), check whether all things "hang together" appropriately. There are no check-expect for system tests, in part because our "system" involves big-bang. So these tests are up to you.

There is no credit for this exercise.