|
home—lectures—recipe—exams—hws—D2L—breeze (snow day; distance)
Due Jul.05 17:45 Note: 15min before class (but intended to be completable by Jun.28).
Reading: §6.6, and §10.1-10.2. (Additional recommended, but not required, background reading: all of Chpt.6, and §10.3. Additional, non-required, challenge-reading: § 10.5.)
Your name and the assignment-number must be in a comment at the start of the file All functions/data must include the appropriate steps of the-design-recipe—the design recipe: final version. 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 suffice.
Unless otherwise indicated, all problems are to be written in Racket. Do not call any of the following functions:
hint: 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!
(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))) |
You will not need to turn in hardcopy of things before the dividing-line if they were in your hw05 solution or in the posted hw05 solution. Any changes you make (e.g. updating the world examples to have a list-of-aliens) will be moved below the dividing line. You do not need to include part A (problems 1,2) in your part B hardcopy.
Right now, you can go ahead and move
all the
hint: When creating the expected-output for you test case, feel free to calldraw-alien . This will help remind you how we drew multiple items onto a single image, back in hw05 #4c and #4e.
(5pts)
Modify your
You'll need to
make updates to your examples of world-structs,
along with
restriction: Do not use the built-in functionremove ; the goal of this assignment is to be able to process the list yourself.
hint: We previously saw that when anif expression was either adding 1 or not, to some value, we could reduce it to add-1-or-0, and then factor out the “some value” from theif . However,cons doesn't have the equivalent to zero that+ has: there is no way to say “cons nothingness onto a list, returning the same list”. So we can't use that same trick.
Add the player firing: If the player presses the "fire" button, the world's bullet is replaced with a new one just above the cannon.
Design discussion: When playing the game, after a bullet hits an alien, there is no bullet left in the world. But our world structure always has a bullet field! How to fix this?
Similarly, if the bullet hits an alien, it should disappear.
(This isn't part of handling a keypress.
Which function should check for this?)
This may involve a helper function,
or you can look up
challenge: Instead of the above three functions, write a single one which will handle all cases. For example, you might havemost : list-of-alien, (alien→real), (real,real→real) → real . (The third input will either bemax ormin ; it's up to you to figure out what you might use as the second input.) Alternately, you can use calls tomap andsort .
Now, upgrade your
language-level: In order to pass a function tomap , you'll need change: Language » Choose Language… » Intermediate Student.
remember:Feel free to uselet* , if you like.
Extra credit:
Add alien-bullets to the world.
I'll leave it to you do decide how to best do this.
Helper functions might include
All the above should have their tests, as well as signatures and (brief) purpose statements. Only after all tests pass, you can check that the following works:
(require 2htdp/universe) (big-bang some-initial-world [on-key world-handle-key] [on-tick update-world] [stop-when (λ (w) … (bottommost …) …)] [to-draw draw-world]) |
1 Your final program doesn't need to include any "transitional" results from the template: For example, you don't need the stubbed-out version of a function from step 5. However, you should still have passed through this phase. ↩
2 Your hw06 may use any/all of the hw05/hw05-soln.rkt; of course, cite any code you use like this (including a URL), just as would do for any purpose, hw or not. ↩
3
Alternately, you can leave
4
But with higher-order-functions, you can still do some refactoring:
you can say “we always do something with the two parts from the template:
we either
home—lectures—recipe—exams—hws—D2L—breeze (snow day; distance)
©2015, Ian Barland, Radford University Last modified 2016.Jul.10 (Sun) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |