This wiki is archived and useful information is being migrated to the main bzflag.org website

Difference between revisions of "BZRobots/API"

From BZFlagWiki
Jump to: navigation, search
(Update with current API reference)
(Added Y/N colors)
Line 32: Line 32:
 
| void ahead(double distance)  
 
| void ahead(double distance)  
 
| Moves the robot ahead by ''distance''
 
| Moves the robot ahead by ''distance''
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| void back(double distance)  
 
| void back(double distance)  
 
| Moves the robot back by ''distance''  
 
| Moves the robot back by ''distance''  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| void doNothing()
 
| void doNothing()
 
| Does nothing (equivalent of a short sleep)  
 
| Does nothing (equivalent of a short sleep)  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| void fire()
 
| void fire()
 
| Fires a single shot  
 
| Fires a single shot  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| double getBattleFieldSize()
 
| double getBattleFieldSize()
 
| Returns the size of the battle field
 
| Returns the size of the battle field
| N  
+
! bgcolor="#BB0000" | N  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| double getGunCoolingRate()
 
| double getGunCoolingRate()
 
| Returns the time it takes to reload a single shot  
 
| Returns the time it takes to reload a single shot  
| N  
+
! bgcolor="#BB0000" | N  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| N
+
! bgcolor="#BB0000" | N  
 
|-
 
|-
 
| double getGunHeat()
 
| double getGunHeat()
 
| Returns the time until the gun will be ready to fire
 
| Returns the time until the gun will be ready to fire
| N  
+
! bgcolor="#BB0000" | N  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| double getHeading()
 
| double getHeading()
 
| Returns the current heading of the robot  
 
| Returns the current heading of the robot  
| N  
+
! bgcolor="#BB0000" | N  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| double getHeight()
 
| double getHeight()
 
| Returns the height (Z-size) of the robot  
 
| Returns the height (Z-size) of the robot  
| N  
+
! bgcolor="#BB0000" | N  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| double getLength()
 
| double getLength()
 
| Returns the length (Y-size) of the robot
 
| Returns the length (Y-size) of the robot
| N  
+
! bgcolor="#BB0000" | N  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| const char * getName()
 
| const char * getName()
 
| Returns the name (Callsign) of the robot  
 
| Returns the name (Callsign) of the robot  
| N  
+
! bgcolor="#BB0000" | N  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| double getTime()
 
| double getTime()
 
| Returns the current game time  
 
| Returns the current game time  
| N  
+
! bgcolor="#BB0000" | N  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| double getWidth()
 
| double getWidth()
 
| Returns the width (X-size) of the robot  
 
| Returns the width (X-size) of the robot  
| N  
+
! bgcolor="#BB0000" | N  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| double getVelocity()
 
| double getVelocity()
 
| Returns the speed of the robot  
 
| Returns the speed of the robot  
| N  
+
! bgcolor="#BB0000" | N  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| double getX()
 
| double getX()
 
| Returns the current X coordinate of the robot  
 
| Returns the current X coordinate of the robot  
| N  
+
! bgcolor="#BB0000" | N  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| double getY()
 
| double getY()
 
| Returns the current Y coordinate of the robot  
 
| Returns the current Y coordinate of the robot  
| N  
+
! bgcolor="#BB0000" | N  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| double getZ()
 
| double getZ()
 
| Returns the current Z coordinate of the robot  
 
| Returns the current Z coordinate of the robot  
| N  
+
! bgcolor="#BB0000" | N  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| void resume()
 
| void resume()
 
| Resumes any movements saved by a previous call to ''stop''
 
| Resumes any movements saved by a previous call to ''stop''
| N  
+
! bgcolor="#BB0000" | N  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| N
+
! bgcolor="#BB0000" | N  
 
|-
 
|-
 
| void scan()
 
| void scan()
 
| Prompts a radar scan, resulting in onScannedRobot events
 
| Prompts a radar scan, resulting in onScannedRobot events
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| void stop(bool overwrite = false)
 
| void stop(bool overwrite = false)
 
| Stops the robot, saving any current movements  
 
| Stops the robot, saving any current movements  
| N
+
! bgcolor="#BB0000" | N  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| N
+
! bgcolor="#BB0000" | N  
 
|-
 
|-
 
| void turnLeft(double degrees)
 
| void turnLeft(double degrees)
 
| Turns the robot left ''degrees'' degrees
 
| Turns the robot left ''degrees'' degrees
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| void turnRight(double degrees)
 
| void turnRight(double degrees)
 
| Turns the robot right ''degrees'' degrees
 
| Turns the robot right ''degrees'' degrees
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
! colspan=7 {{Hl3}} |==BZRobot Event Methods==  
+
! colspan=8 {{Hl3}} |==BZRobot Event Methods==  
 
|-
 
|-
 
! rowspan=2 {{Hl3}} |'''Method'''  
 
! rowspan=2 {{Hl3}} |'''Method'''  
Line 243: Line 243:
 
| void onBattleEnded(BattleEndedEvent e)
 
| void onBattleEnded(BattleEndedEvent e)
 
| Called at the end of a league match, or the server shutting down
 
| Called at the end of a league match, or the server shutting down
| N/A  
+
! bgcolor="#555555" | N /A  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| N
+
! bgcolor="#BB0000" | N  
 
|-
 
|-
 
| void onBulletHit(BulletHitEvent e)
 
| void onBulletHit(BulletHitEvent e)
 
| Called when a bullet fired by the robot hits another robot
 
| Called when a bullet fired by the robot hits another robot
| N/A  
+
! bgcolor="#555555" | N /A  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| N
+
! bgcolor="#BB0000" | N  
 
|-
 
|-
 
| void onBulletMissed(BulletMissedEvent e)
 
| void onBulletMissed(BulletMissedEvent e)
 
| Called when a bullet fired by the robot expires or hits a wall
 
| Called when a bullet fired by the robot expires or hits a wall
| N/A  
+
! bgcolor="#555555" | N /A  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| N
+
! bgcolor="#BB0000" | N  
 
|-
 
|-
 
| void onDeath(DeathEvent e)
 
| void onDeath(DeathEvent e)
 
| Called when a bullet fired by the robot dies
 
| Called when a bullet fired by the robot dies
| N/A  
+
! bgcolor="#555555" | N /A  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| void onHitByBullet(HitByBulletEvent e)
 
| void onHitByBullet(HitByBulletEvent e)
 
| Called when the robot is hit by a bullet
 
| Called when the robot is hit by a bullet
| N/A  
+
! bgcolor="#555555" | N /A  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| N
+
! bgcolor="#BB0000" | N  
 
|-
 
|-
 
| void onHitWall(HitWallEvent e)
 
| void onHitWall(HitWallEvent e)
 
| Called when the robot runs into a wall or object
 
| Called when the robot runs into a wall or object
| N/A  
+
! bgcolor="#555555" | N /A  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| void onRobotDeath(RobotDeathEvent e)
 
| void onRobotDeath(RobotDeathEvent e)
 
| Called when the robot is killed
 
| Called when the robot is killed
| N/A  
+
! bgcolor="#555555" | N /A  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| void onScannedRobot(ScannedRobotEvent e)
 
| void onScannedRobot(ScannedRobotEvent e)
 
| Called each turn as the robot's radar "sees" another robot
 
| Called each turn as the robot's radar "sees" another robot
| N/A  
+
! bgcolor="#555555" | N /A  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| void onSpawn(SpawnEvent e)
 
| void onSpawn(SpawnEvent e)
 
| Called when the robot spawns
 
| Called when the robot spawns
| N/A  
+
! bgcolor="#555555" | N /A  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
 
|-
 
|-
 
| void onStatus(StatusEvent e)
 
| void onStatus(StatusEvent e)
 
| Called at the beginning of each "turn", before the main loop is run
 
| Called at the beginning of each "turn", before the main loop is run
| N/A  
+
! bgcolor="#555555" | N /A  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| N
+
! bgcolor="#BB0000" | N  
 
|-
 
|-
 
| void onWin(WinEvent e)
 
| void onWin(WinEvent e)
 
| Called when the robot (or it's team) wins a league match
 
| Called when the robot (or it's team) wins a league match
| N/A  
+
! bgcolor="#555555" | N /A  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y  
+
! bgcolor="#00BB00" | Y  
| Y
+
! bgcolor="#00BB00" | Y  
| N
+
! bgcolor="#BB0000" | N  
 
|-
 
|-
 
|}
 
|}

Revision as of 10:21, 14 August 2009

Overview

This page describes the API for the BZRobots Programmable Computer Player Client.


The BZRobots API is based heavily on the [1] project. It is class-based, meaning that a robot is built by extending from one of the following four classes:

  • BZRobot (An easy-to-use robot with a simplified API, e.g. degree units, etc.)
  • BZAdvancedRobot (A robot with more advanced features in the API, e.g. radian units, etc.)
  • Robot (Similar to BZRobot - for [2] compatibility)
  • AdvancedRobot (Similar to BZAdvancedRobot - for [3] compatibility)


The main control loop is created by overriding the class method run, and then using the methods shown below to control the robot. These control methods fit into two categories 'blocking', and 'non-blocking'. A blocking function, once called, will not return until either the requested action has completed, or the amount of time allotted for a "turn" or "tick" has passed - whichever comes later. Non-blocking functions will return immediately, allowing for additional processing, but their actions do not take effect immediately; rather, they will take place when the execute method is called. After a blocking function has been called, various "events" that have been generated during that turn may be processed by the various event methods, if they have been overridden.


Note: As BZRobots currently supports bot scripts written in three different languages, the following is a language independent description of the methods available for bot development.

==BZRobot Methods==
Method Description Blocking Available In Functional
BZR BZAR R AR
void ahead(double distance) Moves the robot ahead by distance Y Y Y Y Y Y
void back(double distance) Moves the robot back by distance Y Y Y Y Y Y
void doNothing() Does nothing (equivalent of a short sleep) Y Y Y Y Y Y
void fire() Fires a single shot Y Y Y Y Y Y
double getBattleFieldSize() Returns the size of the battle field N Y Y Y Y Y
double getGunCoolingRate() Returns the time it takes to reload a single shot N Y Y Y Y N
double getGunHeat() Returns the time until the gun will be ready to fire N Y Y Y Y Y
double getHeading() Returns the current heading of the robot N Y Y Y Y Y
double getHeight() Returns the height (Z-size) of the robot N Y Y Y Y Y
double getLength() Returns the length (Y-size) of the robot N Y Y Y Y Y
const char * getName() Returns the name (Callsign) of the robot N Y Y Y Y Y
double getTime() Returns the current game time N Y Y Y Y Y
double getWidth() Returns the width (X-size) of the robot N Y Y Y Y Y
double getVelocity() Returns the speed of the robot N Y Y Y Y Y
double getX() Returns the current X coordinate of the robot N Y Y Y Y Y
double getY() Returns the current Y coordinate of the robot N Y Y Y Y Y
double getZ() Returns the current Z coordinate of the robot N Y Y Y Y Y
void resume() Resumes any movements saved by a previous call to stop N Y Y Y Y N
void scan() Prompts a radar scan, resulting in onScannedRobot events Y Y Y Y Y Y
void stop(bool overwrite = false) Stops the robot, saving any current movements N Y Y Y Y N
void turnLeft(double degrees) Turns the robot left degrees degrees Y Y Y Y Y Y
void turnRight(double degrees) Turns the robot right degrees degrees Y Y Y Y Y Y
==BZRobot Event Methods==
Method Description Blocking Available In Functional
BZR BZAR R AR
void onBattleEnded(BattleEndedEvent e) Called at the end of a league match, or the server shutting down N /A Y Y Y Y N
void onBulletHit(BulletHitEvent e) Called when a bullet fired by the robot hits another robot N /A Y Y Y Y N
void onBulletMissed(BulletMissedEvent e) Called when a bullet fired by the robot expires or hits a wall N /A Y Y Y Y N
void onDeath(DeathEvent e) Called when a bullet fired by the robot dies N /A Y Y Y Y Y
void onHitByBullet(HitByBulletEvent e) Called when the robot is hit by a bullet N /A Y Y Y Y N
void onHitWall(HitWallEvent e) Called when the robot runs into a wall or object N /A Y Y Y Y Y
void onRobotDeath(RobotDeathEvent e) Called when the robot is killed N /A Y Y Y Y Y
void onScannedRobot(ScannedRobotEvent e) Called each turn as the robot's radar "sees" another robot N /A Y Y Y Y Y
void onSpawn(SpawnEvent e) Called when the robot spawns N /A Y Y Y Y Y
void onStatus(StatusEvent e) Called at the beginning of each "turn", before the main loop is run N /A Y Y Y Y N
void onWin(WinEvent e) Called when the robot (or it's team) wins a league match N /A Y Y Y Y N

See Also

BZRobots/Ideas - Ideas for a possible future release