# LIBRARY FUNCTIONS
# This file contains no line define main
# and so will not run in BeeperBot as is.

# Instead it is a collection of predefined procedures
# that can be copied to your program as needed.
# We refer to such a collect as a library.
# Modern languages typically come with huge libraries 
# that can be included automatically with few lines of code
# e.g. a library of mathematical functions; 
#      a library for input/output etc.


# turn_right is not built in
define turn_right {
     turn_left
     turn_left
     turn_left
}

# turn_around does a 180
define turn_around {
    turn_left
    turn_left
}

# 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
    }
}

# the following moves BB to 1 1
# which is the lower left corner
# of its world 
# works from any start location
define Home {
    turn_west
    while(front_is_clear) {
        move
    }
    turn_south
    while(front_is_clear) {
        move
    }
}
