Table of contents Index

class RTBRobotSkel - RTBRobotSkel

Declared in module pyrtb

Synopsis

class RTBRobotSkel:
    def __init__(self, name='RTB Zippy Bot', color='f00ba7', use_signal=0) # Instance initialization.
    def __repr__(self) # Returns a representation of object.
    def accelerate(self, amount) # Sets acceleration of robot.
    def brake(self, portion) # Set the brake.
    def check_messages(self) # Get and handle server messages from the stdin stream.
    def collision(self, colliding_obj_type, angle_relative_robot) # Handle of server notification of object collision.
    def dead(self) # Funeral announce.
    def debug(self, message) # Print message on the message window if in debug mode
    def debug_circle(self, center_angle, center_radius, circle_radius) # Draw a circle directly to arena.
    def debug_line(self, start_angle, start_radius, end_angle, end_radius) # Draw a line directly to arena.
    def display(self, message) # Print message on the message window of server
    def energy(self, level) # Callback updating object energy level.
    def exit(self, message='Received "ExitRobot"') # Exit Robot.
    def game_finishes(self) # Callback called when a match is finished.
    def game_starts(self) # Callback called when server declares game has begun.
    def info(self, time, speed, cannon_angle) # Callback called when an 'Info' message is received.
    def initialize(self, first_seq) # Returns Name/Color to server.
    def install_signals(self) # Setup of signal handlers.
    def log(self, message) # Logs a message in file (or stderr by default).
    def make_empty_options_dicts(self) # 'Useless' internal init function.
    def radar(self, distance, obs_obj_type, angle) # Callback called when a 'Radar' update message is received.
    def robot_info(self, energy_level, team_mate) # Updates enemy informations, if radar found one.
    def robots_left(self, left) # Callback updating internal 'robots_left' count.
    def rotate(self, what, vel) # Rotates a part of the robot with a given angular velocity.
    def rotate_amount(self, what, vel, angle) # As rotate (), but will rotate relaative to the current angle.
    def rotate_to(self, what, vel, angle) # As rotate (), but will rotate to a given angle.
    def rotation_reached(self, what_has_reached) # Method called when the server sent a 'RotationReached' message.
    def send_robot_options(self) # Sends the server our options.
    def set_color(self, color) # Sets instance's color.
    def set_game_option(self, optionnr, value) # Updates instance's game options with server values.
    def set_name(self, name) # Updates instance's bot name.
    def shoot(self, energy) # Shoot with the given energy.
    def sig_recv(self, sig, stack_frame)
    def start(self) # The method you should call when instances are ready to operate.
    def sweep(self, ang_vel, left_angle, right_angle) # As rotate (), but sets radar and/or canon to a sweep mode.
    def warning(self, warning_type, message='<no_message>') # Server Warning callback.

file log_fd = <open fi... 804ac88>
string type = 'RTB Zippy Bot'
int verbose = 0

Description

This class implements basic behavior for Real Time Battle robots in Python, thus allowing, by subclassing it, to develop new robots easily and quickly. Normally, you'll just have to code a few functions to make the beast work flawlessly.

Variables

Behavior of instances

messages_in
Dictionnary associating each command sent by server to a function, setup to class default methods by __init__ () when instanciating ('__init__' is the constructor in Python...) NOTE: keys should be in lowercase to be matched with server' commands.
verbose
If true (not 0), extraneous output message is logged, including the majority of messages received (with Radar and Info message, this can make BIG files...

Robot settings

robots_left
Number of concurrents left to kill. Kill'em! ALL!
energy
Our own energy. In competition mode, it is given through _levels_, with the maximum set in the robot_max_energy key of the game_options dictionary. This is not implemented yet!
game_options
Dictionnary containing options set by the server when the game starts. Known keys are in the GameOptions list.
robot_options
It defines the way the robot communicates with server, using keys defined in the RobotOptions list. We use a blocking, SIGUSR1 signal based behavior (see RealTimeBattle documentation).
log_fd
File descriptor used to log messages. Defaults to stderr.

Miscellaneous

use_signal
If false (0 or None), don't use signal handling to receive message (i.e. we listen at stdin). Else (if signal.{SIGUSR1,SIGUSR2}, use this signal. **It seems there is still some problems with signal handling...**

__init__(self, name='RTB Zippy Bot', color='f00ba7', use_signal=0)

Instance initialization.

Here we setup some stuff, such as the dictionaries we make and the signal handlers we install. We also bind messages_in callbacks dictionnary to our methods.

__repr__(self)

Returns a representation of object.

The __repr__ metaclass attribute returns a string representing the object instance. Almost not used...

accelerate(self, amount)

Sets acceleration of robot.

Accelerates the robot with the given amount (a floating number). The value is bounded by the instance's game_options robot_min/max_acceleration values.

brake(self, portion)

Set the brake.

Full brake (portion = 1.0) means that the friction in the robot direction is equal to Slide friction.

check_messages(self)

Get and handle server messages from the stdin stream.

Commands are parsed from stdin and, if possible, call corresponding commands, following values of messages_in.

collision(self, colliding_obj_type, angle_relative_robot)

Handle of server notification of object collision.

This is the method called when the server issues a Collision message. Arguments provide more informations. For object types, see the constants in the basic module.

dead(self)

Funeral announce.

This sadly notifies us of our death. Not yet implemented!

debug_circle(self, center_angle, center_radius, circle_radius)

Draw a circle directly to arena.

This is similar to debug_line but draws a circle. The first two arguments ('self' excluded, of course) are the angle and radius of the central point of the circle relative to the robot. The last argument gives the radius of the circle.

debug_line(self, start_angle, start_radius, end_angle, end_radius)

Draw a line directly to arena.

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.

energy(self, level)

Callback updating object energy level.

This updates the energy level of an object, given the context when it's received, it could be ours. Not implemented yet

exit(self, message='Received "ExitRobot"')

Exit Robot.

Exits the robot, generally because the server sent an ExitRobot message. The whole process is exited (call of 'sys.exit ()')

game_finishes(self)

Callback called when a match is finished.

It is called when server sends a GameFinishes message. At this time, we do nothing.

game_starts(self)

Callback called when server declares game has begun.

It's up to you to do what you want with it...

info(self, time, speed, cannon_angle)

Callback called when an 'Info' message is received.

The Info message does always follow the Radar message. It gives more general informations on the state of the robot. Within this method, we simply update informations with the one they gave us. Does nothing yet!

initialize(self, first_seq)

Returns Name/Color to server.

This is the method which is called when an Initialize message is received with its sequence equal to 1 (meaning this is the first time we play).

install_signals(self)

Setup of signal handlers.

Robot Options are set to blocking, SIGUSR1 signal-based server communication scheme. The signal handler is set to point to the sig_recv () method.

log(self, message)

Logs a message in file (or stderr by default).

This writes the given message in the stream referenced by our log_fd attribute, which defaults to the stderr output stream.

make_empty_options_dicts(self)

'Useless' internal init function.

Creates instance's game_options and robot_options, assigning None to each key.

radar(self, distance, obs_obj_type, angle)

Callback called when a 'Radar' update message is received.

This method updates information from the radar each turn. Remember that the radar-angle is relative to the robot front, it is given in radians. Does nothing yet!

robot_info(self, energy_level, team_mate)

Updates enemy informations, if radar found one.

If you detect a robot with your radar, this message will follow, giving some information on the robot. The opponents energy level will be given in the same manner as your own energy. The second argument is only interesting in team-mode (which current isn't implemented), 1 means a teammate and 0 an enemy. Does nothing yet!

robots_left(self, left)

Callback updating internal 'robots_left' count.

This handles the RobotsLeft message sent by server when it notifies a robot is dead (other circumstances?)

rotate(self, what, vel)

Rotates a part of the robot with a given angular velocity.

Set the angular velocity for the robot, its cannon and/or its radar (represented by [ROTATE constants], which can be added to rotate more objects at the same time. The angular velocity is given in radians per second and is limited by the GameOptions list.

rotate_amount(self, what, vel, angle)

As rotate (), but will rotate relaative to the current angle.

Anything more to say ?

rotate_to(self, what, vel, angle)

As rotate (), but will rotate to a given angle.

Note that radar and cannon angles are relative to robot angle. You cannot use this command to rotate the robot itself, use rotate_amount () instead!

rotation_reached(self, what_has_reached)

Method called when the server sent a 'RotationReached' message.

RotationReached feature allows us to receive a message each time one of our rotations has finish (the what_has_reached argument is one of ROTATE_ROBOT, ROTATE_CANNON or ROTATE_RADAR constant found in the basic module.

send_robot_options(self)

Sends the server our options.

With this method we send the server contents of our robot_options dictionnary (only keys that have non-'None' values). This function is usually used at configuration time, before running RTBRobotSkel.start ().

set_color(self, color)

Sets instance's color.

Updates class instance's color attribute. This callback is generally called when YourColour is received from the RTB server.

set_game_option(self, optionnr, value)

Updates instance's game options with server values.

This updates the game_options dictionnary of the class' instance with values given by server. See GameOptions list in this module.

set_name(self, name)

Updates instance's bot name.

Sets instance name attribute to the given name. It is generally called by the server when it issues a YourName message.

shoot(self, energy)

Shoot with the given energy.

Shoot has to fit the game_options shot options (**shot_speed**, shot_min_energy, shot_max_energy, **shot_energy_increase_speed**).

sig_recv(self, sig, stack_frame)

None

Signal handler, called when a signal (default SIGUSR1) is caught (i.e. a message sent by the RTB server is waiting in stdin).Actions taken are to check messages (through check_messages (), duh) and to re-set signal handler to capture next signal coming.

start(self)

The method you should call when instances are ready to operate.

Starts listening for server's SIGUSR1 signals (if use_signal is set), in order to handle soon-to-come coming messages from server. This loop is an endless loop (while an ExitRobot message is received, or the process killed).

sweep(self, ang_vel, left_angle, right_angle)

As rotate (), but sets radar and/or canon to a sweep mode.

Note: this is not available for the robot itself.

warning(self, warning_type, message='<no_message>')

Server Warning callback.

This method is called whenever the server sends us a Warning message. The behavior here is to log this, but no more. This has to be fixed I think, and I'll do it ASAP...
Valid HTML 4.0! Made with CSS