6.11.0.4

Week 4 Set c

home work!

Programming Language BSL

Due Date Fri at 9:00pm (Week 4)

Purpose This problem set resumes the graded exercise of Week 4 Set a and continues list exercises.

Finger Exercises

Exercise 1 Design the function to-posns. It consumes a list of Vels and produces a matching list of Posns.

(define-struct vel (x y))
; A Vel is (make-vel Number Number).

Exercise 2 Design the function find-this-posn. It consumes a non-empty list of Posns and a number. Its result is the first Posn whose x coordinate is equal to the given number. You may assume that the list contains at least one Posn with this x coordinate.

Graded Exercises

Exercise 3 Design the function separate. The function consumes a non-empty list L of strings and a string S. It produces a list like L with S inserted between all items.

Exercise 4 The software architect of ApperGamer has produced a modified design document in preparation of a second release. As you can see, the change introduces a list of AI turkeys so that the AI player has a larger chance of getting to the food before the player:
; Gobbler = (make-world Number ListTurkey Turkey Food)
; ListTurkey is one of:
;  (cons Turkey '())
;  (cons Turkey ListTurkey)
While ListTurkey always contains at least one Turkey, you may on occasion wish to act as if it might possibly be empty. Why is this safe?

Your tasks are as follows:
  • Adjust all occurrences of make-gobble so that they now use a list of an ai player not just one. This task includes both uses of make-gobble in tests and functions.

  • Find all places where your program uses gobble-ai. Its result is now a list of turkeys not a single turkey.

    If this list goes back into a Gobbler, your program is fine.

    If not, introduce wish-list entries that consume these lists. These functions must come with signatures (input is at least ListTurkey), purpose statements, and dummy headers.

    If the result of such a function is also a ListTurkey and does not go into a Gobbler, you may need additional wish list functions.

  • Make sure your program runs with failing tests.