~cpp def turn_back(): repeat(turn_left,2) def turn_right(): repeat(turn_left,3) turn_left() move() def go_to_left_end(): while front_is_clear(): # go to left end move() while next_to_a_beeper(): turn_right() move() while next_to_a_beeper(): #search minimum column move() turn_right() if front_is_clear(): move() if next_to_a_beeper():#inspect whether it's empty column or not turn_back() move() turn_left() go_to_left_end() # go to left end if not next_to_a_beeper(): # it's sorted turn_back() while not next_to_a_beeper(): # go to unsorted section move() if next_to_a_beeper(): pick_beeper() # move the beeper from larger column to smaller column move() while next_to_a_beeper(): move() # search the smallest column in unordered columns put_beeper() #return to the larger column which must be sorted elif next_to_a_beeper(): pick_beeper() # move the beeper from larger column to smaller column turn_back() move() while next_to_a_beeper(): move() # search the smallest column in unordered columns put_beeper() else: # one column sorting finished turn_back() move() turn_left() go_to_left_end() turn_back() continue if not next_to_a_beeper(): turn_back() move() turn_left() go_to_left_end() turn_back() while not next_to_a_beeper(): move() turn_left() else: turn_back() while next_to_a_beeper(): move() turn_right() if next_to_a_beeper(): move() else: move() if not next_to_a_beeper(): turn_back() while not next_to_a_beeper(): move() turn_back() move() turn_right() move() turn_left() turn_off()
~cpp def such(): while not next_to_a_beeper(): if right_is_clear(): turn_right() move() else: if front_is_clear(): move() else: turn_left() def move_end(): if front_is_clear(): if next_to_a_beeper(): move() else: move() if next_to_a_beeper(): turn_left() turn_left() move() turn_left() turn_left() def move_wall(): while front_is_clear(): move() def sort_sub(): while front_is_clear(): if front_is_clear(): move() if next_to_a_beeper(): pick_beeper() turn_left() turn_left() move() put_beeper() else: turn_left() turn_left() move_endof_sub() repeat(move_end,10) def gaedan(): repeat(move_end,10) repeat(sort_sub,20) turn_left() turn_left() move_endof() turn_right() move() turn_left() def move_endof_sub(): move_wall() turn_right() move() turn_right() while not next_to_a_beeper(): move() turn_right() move() turn_left() def move_endof(): move_wall() turn_left() turn_left() while not next_to_a_beeper(): move() def sort(): move_endof() repeat(gaedan,9) def turn_right(): repeat(turn_left,3) def go_pick(): move() if next_to_a_beeper(): pick_beeper() def go_go(): turn_right() move() if next_to_a_beeper(): pick_beeper() turn_right() repeat(go_pick,5) turn_left() move() if next_to_a_beeper(): pick_beeper() turn_left() repeat(go_pick,5) def havest(): repeat(go_pick,6) turn_left() move() if next_to_a_beeper(): pick_beeper() turn_left() repeat(go_pick,5) go_go() go_go() move() turn_left() repeat(move,5) turn_left() def go_pick_sub(): move() put_beeper() def go_go_sub(): turn_right() move() put_beeper() turn_right() repeat(go_pick_sub,5) turn_left() move() put_beeper() turn_left() repeat(go_pick_sub,5) def havest_sub(): repeat(go_pick_sub,6) turn_left() move() put_beeper() turn_left() repeat(go_pick_sub,5) go_go_sub() go_go_sub() move() turn_left() repeat(move,5) turn_left() #havest() #havest() #havest() #havest() #havest_sub() sort() turn_off()
~cpp def turn(): repeat(turn_left, 2) def turn_right(): repeat(turn_left, 3) def go(): while front_is_clear(): if not next_to_a_beeper(): bringOne() if front_is_clear(): move() turn_right() move() turn_right() def justGo(): for n in range(7): move() turn() def bringOne(): while not next_to_a_beeper(): move() if not front_is_clear(): break doRest() def doRest(): turn() if next_to_a_beeper(): pick_beeper() while front_is_clear(): move() turn() move() move() while next_to_a_beeper(): move() put_beeper() else: turn() for n in range(8): justGo() go() turn_off()
~cpp ############################### # Function Public Definitions # ############################### #move/get/put functions def right(): repeat(turn_left,3) def back(): repeat(left,2) move() repeat(left,2) def go_left(): left() move() right() def go_right(): right() move() left() def go(): move() left = turn_left get = pick_beeper put = put_beeper #find beeper exist = next_to_a_beeper #################### #private functions # #################### def go_limit_right(): if not exist(): while not exist(): go_right() while exist(): go_right() go_left() def notexist_wantone(): while left_is_clear(): go_left() if exist(): get() go_right() while exist(): go_right() put() def process(): if not exist(): while left_is_clear(): go_left() if exist(): get() go_right() while exist(): go_right() put() else: #exist while left_is_clear(): go_left() if not exist(): notexist_wantone() # main source code # #robot looks top left() go_limit_right() go() for i in range(5): process() back() go_limit_right() if not exist(): while not exist(): process() back() go_limit_right() go() else: go() process() # Finish # turn_off()