BaH.RealTimeBattle: Types Modinfo Source  

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:

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 :

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
DescriptionThe RealtimeBattle Robot base type.
Field awayColor:String = "ff6666"
DescriptionThe robot away color.
Field color:String
DescriptionThe actual robot color.
InformationThis.
Field debugLevel:Int
DescriptionThe debug level is a way of telling robots which messages they should send.
InformationThe 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"
DescriptionThe robot home color.
Field name:String = "maxbot"
DescriptionThe robot name.
Field robotCannonMaxRotate:Double
DescriptionMaximum cannon rotate speed.
InformationNote that the cannon and the radar move relative to the robot, so the actual rotation speed may be higher.
Field robotEnergyLevels:Double
DescriptionThe robot will only know its energy approximately.
InformationThis will decide how many discretation levels will be used.
Field robotMaxAcceleration:Double
DescriptionRobots are not allowed to accelerate faster than this.
Field robotMaxEnergy:Double
DescriptionBy eating a cookie, the robot can increase its energy. Not more than this, though.
Field robotMaxRotate:Double
DescriptionHow fast the robot itself may rotate. Unit: degrees/s.
Field robotMinAcceleration:Double
DescriptionRobots are not allowed to accelerate slower than this.
Field robotRadarMaxRotate:Double
DescriptionMaximum radar rotate speed.
InformationNote that the cannon and the radar move relative to the robot, so the actual rotation speed may be higher.
Field robotStartEnergy:Double
DescriptionThe amount of energy the robots will have at the beginning of each game.
Field sendRobotCoordinates:Int
DescriptionDetermines how coordinates are send to the robots.
InformationThe 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
DescriptionDetermines how fast the robots shot energy noted above, will increase.
InformationUnit: energy/s.
Field shotMaxEnergy:Double
DescriptionThe robots have a shot energy, which increases with time, but will never exceed this value.
Field shotMinEnergy:Double
DescriptionThe lowest shot energy allowed.
InformationA robot trying to shoot with less energy will fail to shoot.
Field shotSpeed:Double
DescriptionShots are moving with this speed in the direction of the cannon plus the velocity of the robot.
Field timeout:Double
DescriptionThis is the longest time a game will take.
InformationWhen the time is up all remaining robots are killed, without getting any more points.
Method Accelerate(value:Double)
DescriptionSet the robot acceleration.
InformationValue is bounded by Robot max/min acceleration.
Method ActionCollision(objectType:Int, relativeAngle:Double)
DescriptionWhen a robot hits (or is hit by) something it gets this message.
InformationYou 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)
DescriptionTells you the current robot position.
InformationIt 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()
DescriptionRobot died.
InformationDo 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)
DescriptionThe end of each round the robot will get to know its energy level.
InformationIt will not, however, get the exact energy, instead it is discretized into a number of energy levels.
Method ActionExitRobot()
DescriptionExit from the program immediately, otherwise it will be killed forcefully.
Method ActionFinished()
DescriptionCurrent game is finished, get prepared for the next!
Method ActionGameOption(option:Int, value:Double)
DescriptionAt the beginning of each game the robots will be sent a number of settings, which can be useful for the robot.
InformationNote : 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.

OptionMeaning
GOPT_ROBOT_MAX_ROTATEHow fast the robot itself may rotate. Unit: degrees/s. See robotMaxRotate.
GOPT_ROBOT_CANNON_MAX_ROTATEMaximum 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_ROTATEMaximum radar rotate speed. See note above. See robotRadarMaxRotate.
GOPT_ROBOT_MAX_ACCELERATIONRobots are not allowed to accelerate faster than this. See robotMaxAcceleration.
GOPT_ROBOT_MIN_ACCELERATIONRobots are not allowed to accelerate slower than this. See robotMinAcceleration.
GOPT_ROBOT_START_ENERGYThe amount of energy the robots will have at the beginning of each game. See robotStartEnergy.
GOPT_ROBOT_MAX_ENERGYBy eating a cookie, the robot can increase its energy. Not more than this, though. See robotMaxEnergy .
GOPT_ROBOT_ENERGY_LEVELSThe robot will only know its energy approximately. This will decide how many discretation levels will be used. See robotEnergyLevels.
GOPT_SHOT_SPEEDShots are moving with this speed in the direction of the cannon plus the velocity of the robot. See shotSpeed.
GOPT_SHOT_MIN_ENERGYThe lowest shot energy allowed. A robot trying to shoot with less energy will fail to shoot. See shotMinEnergy.
GOPT_SHOT_MAX_ENERGYThe robots have a shot energy, which increases with time, but will never exceed this value. See shotMaxEnergy.
GOPT_SHOT_ENERGY_INCREASE_SPEEDDetermines how fast the robots shot energy noted above, will increase. Unit: energy/s. See shotEnergyIncreaseSpeed.
GOPT_TIMEOUTThis 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_LEVELThe 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_COORDINATESDetermines 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()
DescriptionThis message is sent when the game starts (surprise!).
Method ActionInfo(time:Double, speed:Double, cannonAngle:Double)
DescriptionThe ActionInfo message does always follow the ACtionRadar message.
InformationIt 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)
DescriptionThis message gives information from the radar each turn.
InformationRemember that the radar-angle is relative to the robot front. It is given in degrees.
Method ActionRobotInfo(energyLevel:Double, teammate:Int)
DescriptionIf you detect a robot with your radar, this message will follow, giving some information on the robot.
InformationThe 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)
DescriptionAt 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)
DescriptionWhen 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).
InformationThe 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)
DescriptionA warning message can be sent when robot has to be notified on different problems which have occured.
InformationCurrently seven different warning messages can be sent, namely :
ConstantMeaning
WARN_UNKNOWN_MESSAGEThe server received a message it couldn't recognize.
WARN_PROCESS_TIME_LOWThe CPU usage has reached the CPU warning percentage. Only in competition-mode.
WARN_MESSAGE_SENT_IN_ILLEGAL_STATEThe 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_OPTIONThe robot sent a robot option with either illegal option name or illegal argument to that option.
WARN_OBSOLETE_KEYWORDThe 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_GIVENThe 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_GIVENThe robot has not sent its colour before the game begins.
Method ActionYourColour(robotColour:String)
DescriptionCurrent colour of the robot.
InformationChange it if you find it ugly. All robots in a team will have the same colour.
Method ActionYourName(robotName:String)
DescriptionCurrent name of the robot.
InformationDon't change it if you don't have very good reasons.
Method Brake(portion:Double)
DescriptionSet the brake.
InformationFull brake (portion = 1.0) means that the friction in the robot direction is equal to Slide friction.
Method Debug(message:String)
DescriptionPrint message on the message window if in debug-mode.
Method DebugCircle(centerAngle:Double, centerRadius:Double, circleRadius:Double)
DescriptionSimilar to DebugLine, but draws a circle.
InformationThe 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)
DescriptionDraw a line direct to the arena.
InformationThis 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()
DescriptionPerform any initializations for the robot.
InformationFor example, you may wish to specify name, homeColor and awayColor here.
This is automatically called by Run.
Method Print(message:String)
DescriptionPrint 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)
DescriptionSet the angular velocity for the robot, its cannon and/or its radar.
InformationSet '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)
DescriptionAs Rotate, but will rotate relative to the current angle.
Method RotateTo(what:Int, angularVelocity:Double, endAngle:Double)
DescriptionAs Rotate, but will rotate to a given angle.
InformationNote 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
DescriptionInitialize and run the robot.
Method Shoot(shotEnergy:Double)
DescriptionShoot with the given energy.
InformationThe shot options give more information.
Method Sweep(what:Int, angularVelocity:Double, rightAngle:Double, leftAngle:Double)
DescriptionAs Rotate, but sets the radar and/or the cannon (not available for the robot itself) in a sweep mode.

Module Information

Version1.00
LicenseFree.
AuthorBruce A Henderson
ModserverBRL
History1.00
HistoryInitial Release.