Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# ... title line ... # PROGRAM ID: luckywalk.py / The Lucky Walk Task # AUTHOR: course instructor # INSTALLATION: MTSU # REMARKS: Reeborg has

# ... title line ... # PROGRAM ID: luckywalk.py / The Lucky Walk Task # AUTHOR: course instructor # INSTALLATION: MTSU # REMARKS: Reeborg has decided to go on a "walkabout". Reeborg starts # his walk with an unknown, but non-zero, number of beepers in his # pocket. Reeborg moves from rest area to rest area. Reeborg uses # the following criteria to decide where to go and when to stop. If # Reeborg ever rests on a corner with no beepers on it, he will end his # walk. If a corner has an EVEN number of beepers on it, Reeborg will # turn left and then walk that number of beepers forward to his next # rest area. If a corner has an ODD number of beepers on it, Reeborg # will turn right and then walk that number of beepers forward PLUS an # additional move forward (for luck) if he's facing north in his walk. # This additional move forward is ONLY done on a northbound walk that # results from having turned right because of there being an odd number # of beepers on a corner. If Reeborg has any beepers in his pocket, # Reeborg leaves each rest corner with one more beeper than were there # originally (i.e., he deposits a beeper if he can). If Reeborg has # run out of beepers, he simply leaves each rest corner with the same # number of beepers as were there originally. # # $PUB contains one applicable sample world: luckywalk.wld

def main(): # Determine number of beepers on rest corner number_of_beepers = beepers_on_corner() while number_of_beepers > 0: # Before leaving corner, leave a beeper if possible if carrying_beepers(): put_beeper() # Go to next rest corner follow_walkabout_rules( number_of_beepers ) # Determine number of beepers on rest corner number_of_beepers = beepers_on_corner() # Leave a beeper, if possible, on final rest corner if carrying_beepers(): put_beeper() turn_off()

# Return a count representing the number of beepers on a corner. # This function does NOT change the final number of beepers on the corner. def beepers_on_corner(): beeper_tally = 0 # Counter used to track number of beepers

# Count how many beepers Reeborg was able to pick up while on_beeper(): pick_beeper() beeper_tally = beeper_tally + 1

# Return the picked up beepers to corner for x in range(beeper_tally): put_beeper()

return beeper_tally

# Move Reeborg according to the rules of the walkabout. That is, # if given an EVEN number as an argument, turn Reeborg left and # move that number of corners forward. Otherwise, turn Reeborg # right and move that number--check in this case if facing north # in which case Reeborg is moved one extra corner. def follow_walkabout_rules(count): if count%2==0: turn_left() move_forward(count) else: turn_right() if facing_north(): move_forward(count+1) else: move_forward(count)

# Move forward "distance" amount def move_forward(distance): for x in range(distance): move()

# Pivot Reeborg 90 degrees to right. def turn_right(): for x in range(3): turn_left()

# Main main()

image text in transcribed

TS CSCI 1170 - Computer Science I TENNESSEE STATE UNIVERSITY The Follow the Treasure Map Task OLA108 Project Due: March 12,2018 NOTE: Please remember that projects are due by midnight (defined to be 11:59pm) of the day due. Late projects will be accepted subject to the grade reduction schedule described in the syllabus BACKGROUND: Reeborg likes to take long meandering walks in his world. On one such walk he discovered a map showing the way to some treasure. Reeborg is puzzled as to how to follow the clues an

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

u = 5 j , v = 6 i Find the angle between the vectors.

Answered: 1 week ago