Description
Expectations
-
You and your partner must submit a single .rkt file containing your responses to all exercises via the Handin Server. We accept no email submissions.
-
You must use the 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. (You can resubmit as many times as you like until the due date without penalty.)
-
Unless otherwise stated, every function and data definition that you design, including helper functions, must follow all steps of the design recipe.
Failure to comply with these expectations will result in deductions and possibly a 0 score.
Finger Exercises:
Graded Exercises:
Note that for this homework, you must use foldr, filter, map, andmap, ormap, and/or build-list when appropriate.
These four functions use the definition of S-expressions from class (where again, we write out the list definition explicitly just for clarity):
-
; – Number
; – String
; – Boolean
; – Symbol
;
; – Atom
; – ListOfSExpr
;
; – ‘()
; – (cons SExpr ListOfSExpr)
Exercise 2 Design the function print-sexpr, that takes in an SExpr and produces a string that looks like ISL code:
-
Numbers are rendered using number->string
-
Strings are rendered as themselves, surrounded by double-quotes. (For simplicity, you may assume that any strings in your s-expressions do not themselves contain any quotes or other special characters.)
-
Booleans are rendered as #true or #false
-
Symbols are rendered using symbol->string, and preceded by a single quote
-
Lists are rendered as the string “(list”, followed by a space-separated string of rendering the expressions, followed by a closing “)”. (The empty list would be rendered as “(list)” without any spaces.)
Exercise 3 Consider the following data definition:
-
-
; – X
; – [List-of [Wide-tree X]]
-
Design a function sexpr-map that takes in an SExpr and four functions (with signatures [Number -> X], [String -> X], [Boolean -> X] and [Symbol -> X]), and produces a [Wide-tree X] that is the same shape as the original s-expression, but where each Atom in the s-expression has been transformed by the appropriate function.
Exercise 4 Design a function all-numbers? to check whether every Atom in an SExpr is a number.
Exercise 5 Design a second function to check whether every Atom in an SExpr is the string “hi”. Generalize this function and all-numbers? to a new abstraction for working with s-expressions. Rewrite your all-numbers? implementation to use this new abstraction. (Hint: it’s very much analogous to a list abstraction you’ve already seen.)
Tetris Wrap-Up
Exercise 6 Incorporate the feedback you received on your last Tetris assignment (Homework 8, see feedback on handin server). Make the suggested improvements and fix any bugs that still exist.
Note If you do not correct design errors and functionality errors pointed out on Homework 8, you will likely lose points for them again on this homework. Again, remember that our goal is not merely to hack together something that works, but to craft a program that is designed well.
Exercise 7 Give your program the missing feature that will make it a full Tetris game: whenever some row of the board is completely full of bricks, it should be deleted, and everything above shifted down one row.
Exercise 8 Finally, add scoring to your game. A player scores points each time rows are cleared and the number of points is based on the number of rows cleared all at once according to the following formula: 10 * sqr(num-rows-cleared). Therefore, a player scores 10 points when a single row is cleared, 40 points when two rows are cleared at once, 90 when three rows are cleared at once, and so on. While playing the game, the current score should be displayed somewhere to the right of the board. You should also modify your main function so that it returns the final score when the game ends.