# Similar to the program developed in Chapter 1
# From an arbitrary position go to corner
# get the beepers and return

# the next 4 procedures turn 
# BB to a particular direction
define turn_north {
    while (not_facing_north) {
        turn_left
    }
}

define turn_west {
    while (not_facing_west) {
        turn_left
    }
}

define turn_east {
    while (not_facing_east) {
        turn_left
    }
}

define turn_south {
    while (not_facing_south) {
        turn_left
    }
}


define main {

    # find west wall
    turn_west
    while (front_is_clear) {
        create_beeper
        pick_beeper
        move_beeper(0,1)
        move
    }

    # find south wall 
    # (and thus the corner!)
    turn_south
    while (front_is_clear) {
        create_beeper
        pick_beeper
        move_beeper(0,2)
        move
    }

    # pick all the beepers
    while(next_to_a_beeper) {
        pick_beeper
    }

    # go back north
    turn_north
    while (has_beeper(2)) {
        move_beeper(2,3)
        move
    }

    # go back east
    turn_east
    while (has_beeper(1)) {
        move_beeper(1,3)
        move
    }

    # drop the beepers
    while (has_beeper(0)) {
        put_beeper
    }

    # move out of the way
    move
    move
    
}
