### Problem Set 6

Programming Language BSL

Purpose This problem set concerns the design and creation of a larger program — something beyond the single-function exercises we’ve done up to now.

Important! Because exam 1 is on Thursday, October 16, we have provided a one-day extension on this homework, to Friday, October 17, 7:00 PM. (We return to our regularly scheduled Thursday due dates afterward, however.)

Problem 1 Develop the Bin-Packing game.

A "tetra" is made of four blocks; in this game there are seven kinds of tetra. A tetra falls from just above the top of a 10x20-block grid at a constant rate and as it falls the user can navigate the tetra left and right and rotate the tetra. The tetra cannot be moved off of the grid and once it lands on the base of the grid or another tetra, it is frozen in position and a new tetra, of randomly selected kind, falls from the ceiling. The game is over as soon as a tetra lands but extends beyond the top of the grid.

The game is scored by counting the number of blocks that have been fit onto the grid.

Your game should support at least these keyboard commands:
• left arrow: Shift the current piece left.

• right arrow: Shift the current piece right.

• s: Rotate the current piece 90 degrees clockwise.

• a: Rotate the current piece 90 degrees counterclockwise.

Here are the seven kinds of tetras and their names:
1. "O"

2. "I"

3. "L"

4. "J"

5. "T"

6. "Z"

7. "S"

This game is unlike Tetris in that blocks never go away.

The following data definitions may or may not be useful (and indicative of the kind of operations you might want to develop) for writing this program:

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Data Definitions ;; A Block is a (make-block Number Number Color) (define-struct block (x y color)) ;; A Tetra is a (make-tetra Posn BSet) ;; The center point is the point around which the tetra rotates ;; when it spins. (define-struct tetra (center blocks)) ;; A Set of Blocks (BSet) is one of: ;; - empty ;; - (cons Block BSet) ;; Order does not matter. ;; A World is a (make-world Tetra BSet) ;; The BSet represents the pile of blocks at the bottom of the screen. (define-struct world (tetra pile))

Rotations are difficult; here’s how you do it. Assuming the above data definitions, this code will perform a counterclockwise rotation of a block around a given point:

 ;; block-rotate-ccw : Posn Block -> Block ;; Rotate the block 90 counterclockwise around the posn. (define (block-rotate-ccw c b) (make-block (+ (posn-x c) (- (posn-y c) (block-y b))) (+ (posn-y c) (- (block-x b) (posn-x c))) (block-color b)))

A clockwise rotation is just the same as three counterclockwise rotations.