cz.cuni.pogamut.Client
Class BaseBot

java.lang.Object
  extended by cz.cuni.pogamut.Client.Agent
      extended by cz.cuni.pogamut.Client.BaseBot
All Implemented Interfaces:
RcvMsgListener, Introspectable, java.lang.Runnable, java.util.EventListener

public class BaseBot
extends Agent

This class is meant as an example for the user of Pogamut2 - it overrides the crucial methods and explains them (see the respective methods).

You may inherit this class (but that's no need to) or class cz.cuni.pogamut.Client.Agent (which is recommanded).

We recommand you to read the documentation of methods overriden by this class and then check out the Agent class.

This is commented template class - do not add any code here! If you wish to test stuff - change class TestBot or create your own.

========================================================================

Q: How it all works?
--------------------

The bot consists of two threads - Logic thread and Communication thread.

Communication thread is meant to communicate with Parser (which can be LOCAL - part of the agent or REMOTE - run as an independent application usualy at computer where UT2004 server is running).

Parser is parsing text messages from GameBots and translates them into java objects which are sent to communication thread. The communication thread is responsible for maintaining information about the world around the bot. For that - see cz.cuni.Client.GameMap / History / HistoryBatch / Agent, etc.

Before logic thread is started you must be sure, that you've bind a parser to the bot (well NetBeans plugin does that for you :-). Check out methods cz.cuni.Client.Agent-connectToLocalParser() / connectToRemoteParser().

When logic thread is started it does a few things:

  1. calls this.prePrepareAgent() - method which is meant for you, you can use it to initialize variables before the bot connects to GameBot (via parser)
  2. starts the communication thread - if that fails, the thread is destroyed (and you get SEVERE error in log)
  3. calls this.postPrepareAgent() - method in which you can prepare more properties for your bot (note that by that time the GameBots sends you all the navpoint and items which are available somewhere in the map as well as information about the game (like type, mapname, etc.)
  4. goes to the while cycle, which is repeatedly calling doLogic() while running() returns true
  5. when running() returns false, the while cycle is left and this.shutdownAgent() is called - it's place where you can save / print anything you want

Now you should have good picture about which method you need to override and what to place into them - checkout documentation inside those methods for more informations.

Check out the method main() code for tips on how to run the bot from your code.

Q: That's fine but I don't know how to work with the class at all!
------------------------------------------------------------------

You're right - we haven't explain where sensors and efetors of the agent are. And we won't do this here. Just check out Agent.memory (AgentMemory) and Agent.body (AgentBody). Those are class where you find sensors (AgentMemory, stuff like seeAnyEnemy(), etc.) and effectors (AgentBody, stuff like jump(), runTo(), etc.)


Field Summary
protected  java.lang.String botName
          Name of the bot.
 
Fields inherited from class cz.cuni.pogamut.Client.Agent
bindedParserType, body, flagLogicTemporalyStopped, gameBotConnection, gameMap, GARBAGE_COLLECTOR_FREQUENCY, instancesAlive, iterationEndListeners, log, logicFrequency, logicFrequencyChanged, memory, oldLogicFrequency, parserLogger, pauseHolders, platformLog, random, rawGBLog
 
Constructor Summary
BaseBot()
          Constructor of the bot - here is place where you should initialize any variables you need to.
 
Method Summary
protected  void doLogic()
          doLogic() is repeatedly called by Agent while running() returns true.
 java.lang.String getBotName()
          Returns bot name.
static void main(java.lang.String[] Args)
          This main() method is for 'learn by example' - it contains everything what is needed to run the agent - check to code.
protected  void postPrepareAgent()
          Prepares logic according to information gathered from cz.cuni.pogamut.Client.Agent.startCommunication().
protected  void prePrepareAgent()
          Prepares agent logic to run - whings like initializing neural networks etc.
 void setBotName(java.lang.String newBotName)
          Sets new name of the bot.
protected  void shutdownAgent()
          This method is last to be called before disposing of the agent.
 
Methods inherited from class cz.cuni.pogamut.Client.Agent
addIterationEndListener, bindLocalParser, bindRemoteParser, clearListeners, disconnect, finalize, getBindedParserType, getBody, getCommunicationState, getFlagLogicTemporalyStopped, getIntrospectableProxy, getLogger, getLogicThread, getMap, getMediator, getMemory, getMilisecToSleep, getName, getPlatformLog, getRawDataLog, initBody, initGameMap, initLogging, initMemory, isRunning, logicReady, pauseLogic, receiveMessage, removeIterationEndListener, resumeLogic, run, sendMessageToGB, setFlagLogicTemporalyStopped, setLogicStartLatch, startAgent, startAgent, stopAgentSoft
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

botName

protected java.lang.String botName
Name of the bot.

Constructor Detail

BaseBot

public BaseBot()
Constructor of the bot - here is place where you should initialize any variables you need to.

Method Detail

doLogic

protected void doLogic()
doLogic() is repeatedly called by Agent while running() returns true. This is a main place for you to add the code which will control your bot.

Overrides:
doLogic in class Agent

prePrepareAgent

protected void prePrepareAgent()
Prepares agent logic to run - whings like initializing neural networks etc.
It's called before Connecting the parser and GameBot.
It's not meant for establishing communication with Parser and/or GameBots, those things are already handled for you in cz.cuni.pogamut.Client.Agent.run()

Overrides:
prePrepareAgent in class Agent

postPrepareAgent

protected void postPrepareAgent()
Prepares logic according to information gathered from cz.cuni.pogamut.Client.Agent.startCommunication(). like choosing plan/parameters according to game type etc.

Overrides:
postPrepareAgent in class Agent

shutdownAgent

protected void shutdownAgent()
This method is last to be called before disposing of the agent. You should save your work here (like neural networks params, etc.)

Overrides:
shutdownAgent in class Agent

main

public static void main(java.lang.String[] Args)
This main() method is for 'learn by example' - it contains everything what is needed to run the agent - check to code.


getBotName

public java.lang.String getBotName()
Returns bot name.

Returns:
bot name

setBotName

public void setBotName(java.lang.String newBotName)
Sets new name of the bot.

Parameters:
newBotName - new name of the bot