FHP Language Overview
FooBots are programmed in a language called FHP (pronounced "foop"). FHP is based on PHP, so it should be immediately familiar to many programmers. If you know how to do something in PHP, you already know how to do it in FHP. For anything you don't already know how to do, there are tons of PHP tutorials, sample programs, and code snippets on the web that can be directly applied to FHP with little or no change.
Here is a small sample of a FHP program:
variable $random, $direction;
$random=rand(0,1);
$direction=$random?'F':'R';
foo_drive($direction);
while (true)
{
foo_laser(foo_gettime()%2);
}
All of the control structures from PHP (such as for-loops, if-then statements, switch-statements) are also available in FHP, as well as most of the standard functions PHP programmers are used to. Certain more exotic PHP structures and features which would be of no use for controlling bots have been omitted from FHP.
Keep in mind the following important differences from PHP:
- There are no "open" (e.g. <?) or "close" (e.g. ?>) tags. FHP is always in program mode.
- All variables must be declared before they can be used. This is done with the variable keyword.
- Variables and functions do not have special attributes such as abstract, static, final, private, public, protected.
- There are no include or require statements.
- There are no output commands such as echo or print.
- There are no file handling commands such as fopen or dir.
- There are no subprocess commands such as popen, eval, or the backtick operator.
- There are no classes, objects, or other OOP constructs.
- There are no variable variables.
- Variable names may not start with an underscore.
- Function names may not start with "foo_" which is reserved for internal bot control functions.
Many customary PHP functions such as abs(), rand(), and substr() are also available in FHP. In addition there are many new functions which are used to control the bot or retrieve data from the bot's sensors. For a list of all available functions see the following link.