Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

# ... title line ... # PROGRAM ID: luckywalk.py / The Lucky Walk Task # AUTHOR:

ID: 3728738 • Letter: #

Question

# ... 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()

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

Explanation / Answer

CODES TO COPY

treasure.py

def main():
    direction = beepers_on_corner()
    while direction != 5:
        distance = distance_clue()
        face_direction(distance)
        move_foward(distance)
        direction = beepers_on_corner()
    celebrate()
    turn_off()

#returns number of beepers on corner
def beepers_on_corner():
    count = 0
    while on_beeper():
        pick_beeper()
        count += 1
    for i in range(count):
        put_beeper()
    return count

#get distance clue
def distance_clue():
    distance = 0  
    while distance == 0:
        if front_is_clear():
            move()
            if on_beeper():
                distance = beepers_on_corner()
                while carrying_beepers():
                    put_beeper()
                turn_around()
            else:
                turn_around()
                if front_is_clear():
                    turn_left()
                else:
                    if not left_is_clear():
                        turn_right()
        else:
            turn_left()
    return distance

#turn right
def turn_right():
    turn_left()
    turn_left()
    turn_left()
#turn around 180 degrees and move to original spot
def turn_around():
    turn_left()
    turn_left()
    move()
#face direction clue gives

def face_direction(direction):
    direction = beepers_on_corner()
    if direction == 1:
        while not facing_east():
            turn_left()
    elif direction == 2:
        while not facing_north():
            turn_left()
    elif direction == 3:
        while not facing_west():
            turn_left()
    else:
        direction == 4
        while not facing_south():
            turn_left()
#move number of corners in clue
def move_foward(distance):
    for i in range(distance):
        move()
#celebrate finding treasure
def celebrate():
    while on_beeper():
        pick_beeper()
    while not facing_north():
        turn_left()
main()

test.py

def main():
   check_beepers(clus)
   if check_beepers(clue) != 5:
       distance = 0
       while distance == 0:
           find_distance()
           advance()


def turn_around():
   turn_left()
   turn_left()
   move()  
def check_beepers(bnum):
   while on_beeper():
       bnum = 0
       pick_beeper()
       bnum += 1
   if bnum != 5:
       put_beeper
   return bnum
def find_distance():
   if front_is_clear():
       move()
       if on_beeper():

           distance = check_beeper(bnum)
           return distance

           turn_around()
           move()
       else:
           turn_around()
           move()

def get_clue():
   x= check_beepers(clue)
   if x != 5:
       return x

def get_direction():
   find_distance()
   if not front_is_clear():
       turn_left()
       find_distance()
           if not front_is_clear():
               turn_left()
               find_distance()
               if not front_is_clear():
                   turn_left()
                   find_distance()
   return find_distance()
def advance():
   if get_clue()== 1:
       while not facing_east():
           turn_left()
           move(distance)
   if get_clue == 2:
       while not facing_north():
           turn_left()
           move(distance)
   if get_clue == 3:
       while not facing_west():
           turn_left()
           move(distance)
   if get_clue == 2:
       while not facing_soutn():
           turn_left()
move(distance)

If any queries regarding code and execution please get back to me

Thank You