|
home—lectures—recipe—exams—hws—D2L—breeze (snow day; distance)
Due Nov.02 (Mon.) in class.
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, and your hardcopy must be stapled. All functions/data must include the appropriate steps1 of the-design-recipe—the design recipe: final version. In particular, test cases alone might be worth half the credit for a function. Unless otherwise indicated, two test cases will suffice for most problems, if they are testing different situations.
Unless otherwise indicated, all problems are to be written in Racket.
As mentioned in class:
do not call any of the following functions:
(check-expect (count-bigs 7 empty) 0) (check-expect (count-bigs 7 (cons 5 empty)) 0) (check-expect (count-bigs 7 (cons 7 empty)) 0) (check-expect (count-bigs 7 (cons 9 empty)) 1) (check-expect (count-bigs 7 (cons 3 (cons 7 empty))) 0) (check-expect (count-bigs 7 (cons 9 (cons 7 empty))) 1) (check-expect (count-bigs 7 (cons 3 (cons 9 empty))) 1) (check-expect (count-bigs 7 (cons 8 (cons 9 empty))) 2) (check-expect (count-bigs 7 (cons 3 (cons 7 (cons 8 (cons 2 empty))))) 1) |
(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 solution2. 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 trick4.
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 to
remember:Feel free to use
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-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 2015.Oct.30 (Fri) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |