On this page:
Going Batty
Before You Go...
Posns in Posns
6.6

Lab 3 Posns in the World

lab!

Purpose: The purpose of this lab is to practice designing and programming with Posns.

Textbook references: Chapter 3: How to Design Programs Chapter 5: Adding Structure

Going Batty

Goals: Practice designing world programs and working with Posns.

Exercise 1 Design a cute little program where a bat moves towards some fruit. The program should take the initial location of the bat. The fruit should be in the lower right corner of the screen. Every tick the bat should move towards the fruit by moving either down or right. If the bat has moved as far down as possible it will move to the right. If it has moved as far to the right as possible it should move down. Otherwise it should move randomly either down or right. The program will end when the bat reaches the fruit and will display some kind of win screen to let people know that he made it and will not starve after all.

If this all sounds very confusing, below is a video of a finished program. Yours doesn’t have to look exactly like this but it should be similar.

bat program

Before You Go...

If you had trouble finishing any of the exercises in the lab or homework, or just feel like you’re struggling with any of the class material, please feel free to come to office hours and talk to a TA or tutor for additional assistance. We love to teach and you will learn. It’s symbiotic!

Posns in Posns

Consider the following data definition:

; A BatAndMoon is a (make-posn Posn Posn)
; - where the first Posn is the location of the bat
; - and the second Posn is the location of the moon in the sky

Exercise 2 What’s one problem with this data definition? What makes it confusing? If you’re struggling to figure it out feel free to ask a tutor or TA for help.

Exercise 3 It’s too bad about that problem and we will find a way to combat that next week but for now we’re going to just ignore the problem and hope it goes away. Let’s design a new program which allows our bat to go towards the fruit while the moon goes across the sky. The moon should go up and to the right until it reaches the midway point on the screen, then it should go down and to the right. Your program should still take in only the initial position of the bat. The moon should always start in the same position (it’s up to you to decide where this is). If that all sounds confusing, here’s another video to show you what we mean: bat and moon program