[Pogamut-list] Launching Multiple Bots of Different Types

jakub.gemrot pogamut-forum at diana.ms.mff.cuni.cz
Mon Nov 29 11:32:40 CET 2010


Re: Launching Multiple Bots of Different Types

Author: jakub.gemrot

Hi! Excellent!

So I'm going to explain how to work with MultipleUT2004BotRunner inside Pogamut 3.1 (I'm 

afraid you're on your own with 3.0.11 which I would suggest not to use).

To be able to talk about MultipleUT2004BotRunner I will need to explain how objects of 

UT2004Bot class are constructed and initialized and what roles objects implementing 

IUT2004BotController (namely UT2004BotModuleController which you are extending) plays.

First of all you have to notice that what we call JAVA BOT PROJECT in the NetBeans plugin 

is in fact UT2004 BOT CONTROLLER PROJECT, i.e., you're just creating something that control 

the bot. That is because UT2004Bot is wrapping all the low-level communication stuff with 

GameBots2004 (i.e., Unreal Tournament 2004) you do not want to care about. All you 

(usually) want is to code a behavior for your bot.
(This is our stance when coding Pogamut).

In fact, we did not spot any place where a user might want to extends the UT2004 except the 

IUT2004BotController methods. That is to instantiate 2 (or more) different bots means to 

instantiate 2 (or more) UT2004Bot objects each having a different IUT2004BotController 

implementation.

As I said before, UT2004Bot handles communication with GB2004 which involves great deal of 

objects that interacts with each others having their own threads, states, behaviors, etc... 

Thus to construct UT2004Bot means to instantiate a lot of (correct) objects in concrete 

sequence embedding one into another until you finally instantiates an UT2004Bot. Pretty 

hard to do if you are not one of the authors... but the whole thing is handled gracefully 

with Google Guice IoC container. I recommand you to see UT2004BotModule class which is a 

descendent of some other classes which are defining dependencies between interfaces and 

their implementations providing Guice an information how you want to instantiate the 

UT2004Bot (or IAgent which is a base interface for any Pogamut's agent).

Guice module, i.e., UT2004BotModule is a place where you:
1) saying which IUT2004BotController implementation you want to use (that's why it has a 

constructor with Class< extends IUT2004BotController> as parameter)
2) providing a parametrization of the agent (check the UT2004AgentParameters) ... note that 

UT2004Bot has a method getParams() which returns them, you are free to extend 

UT2004AgentParameters and pass them into your bot in order to parametrize the behavior of 

your bot (i.e., set a concrete skill level of the bot, sparing you of hard coding such 

things into your IUT2004BotController implementation).

To utilize the UT2004BotModule you may use UT2004BotFactory but this is not needed because 

it is internally wrapped by the MultipleUT2004BotRunner that provides an abstraction for 

running a bunch of bots.

All you have to do is to utilize this method from MultipleUT2004BotRunner:

public List<BOT> startAgents(IAgentDescriptor<PARAMS,MODULE>... agentDescriptors)

It says you may provide arbitrary number of UT2004BotDescriptor objects which contains 

information about which bots you want to start (i.e., which IUT2004BotController to 

utilize) and which parameters you want to pass.

To put long story short, let's say you have three controllers ... Hunter, Prey, Defender 

and you want to start one instance of UT2004Bot for every controller. You will code 

something like this:


UT2004BotDescriptor hunterDesc = new UT2004BotDescriptor().setController

(Hunter.class).addParams(new UT2004AgentParameters());
UT2004BotDescriptor preyDesc = new UT2004BotDescriptor().setController

(Prey.class).addParams(new UT2004AgentParameters());
UT2004BotDescriptor defenderDesc = new UT2004BotDescriptor().setController

(Defebder.class).addParams(new UT2004AgentParameters());

new MultipleUT2004BotRunner("Multiple").setMain(true).startAgents(hunterDesc, preyDesc, 

defenderDesc);


Note that you do not need to set any special parameters to UT2004AgentParameters class as 

defaults are picked up via "assignDefaults()" method from inside the 

MultipleUT2004BotRunner that gets them from the Pogamut.getPlatform().getProperty

(PogamutProperty.XXX.getKey()).

If you want to start for instance more prays (let's say 3), you would modify the code like 

this:

UT2004BotDescriptor hunterDesc = new UT2004BotDescriptor().setController

(Hunter.class).addParams(new UT2004AgentParameters());
UT2004BotDescriptor preyDesc = new UT2004BotDescriptor().setController

(Prey.class).addParams(new UT2004AgentParameters()).addParams(new UT2004AgentParameters

()).addParams(new UT2004AgentParameters());
UT2004BotDescriptor defenderDesc = new UT2004BotDescriptor().setController

(Defebder.class).addParams(new UT2004AgentParameters());

new MultipleUT2004BotRunner("Multiple").setMain(true).startAgents(hunterDesc, preyDesc, 

defenderDesc);


If you wish to use your own HunterParameters extends UT2004AgentParameters, which have a 

constructor specifying the skill level of the hunter you will do something like:

UT2004BotDescriptor hunterDesc = new UT2004BotDescriptor().setController

(Hunter.class).addParams(new HunterParameters(5));
UT2004BotDescriptor preyDesc = new UT2004BotDescriptor().setController

(Prey.class).addParams(new UT2004AgentParameters()).addParams(new UT2004AgentParameters

()).addParams(new UT2004AgentParameters());
UT2004BotDescriptor defenderDesc = new UT2004BotDescriptor().setController

(Defebder.class).addParams(new UT2004AgentParameters());

new MultipleUT2004BotRunner("Multiple").setMain(true).startAgents(hunterDesc, preyDesc, 

defenderDesc);


Note that "Multiple" will be used as a basis for all bot's ids. If you want to supply your 

own ID (which is also a basis for a bot's name, but that may be changed later in the 

controller in getInitialize() method) you will do something like:


UT2004BotDescriptor hunterDesc = new UT2004BotDescriptor().setController

(Hunter.class).addParams(new HunterParameters(5).setAgentId(new AgentId("Hunter"));
...
new MultipleUT2004BotRunner("Multiple").setMain(true).startAgents(hunterDesc, preyDesc, 

defenderDesc);


Hope it helps :-)

Jimmy

-- 
Reply Link: <http://diana.ms.mff.cuni.cz/main/tiki-view_forum_thread.php?forumId=4&comments_reply_threadId=4&comments_parentId=221&post_reply=1#form>





More information about the Pogamut-list mailing list