Last updated: Thu, 12 Feb 2015 10:47:33 -0500
DUE: Monday 2/9/2015, 9pm EST
You must use the Beginning Student with List Abbreviations language to complete this assignment. Select it via the Choose Language... menu located at the bottom-left of the DrRacket window.
Put all your solution files in a directory named set04 in your repository.
Download extras.rkt to this directory (right-click and choose "Save As"; don’t copy and paste) and commit it as well.
Use begin-for-test and rackunit to define your examples and tests.
- Don’t forget to tell us how many hours you spent working on the assignment. This should be a global variable called TIME-ON-TASK in each file. For example:
(define TIME-ON-TASK 10.5) ; hours
- So each solution file must have at least the following at the top:
(require "extras.rkt") (require rackunit) (define TIME-ON-TASK <number-of-hours-you-spent>)
- After you’ve submitted your solution, use a web browser to go to https://github.ccs.neu.edu/ and check that your repository contains the following files:
Alternate Data Definitions: For each problem, describe in prose two alternative data definitions. For each of these alternatives, list pros and cons of how the changes would affect your code. For example, some data definition changes may simplify parts of your program and make other parts more complex. You should also consider how the alternatives affect your program in terms of readability and maintainability. Sometimes a little additional complexity may be worthwhile if makes your code more understandable. These are the tradeoffs you should constantly be considering.
Put these alternative data definitions and writeups at the end of your solution file(s).
Git Commit Requirement: For this assignment, you must have at least three well-labeled git commits (including the final commit). A well-labeled git commit accurately and succinctly describes the changes since the previous commit. Something like "commit2", or "home work 3" is not an acceptable git commit label. Failure to meet this requirement will result in loss of points.
For this assignment, you must explicitly define all list data definitions. You may not use ListOf<X>.
(check-location "04" "editor.rkt")
(check-location "04" "words.rkt")
UPDATE 2015-02-08: We realize the textbook specifies an arrange-main function instead of arrangement-main. However, follow the requested provides from this problem set (i.e., call your function arrangement-main and provide it).
(check-location "04" "worms.rkt")
There can only be one food in the game at any time.
The worm eats the food if there is any overlap. A worm and food touching at only their edges are not considered overlapping.
- Instead of the food-create and food-check-create mentioned in the textbook, use these functions:
; random-posn : ??? ; Returns a random posn within a width x height canvas. ; WHERE: the returned posn satisfies ??? (define (random-posn width height interval offset) (make-posn (+ offset (* interval (random (quotient width interval)))) (+ offset (* interval (random (quotient height interval)))))) ; random-food : ListOfPosn -> Food ; ??? (define (random-food not-allowed) (food-check (random-posn CANVAS-WIDTH CANVAS-HEIGHT FOOD-DIAMETER FOOD-RADIUS) not-allowed)) ; food-check : Food ListOfPosn -> Posn ; ??? ; Strategy: generative recursion (define (food-check candidate-food not-allowed) (if (posns-overlap? candidate-food not-allowed) (random-food not-allowed) candidate-food))
UPDATE 2015-02-07: Clarified purpose statement of create-worm and replace-worm.
; world-worm : World -> Worm ; Returns a representation of the Worm in the game. ; create-worm : ListOfPosn -> Worm ; Creates a worm from the given Posns, using the first Posn in the list ; as the worm's head, and the rest of the list, in that order, ; as the worm's body. ; The resulting Worm may have other attributes of any value. ; WHERE: the list of posns are contiguous and form a valid worm ; worm-length : Worm -> PosInt ; Returns the number of segments in the given worm. ; worm-head-x : Worm -> Coordinate ; worm-head-y : Worm -> Coordinate ; Returns the x or y position of the center of the worm's lead segment. ; replace-worm : World Worm -> World ; Replaces *only the positions* of the Worm in World w with the positions ; of the given worm. Any other Worm properties in the resulting World ; should be the same as in the input World. ; WHERE: The Worm does not overlap with the food. (define (replace-worm w worm) ...) ; replace-food : World Posn -> World ; Inserts a piece of food into the world at the given Coordinates, ; replacing the existing food. ; WHERE: The food does not overlap with any of the worm's segments. ; posns-overlap? : Posn ListOfPosn -> Boolean ; Returns true if p overlaps with any elements of ps. ; Two posns touching at only their outer edges are not overlapping. (define (posns-overlap? p ps) ...)