![]() |
![]() |
|
Due
Sep.25 (Fri)Sep.27 (Sun) 23:59: the remainder (and if by original deadline, I'll add 10% of your score).
You need only submit your file hw05.rkt each time
(no .zip, thanks).
For this homework:
Reading: §6.6, and §10.1–10.3.1.
(Additional recommended, but not required, background reading: all of Chpt.6, and §10.3.
Additional, non-required, challenge-reading: § 10.5.)
All problems are to be written in Racket. Do not call any of the following functions:
Your name and the assignment-number must be in a comment at the start of the file All functions/data must include the appropriate steps1 of the design recipe. In particular, test cases alone might be worth 40-50% of the credit for a function. Have enough test cases to cover different corner cases; often 2–3 can suffice.
Remember: We can't re-assign to variables, in functional programming. So we won't have a counter which we increment, like you might in your imperative-programming class. Instead, be sure to follow the design recipe, and after copying the template, think about the inventory-with-values (assuming we call our parameters “threshold” and “nums”): if we callcount-bigs with the particular inputs(count-bigs 3 (cons 10 (cons 2 (cons 5 empty)))) , what is…Fill in each blank with a particular number, or list-of-numbers. Then, ask yourself: Starting with those pieces of info, how do I assemble them to get my desired result of 2?
threshold =nums =(first nums) =(rest nums) =(count-bigs threshold (rest nums)) =You don't need to include the above in your answer — it's just to remind you of what you do, for the “inventory-with-values” step of the design-recipe, #6. If you get stuck on any of the problems below, make sure you didn't skip this step; it's the one that can really make things click!
(check-expect (map-sqr empty) empty) (check-expect (map-sqr (cons 7 empty)) (cons 49 empty)) (check-expect (map-sqr (cons 9 (cons 7 empty))) (cons 81 (cons 49 empty))) |
Copy your hw04(structs) racket file to one that we'll use for this one.
Add a very noticeable dividing-line (say, 80
To save some typing,
feel free to rename your asteroid-struct to be an
.
I'll do that in the instructions here,
though you can use whichever name you prefer.
Your hw05 may use any/all of the hw04-soln; of course, cite any code you use like this (including a URL), just as would do for any purpose, hw or not.
Moving lists-of-objects.
Note: Your test cases can call our already-testedmove-astr , which in turn suggests your codecanshould! call it as well.
Note: The code for this will follow directly from the template. Its return value happens to be a list; we have seen that both in lecture'stee (triple-every-even), andmap-sqr above.
bounding boxes: We'll say that an oval and a triangle collide if the imaginary rectangles containing each of them overlap. That's expedient, because it's easy to tell if two rectangles
Write
Then use this as a helper to write
Note: This function takes in an astr, not a list; be sure to use the correct template.
surviveuntil the following tick. The exact details are left up to you, but you should probably have bullets
dieif either — or possible both — of the following happen: (a) the bullet has collided with some asteroid, and/or (b) the bullet dies of old-age. The former requires a helper
Note: I placed this filter last, since if you don't get to it you simply have immortal bullets, which isn't the worst possible game.
Define a “world” structure which contains one ship, a list of bullets, and a list of astrs
As usual for our data-definitions, make examples of the data (at least two).
very firstbackground-image that gets passed to other
All the above should have their tests, as well as signatures and (brief) purpose statements.
Only after all tests pass, add
(require 2htdp/universe) (big-bang some-initial-world [on-key world-handle-key] [on-tick update-world] [to-draw draw-world] [stop-when game-over?] ) |
Here is a function that you might find helpful,
to combine the result of calling
; cons3-or-0 : (union '() (cons ANY (cons ANY (cons ANY '()))),
; (list-of ANY)
; -> (list-of ANY)
; Add the exactly-three-or-zero-elements of the first list onto the front of the second.
;
; source: https://www.radford.edu/~itec380/2020fall-ibarland/Homeworks/lists/ (CC-BY)
;
(define (cons3-or-0 three-things-or-none others)
(cond [(empty? three-things-or-none) others]
[else ; it must be a list of exactly three items:
(cons (first three-things-or-none)
(cons (second three-things-or-none)
(cons (third three-things-or-none)
others)))]))
; Btw, `second` is shorthand for `(first (rest ..))`.
(check-expect (cons3-or-0 '() '())
'())
(check-expect (cons3-or-0 (cons 'hi (cons 'bye (cons 'aloha '())))
'())
(cons 'hi (cons 'bye (cons 'aloha '()))))
(check-expect (cons3-or-0 '()
(cons 100 (cons 101 '())))
(cons 100 (cons 101 '())))
(check-expect (cons3-or-0 (cons 'hi (cons 'bye (cons 'aloha '())))
(cons 100 (cons 101 '())))
(cons 'hi (cons 'bye (cons 'aloha (cons 100 (cons 101 '())))))) |
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland |