edu.isi.gamebots.client
Class Bot

java.lang.Object
  |
  +--edu.isi.gamebots.client.Bot
All Implemented Interfaces:
GamebotsConstants
Direct Known Subclasses:
CMU_JBot, ExampleBot, HumanBot

public abstract class Bot
extends Object
implements GamebotsConstants

This is the base class for all Java Bots. It handles most low level functionality, including bot life cycle hooks, and many helper functions.

Author:
Andrew n marshall

Nested Class Summary
 
Nested classes inherited from class edu.isi.gamebots.client.GamebotsConstants
GamebotsConstants.TeamColorMap
 
Field Summary
protected  GamebotsClient client
           The UTServer
protected  GamebotsClient.Listener clientListener
           Handles server message events
protected  Runnable eventProcessor
           Processes events as they arrive
protected  us.ca.la.anm.util.io.DebugLog log
           A logging mechanisn
 
Fields inherited from interface edu.isi.gamebots.client.GamebotsConstants
ACTOR_CLASS, ACTOR_ID, ACTOR_REACHABLE, ARG_ALT, ARG_AMOUNT, ARG_GLOBAL, ARG_TARGET, ARG_TEXT, ARG_WALK, BEG, BUMP, CHANGEWEAPON, CHECKREACH, DAMAGE, DEATH_DAMAGE_TYPE, DEATH_KILLER, DEFAULT_BOT_PORT, DEFAULT_VIZ_PORT, DIE, DOM, DOMPOINTS, END, FALSE, FINISHED, GAMESTATE, GETPATH, INFO, INIT, INV, ITEM, ITEM_ID, JUMP, KILL, LOCATION, MESSAGE, MOV, NAV, NODE_DOMINATION, NODE_INVENTORY, NODE_MOVER, NODE_NAVIGATION, OWNER, PATH, PING, PLAYER, PLAYER_AMMO, PLAYER_ARMOR, PLAYER_HEALTH, PLAYER_NAME, PLAYER_RADIUS, PLAYER_TEAM, PLAYER_WEAPON, PONG, ROTATE, ROTATION, RUNTO, SEE, SELF, SETWALK, SHOOT, STOP, STOP_SHOOT, STRAFE, TEAM_ANY, TEAM_BLUE, TEAM_GOLD, TEAM_GREEN, TEAM_NONE, TEAM_RED, TRUE, TURNTO, VELOCITY, WALL, WEAPON_1, WEAPON_2
 
Constructor Summary
Bot()
           Creates a new Bot
 
Method Summary
 void changeWeapon(String weaponID)
           Changes to another weapon that the agent posseses.
 void checkReach(String id, double fromX, double fromY, double fromZ)
           check to see if you can move directly to a destination without hitting an obstruction, falling in a pit, etc...
 void checkReach(String id, String target)
           check to see if you can move directly to a destination without hitting an obstruction, falling in a pit, etc...
 void connect()
          This initiates a connection with the server.
protected  void connected()
           Bot implementations override this to specify what to do (if anything) after the bot established a server connection.
 void destroy()
           Event Handler.
protected  void destroyImpl()
           Event handling.
 void disconnect()
          This forces disconnect with the server.
protected  void disconnected()
           Event handling.
 GamebotsClient getClient()
           Get the server that this bot is running on.
 int getInitialTeam()
           Return the name of the team that the bot was initialized to.
 us.ca.la.anm.util.io.DebugLog getLog()
           Return the log for the bot
 String getName()
           Get the bot's name
 void getPath(String pathName, double x, double y, double z)
           The bot asks for a path to an xyz coordinate
 JComponent getView()
           Returns a user interface for the bot.
protected  void init()
           Bot implementations override this to specify what to do (if anything) when the bot is initialized.
 void init(String name, GamebotsClient client, int team, us.ca.la.anm.util.io.DebugLog log)
           Main initialization method for BotRunnerApp.
 void jump()
           The agent jumps.
static double[] parseVector(String in)
           Parses any comma or space delimited list of numbers into an array of doubles.
protected abstract  void receivedAsyncMessage(Message message)
           Bot implementations must override this method.
protected  void receivedError(Throwable error)
           Event handling.
protected abstract  void receivedSyncMessage(MessageBlock message)
           Bot implementations must override this method.
 void rotate(double amount)
           Rotate the agent by a particular amount.
 void runTo(double x, double y, double z)
           The bot runs to a perticular location
 void runTo(String target)
           The bot runs to a perticular target.
 void say(String message, boolean forEveryone)
           Say something that is heard by other players.
protected  void setName(String newName)
           Sets the bot's name.
 void setWalk(boolean doWalk)
           Set the agent to walk instead of run.
 void shoot()
           Agent shoots their current weapon (if they have one).
 void shoot(double x, double y, double z, String targetID, boolean altFire)
           Shoot at a particular target.
 void shoot(String targetID, boolean altFire)
           Shoot at a particular target.
 void stop()
           Stop moving.
 void stopShoot()
           If currently shooting its weapon, the bot will stop.
 void strafe(double x, double y, double z, String faceObjectID)
           Strafe.
 void turnTo(double pitch, double yaw, double roll)
           Turn a particular amount in three dimentional space.
 void turnToLoc(double x, double y, double z)
           Turn towards a particular location in space
 void turnToLoc(String coords)
           Turn towards a particular location in space
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

client

protected GamebotsClient client

The UTServer


log

protected us.ca.la.anm.util.io.DebugLog log

A logging mechanisn


clientListener

protected GamebotsClient.Listener clientListener

Handles server message events


eventProcessor

protected Runnable eventProcessor

Processes events as they arrive

Constructor Detail

Bot

public Bot()

Creates a new Bot

Method Detail

parseVector

public static double[] parseVector(String in)
                            throws NumberFormatException

Parses any comma or space delimited list of numbers into an array of doubles. Particularly useful for parsing location and rotation information.

Parameters:
in - The String object to parse
Returns:
an array of doubles
Throws:
NumberFormatException - If there is a non-number in the list

init

public final void init(String name,
                       GamebotsClient client,
                       int team,
                       us.ca.la.anm.util.io.DebugLog log)

Main initialization method for BotRunnerApp. All Bot specific initialization should occur in init(java.lang.String, edu.isi.gamebots.client.GamebotsClient, int, us.ca.la.anm.util.io.DebugLog).

Parameters:
name - Name of the bot
client - UTServer that bot talks to
team - Team that the bot is on
log - Where to log debug messages to (can specify System.out to log to the console)

getName

public final String getName()

Get the bot's name

Returns:
the Bot name.

getClient

public final GamebotsClient getClient()

Get the server that this bot is running on.

Returns:
the bot's GamebotsClient.

getInitialTeam

public final int getInitialTeam()

Return the name of the team that the bot was initialized to.

Returns:
int team that the bot belongs to

getView

public JComponent getView()

Returns a user interface for the bot. This is needed if you want to use the BotRunnerApp to start and view the status of your bots. The JComponent that this returns is what gets added to a new tab in the interface.

Returns:
a Swing user interface for the bot.

connect

public final void connect()
This initiates a connection with the server. It is called from the BotRunnerApp.


disconnect

public final void disconnect()
This forces disconnect with the server. It is called from the BotRunnerApp.


destroy

public final void destroy()

Event Handler. Override this method to define what to do when the bot is distroyed/disconnected by the user.


runTo

public void runTo(String target)

The bot runs to a perticular target.

Parameters:
target - The UnrealTournament ID to run to

getPath

public void getPath(String pathName,
                    double x,
                    double y,
                    double z)

The bot asks for a path to an xyz coordinate


runTo

public void runTo(double x,
                  double y,
                  double z)

The bot runs to a perticular location

Parameters:
x - global x coordinate in the world
y - global y coordinate in the world
z - global z coordinate in the world

getLog

public us.ca.la.anm.util.io.DebugLog getLog()

Return the log for the bot

Returns:
The DebugLog of the agent

turnTo

public void turnTo(double pitch,
                   double yaw,
                   double roll)

Turn a particular amount in three dimentional space. Yaw is side to side, pitch up and down, and Roll the equivelent of doing a cartwheel. You probably won't need Roll, so don't sweat it. A full rotation using UT's measurements is 65535. To convert the values you are sent to radiens, divide by 65535 and multiply by 2 * pi. This is already converted for you to radians though. UnrealTournament units.

Parameters:
pitch - Amount to look up or down in radians
yaw - Amount to turn side to side in radians
roll - Amount of 'roll' rotation. Not sure what this does.

turnToLoc

public void turnToLoc(double x,
                      double y,
                      double z)

Turn towards a particular location in space

Parameters:
x - The global x coordinate to turn toward
y - The global y coordinate to turn toward
z - The global z coordinate to turn toward

turnToLoc

public void turnToLoc(String coords)

Turn towards a particular location in space

Parameters:
coords - Same as turnTo(double, double, double) except this takes the three corrdinates as a single string.

setWalk

public void setWalk(boolean doWalk)

Set the agent to walk instead of run. It seems intuitive that when true is sent, the agent should walk. But in our tests, it seems the agent is set to run when true is sent and walks when false is sent.

Parameters:
doWalk - We think that true means run and false means walk.

say

public void say(String message,
                boolean forEveryone)

Say something that is heard by other players.

Parameters:
message - The message to send
forEveryone - True if this is sent to both teams, false if only to your team

stop

public void stop()

Stop moving. If the agent is en route to a location (via the runTo) command or is otherwise moving and can stop, the agent will stop.


jump

public void jump()

The agent jumps. I think that it is a bug that the bot is able to jump again while in the middle of a jump. In a room with high celings this gives bots magical flying ability.


strafe

public void strafe(double x,
                   double y,
                   double z,
                   String faceObjectID)

Strafe. This causes the agent to run to a particular location while looking at another.

Parameters:
x - Global x coordinate run to.
y - Global y coordinate run to.
z - Global z coordinate run to.
faceObjectID - Object ID to face while running

rotate

public void rotate(double amount)

Rotate the agent by a particular amount. A full rotation using UT's measurements is 65535. To convert the values you are sent to radiens, divide by 65535 and multiply by 2 * pi.

Parameters:
amount - Amount in UT units to rotate

shoot

public void shoot()

Agent shoots their current weapon (if they have one). Sometimes the agent will fire one or two shots and sometimes they fire more.


shoot

public void shoot(double x,
                  double y,
                  double z,
                  String targetID,
                  boolean altFire)

Shoot at a particular target. The bot will auto aim. As long as the target stays within the bots visual range, the bot will keep shooting the target until it runs out of ammo. Use the {stopShoot command to stop shooting.

Parameters:
x - Global x coordinate to fire toward
y - Global y coordinate to fire toward
z - Global z coordinate to fire toward
targetID - Global UT target ID to fire at
altFire - true to use the weapon's alternate fire feature.

shoot

public void shoot(String targetID,
                  boolean altFire)

Shoot at a particular target. The bot will auto aim. As long as the target stays within the bots visual range, the bot will keep shooting the target until it runs out of ammo. Use the stopShoot command to stop shooting.

Parameters:
targetID - The UT id of the target to shoot at
altFire - true to use the weapon's alternate fire feature.

changeWeapon

public void changeWeapon(String weaponID)

Changes to another weapon that the agent posseses.

Parameters:
weaponID - The UT id of the weapon to switch to

stopShoot

public void stopShoot()

If currently shooting its weapon, the bot will stop.


setName

protected void setName(String newName)

Sets the bot's name. Currently does nothing if the Bot is already connected.

Future: request name changes to the server when connected.

Parameters:
newName - Agent name

init

protected void init()

Bot implementations override this to specify what to do (if anything) when the bot is initialized.


connected

protected void connected()

Bot implementations override this to specify what to do (if anything) after the bot established a server connection.


receivedAsyncMessage

protected abstract void receivedAsyncMessage(Message message)

Bot implementations must override this method. This specifies what to do when an asynchronous message is recieved. A description of the difference between sync and async messages can be found at http://www.planetunreal.com/gamebots/docapi.html. Although this is not nessesarily a complete reference, it is a good general intro.

Parameters:
message - The Message object to handle

receivedSyncMessage

protected abstract void receivedSyncMessage(MessageBlock message)

Bot implementations must override this method. This specifies what to do when an synchronous message is recieved. A description of the difference between sync and async messages can be found at http://www.planetunreal.com/gamebots/docapi.html. Although this is not nessesarily a complete reference, it is a good general intro.

Parameters:
message - The synchronous MessageBlock to handle

receivedError

protected final void receivedError(Throwable error)

Event handling. What to do when a bot throws an error. Default is to disconnect.

Parameters:
error - The error that was recieved to handle.

disconnected

protected void disconnected()

Event handling. Bot implementation overrides this to tell what to do when disconnected from the server.


destroyImpl

protected void destroyImpl()

Event handling. Describes what to do when the bot is destroyed.


checkReach

public void checkReach(String id,
                       String target)

check to see if you can move directly to a destination without hitting an obstruction, falling in a pit, etc...

Parameters:
id - message id made up by you and echoed in respose so you can match up response with querry
target - the unique id of a player/object/nav point/whatever. Must be visible.

checkReach

public void checkReach(String id,
                       double fromX,
                       double fromY,
                       double fromZ)

check to see if you can move directly to a destination without hitting an obstruction, falling in a pit, etc...

Parameters:
id - message id made up by you and echoed in respose so you can match up response with querry
fromX - Location you want to go to. Normal location rules.
fromY - Location you want to go to. Normal location rules.
fromZ - Location you want to go to. Normal location rules.