RealTimeBattle
RealTimeBattle is a programming game, in which robots controlled by programs are
fighting each other. The goal is to destroy the enemies, using the radar to examine the environment
and the cannon to shoot.
This module allows you to create robots written in BlitzMax, to compete with other robots in the RealTimeBattle
arena.
Here is a list of features of RealTimeBattle:
- Game progresses in real time, with the robot programs running as child processes to RealTimeBattle.
- The robots communicate with the main program using the standard input and output.
- Robots can be constructed in almost any programming language.
- Any number of robots can compete simultaneously if allowed by your operating system.
- A simple messaging language is used for communication, which makes it easy to start constructing robots.
- Robots behave like real physical object.
- You can create your own arenas.
- Highly configurable.
Getting Started
If you don't have it already, you will need to download RealTimeBattle from
http://realtimebattle.sourceforge.net. You can also
find out the latest news, information and system requirements from there.
Once this has been compiled and installed (see the RealTimeBattle documentation), you are ready to start
building your own your robots.
The RealTimeBattle server loads robots based on their filename, which ends with ".robot". For convenience,
when creating the Max source file for your robot, you should name it with .robot.bmx as the
suffix. For example, maxbot.robot.bmx. When you come to compile your robot in release mode, it will compile to
maxbot.robot, saving you a step of hassle renaming it.
Note: You should always compile your robot in release mode, as it uses stdin and stdout to communicate with
the RealTimeBattle server, which I believe is also used for debug mode, and therefore your mileage may vary if you
decide to use debug mode. In any case, RealTimeBattle has a facility which allows you to send "debug"/messages to
the server, which can be displayed on-screen.
Robot Construction
Building robots with BlitzMax is meant to be easy.
To create your own, you simply extend TRTBRobot and override whichever methods you think
you need to make your robot.
The robot API is split into two main sets of methods :
- Methods for sending instructions to the server (message from robot)
- Methods for acting on messages from the server (message to robot)
Plus a couple of methods for getting things started.
Start of the Game
Running your robot couldn't be any easier...
Local bot:TMyRobot = New TMyRobot
bot.run()
where TMyRobot extends the base TRTBRobot.
For setting up your own data, you can override InitializeRobot, which is called automatically.
Acting on Server messages
When your robot receives a message from the server, the corresponding method is called to allow you to act upon it.
These methods are prefixed with Action. For example override ActionRobotsLeft
if you want to be notified of the number of remaining robots in the arena.
The other actions you can override are, ActionYourName,
ActionYourColour, ActionGameOption,
ActionGameStarts,
ActionRadar, ActionInfo,
ActionCoordinates, ActionRobotInfo,
ActionRotationReached, ActionEnergy,
ActionCollision, ActionWarning,
ActionDead, ActionFinished and ActionExitRobot.
Making your robot dance
Of course, you need to be able to make your robot do things, otherwise it would be a very boring arena.
You can call the following methods to tell the server what you want your robot to do :
Accelerate, Brake,
RobotOption,
Rotate, RotateAmount,
RotateTo, Shoot,
and Sweep.
If you want to send a message, you can call the Print method.
To send debug messages, you can call
Debug, DebugCircle and DebugLine.
Interesting Information
Lastly, TRTBRobot holds some details that you might find useful, these include valid
ranges when performing movements, and various levels, allowing your robot to adapt to its environment and win
those all important grudge matches.
You should consider the following fields "Information Only" :
debugLevel, robotCannonMaxRotate,
robotEnergyLevels, robotMaxAcceleration,
robotMaxEnergy, robotMaxRotate,
robotMinAcceleration, robotRadarMaxRotate,
robotStartEnergy, sendRobotCoordinates,
shotEnergyIncreaseSpeed, shotMaxEnergy,
shotMinEnergy, shotSpeed and
timeout.
You can modify the following fields before the game starts :
name, homeColor and awayColor.
Example
Here is a very basic robot which simply rotates its cannon and radar from wherever it starts in the arena
and shoot at any robots it happens to see (You can also open the code in the editor) :
SuperStrict
Import BaH.RealTimeBattle
Local bot:TMyRobot = New TMyRobot
bot.run()
Type TMyRobot Extends TRTBRobot
Method InitializeRobot()
name = "I'm Basic!"
End Method
Method ActionGameStarts()
Rotate(ROT_CANNON | ROT_RADAR, 10)
End Method
Method ActionRadar(distance:Double, observedObject:Int, radarAngle:Double)
Select observedObject
Case OBJ_ROBOT
Shoot(10)
End Select
End Method
End Type
Types
| Type TRTBRobot |
| Description | The RealtimeBattle Robot base type. |
| Field awayColor:String = "ff6666" |
| Description | The robot away color. |
| Field color:String |
| Description | The actual robot color. |
| Information | This. |
| Field debugLevel:Int |
| Description | The debug level is a way of telling robots which messages they should send. |
| Information | The range is between 0 and 5, where 0 means no debugging and 5 is the highest level of debugging,
i.e. all debug-messages should be send. |
| Field homeColor:String = "cecece" |
| Description | The robot home color. |
| Field name:String = "maxbot" |
| Description | The robot name. |
| Field robotCannonMaxRotate:Double |
| Description | Maximum cannon rotate speed. |
| Information | Note that the cannon and the radar move relative to the robot, so the actual rotation speed may be higher. |
| Field robotEnergyLevels:Double |
| Description | The robot will only know its energy approximately. |
| Information | This will decide how many discretation levels will be used. |
| Field robotMaxAcceleration:Double |
| Description | Robots are not allowed to accelerate faster than this. |
| Field robotMaxEnergy:Double |
| Description | By eating a cookie, the robot can increase its energy. Not more than this, though. |
| Field robotMaxRotate:Double |
| Description | How fast the robot itself may rotate. Unit: degrees/s. |
| Field robotMinAcceleration:Double |
| Description | Robots are not allowed to accelerate slower than this. |
| Field robotRadarMaxRotate:Double |
| Description | Maximum radar rotate speed. |
| Information | Note that the cannon and the radar move relative to the robot, so the actual rotation speed may be higher. |
| Field robotStartEnergy:Double |
| Description | The amount of energy the robots will have at the beginning of each game. |
| Field sendRobotCoordinates:Int |
| Description | Determines how coordinates are send to the robots. |
| Information | The following options are available:
- 0 - don't send any coordinates (default)
- 1 - send the coordinates relative the starting position
- 2 - send absolute coordinates
|
| Field shotEnergyIncreaseSpeed:Double |
| Description | Determines how fast the robots shot energy noted above, will increase. |
| Information | Unit: energy/s. |
| Field shotMaxEnergy:Double |
| Description | The robots have a shot energy, which increases with time, but will never exceed this value. |
| Field shotMinEnergy:Double |
| Description | The lowest shot energy allowed. |
| Information | A robot trying to shoot with less energy will fail to shoot. |
| Field shotSpeed:Double |
| Description | Shots are moving with this speed in the direction of the cannon plus the velocity of the robot. |
| Field timeout:Double |
| Description | This is the longest time a game will take. |
| Information | When the time is up all remaining robots are killed, without getting any more points. |
| Method Accelerate(value:Double) |
| Description | Set the robot acceleration. |
| Information | Value is bounded by Robot max/min acceleration. |
| Method ActionCollision(objectType:Int, relativeAngle:Double) |
| Description | When a robot hits (or is hit by) something it gets this message. |
| Information | You get the angle from where the collision occurred (the angle relative the robot) and the type of object
hitting you, but not how severe the collision was. This can, however, be determined indirectly
(approximately) by the loss of energy.
Possible object types are :
| OBJ_ROBOT |
| OBJ_SHOT |
| OBJ_WALL |
| OBJ_COOKIE |
| OBJ_MINE |
|
| Method ActionCoordinates(x:Double, y:Double, angle:Double) |
| Description | Tells you the current robot position. |
| Information | It is only sent if the option Send robot coordinates is 1 or 2. If it is 1 the coordinates
are sent relative the starting position, which has the effect that the robot doesn't know where it is
starting, but only where it has moved since.
The angle is in degrees. |
| Method ActionDead() |
| Description | Robot died. |
| Information | Do not try to send more messages to the server until the end of the game, the server doesn't read them. |
| Method ActionEnergy(energyLevel:Double) |
| Description | The end of each round the robot will get to know its energy level. |
| Information | It will not, however, get the exact energy, instead it is discretized into a number of energy levels. |
| Method ActionExitRobot() |
| Description | Exit from the program immediately, otherwise it will be killed forcefully. |
| Method ActionFinished() |
| Description | Current game is finished, get prepared for the next! |
| Method ActionGameOption(option:Int, value:Double) |
| Description | At the beginning of each game the robots will be sent a number of settings, which can be useful for the robot. |
| Information | Note : These options are automatically stored for you in like-named fields, but the message is also
made available to you in case you wish to be notified about it.
| Option | Meaning |
| GOPT_ROBOT_MAX_ROTATE | How fast the robot itself may rotate. Unit: degrees/s. See robotMaxRotate. |
| GOPT_ROBOT_CANNON_MAX_ROTATE | Maximum cannon rotate speed. Note that the cannon and the
radar move relative to the robot, so the actual rotation speed may be higher. See robotCannonMaxRotate. |
| GOPT_ROBOT_RADAR_MAX_ROTATE | Maximum radar rotate speed. See note above. See robotRadarMaxRotate. |
| GOPT_ROBOT_MAX_ACCELERATION | Robots are not allowed to accelerate faster than this. See robotMaxAcceleration. |
| GOPT_ROBOT_MIN_ACCELERATION | Robots are not allowed to accelerate slower than this. See robotMinAcceleration. |
| GOPT_ROBOT_START_ENERGY | The amount of energy the robots will have at the beginning of
each game. See robotStartEnergy. |
| GOPT_ROBOT_MAX_ENERGY | By eating a cookie, the robot can increase its energy. Not more
than this, though. See robotMaxEnergy . |
| GOPT_ROBOT_ENERGY_LEVELS | The robot will only know its energy approximately. This will decide how many
discretation levels will be used. See robotEnergyLevels. |
| GOPT_SHOT_SPEED | Shots are moving with this speed in the direction of the cannon plus the
velocity of the robot. See shotSpeed. |
| GOPT_SHOT_MIN_ENERGY | The lowest shot energy allowed. A robot trying to shoot with less energy
will fail to shoot. See shotMinEnergy. |
| GOPT_SHOT_MAX_ENERGY | The robots have a shot energy, which increases with time, but will
never exceed this value. See shotMaxEnergy. |
| GOPT_SHOT_ENERGY_INCREASE_SPEED | Determines how fast the robots shot energy noted above,
will increase. Unit: energy/s. See shotEnergyIncreaseSpeed. |
| GOPT_TIMEOUT | This is the longest time a game will take. When the time is up all remaining
robots are killed, without getting any more points. See timeout. |
| GOPT_DEBUG_LEVEL | The debug level is a way of telling robots which messages they should send.
The range is between 0 and 5, where 0 means no debugging and 5 is the highest level of debugging,
i.e. all debug-messages should be send. See debugLevel. |
| GOPT_SEND_ROBOT_COORDINATES | Determines how coordinates are send to the robots.
The following options are available:
- 0 - don't send any coordinates (default)
- 1 - send the coordinates relative the starting position
- 2 - send absolute coordinates
See sendRobotCoordinates.
|
|
| Method ActionGameStarts() |
| Description | This message is sent when the game starts (surprise!). |
| Method ActionInfo(time:Double, speed:Double, cannonAngle:Double) |
| Description | The ActionInfo message does always follow the ACtionRadar message. |
| Information | It gives more general information on the state of the robot. The time is the game-time elapsed
since the start of the game. This is not necessarily the same as the real time elapsed, due to time scale
and max timestep. |
| Method ActionRadar(distance:Double, observedObject:Int, radarAngle:Double) |
| Description | This message gives information from the radar each turn. |
| Information | Remember that the radar-angle is relative to the robot front. It is given in degrees. |
| Method ActionRobotInfo(energyLevel:Double, teammate:Int) |
| Description | If you detect a robot with your radar, this message will follow, giving some information on the robot. |
| Information | The opponents energy level will be given in the same manner as your own energy (see ActionEnergy).
The second argument is only interesting in team-mode, 1 means a teammate and 0 an enemy. |
| Method ActionRobotsLeft(numberOfRobots:Int) |
| Description | At the beginning of the game and when a robot is killed the number of remaining robots is broadcasted to all living robots. |
| Method ActionRotationReached(what:Int) |
| Description | When the robot option ROPT_SEND_ROTATION_REACHED is set appropriately (see RobotOption), this message is sent when a rotation (with RotateTo or RotateAmount) has finished or the direction has changed (when Sweep ing). |
| Information | The argument corresponds to 'what to rotate' in e.g. Rotate, and can be a combination of
| ROT_ROBOT |
| ROT_CANNON |
| ROT_RADAR |
|
| Method ActionWarning(warningType:Int, message:String) |
| Description | A warning message can be sent when robot has to be notified on different problems which have occured. |
| Information | Currently seven different warning messages can be sent, namely :
| Constant | Meaning |
| WARN_UNKNOWN_MESSAGE | The server received a message it couldn't recognize. |
| WARN_PROCESS_TIME_LOW | The CPU usage has reached the CPU warning percentage. Only in competition-mode. |
| WARN_MESSAGE_SENT_IN_ILLEGAL_STATE | The message received couldn't be handled in this state of the program. For example if Rotate is sent before the game has started. |
| WARN_UNKNOWN_OPTION | The robot sent a robot option with either illegal option name or illegal argument to that option. |
| WARN_OBSOLETE_KEYWORD | The keyword sent is obsolete and should not be used any more, see the ChangeLog file for information on what to use instead. |
| WARN_NAME_NOT_GIVEN | The robot has not sent its name before the game begins. This happens if the robot startup time is too long or the robot does not send its name early enough. |
| WARN_COLOUR_NOT_GIVEN | The robot has not sent its colour before the game begins. |
|
| Method ActionYourColour(robotColour:String) |
| Description | Current colour of the robot. |
| Information | Change it if you find it ugly. All robots in a team will have the same colour. |
| Method ActionYourName(robotName:String) |
| Description | Current name of the robot. |
| Information | Don't change it if you don't have very good reasons. |
| Method Brake(portion:Double) |
| Description | Set the brake. |
| Information | Full brake (portion = 1.0) means that the friction in the robot direction is
equal to Slide friction. |
| Method Debug(message:String) |
| Description | Print message on the message window if in debug-mode. |
| Method DebugCircle(centerAngle:Double, centerRadius:Double, circleRadius:Double) |
| Description | Similar to DebugLine, but draws a circle. |
| Information | The first two arguments are the angle and radius of the central point of the
circle relative to the robot. The third argument gives the radius of the circle. |
| Method DebugLine(angle1:Double, radius1:Double, angle2:Double, radius2:Double) |
| Description | Draw a line direct to the arena. |
| Information | This is only allowed in the highest debug level(5), otherwise a warning message is
sent. The arguments are the start and end point of the line given in polar coordinates
relative to the robot. |
| Method InitializeRobot() |
| Description | Perform any initializations for the robot. |
| Information | For example, you may wish to specify name, homeColor and awayColor here.
This is automatically called by Run. |
| Method Print(message:String) |
| Description | Print message on the message window. |
| Method RobotOption(option:Int, value:Int) |
| Information |
- ROPT_SEND_ROTATION_REACHED : If you want the server to send a RotationReached (see ActionRotationReached) message when a rotation
is finished, you should set this option.
With a value of 1, the message is sent when a RotateTo or a RotateAmount is finished.
With a value of 2, changes in Sweep direction are also notified.
Default is 0, i.e. no messages are sent.
|
| Method Rotate(what:Int, angularVelocity:Double) |
| Description | Set the angular velocity for the robot, its cannon and/or its radar. |
| Information | Set 'what to rotate' using ROT_ROBOT, ROT_CANNON or ROT_RADAR, or to a sum of these
to rotate more objects at the same time.
The angular velocity is given in degrees per second and is limited by Robot (cannon/radar)
max rotate speed |
| Method RotateAmount(what:Int, angularVelocity:Double, angle:Double) |
| Description | As Rotate, but will rotate relative to the current angle. |
| Method RotateTo(what:Int, angularVelocity:Double, endAngle:Double) |
| Description | As Rotate, but will rotate to a given angle. |
| Information | Note that radar and cannon angles are relative to the robot angle. You cannot use this
command to rotate the robot itself, use RotateAmount instead! |
| Method Run() Final |
| Description | Initialize and run the robot. |
| Method Shoot(shotEnergy:Double) |
| Description | Shoot with the given energy. |
| Information | The shot options give more information. |
| Method Sweep(what:Int, angularVelocity:Double, rightAngle:Double, leftAngle:Double) |
| Description | As Rotate, but sets the radar and/or the cannon (not available for the robot itself) in a sweep mode. |
Module Information
| Version | 1.00 |
| License | Free. |
| Author | Bruce A Henderson |
| Modserver | BRL |
| History | 1.00 |
| History | Initial Release. |