[Pogamut-list] Controlling Bot
jakub.gemrot
pogamut-forum at diana.ms.mff.cuni.cz
Wed Dec 22 07:39:55 CET 2010
Re: Controlling Bot
Author: jakub.gemrot
Hi,
I've created the test observer as an extension of UT2004Observer, that means, you can't use UT2004ObserverRunner for that. Instead, you must use UT2004ObserverFactory for that purpose.
UT2004ObserverFactory requires UT2004ObserverModule (If you want to know more, read something about goog Guice IoC that we're using). Thus you have to create an extension of UT2004ObserverModule where you specify that it is this new observer you want to construct.
Module:
{CODE()}
public class TestUT2004BotObserverModule extends UT2004ObserverModule {
@Override
protected void configureModules() {
super.configureModules();
addModule(new AbstractModule() {
@Override
public void configure() {
bind(IUT2004Observer.class).to(TestUT2004BotObserver.class);
}
});
}
}
{CODE}
Now having such a module, you may instantiate the factory:
{CODE()}
UT2004ObserverFactory observerFactory = new UT2004ObserverFactory(new TestUT2004BotObserverModule());
{CODE}
When you look at the methods the factory is offering, you will find out you have to provide some parameters that the observer is going to be started with. Note that this is a place, where you may provide your custom class with your own parameters which will be accessible then inside the observer via getParams() method (this is a way how to parametrize your agent).
Anyway, I will just create a common params for now and leave experiments to you.
{CODE()}
UT2004AgentParams observerParams =
new UT2004AgentParams()
.setWorldAddress("localhost", 3002)
.setAgentId(new AgentId("observer");
{CODE}
Good, this params is telling that you want to name your observer as "observer" and you want it to connect to localhost:3002.
Now, we may instantiate our observer.
{CODE()}
TestUT2004BotObserver observer = (TestUT2004BotObserver)observerFactory.newAgent(observerParams);
{CODE}
Having the observer constructed, you may start it. Note that you have to take care of cleaning up stuff for yourself when not using UT2004xxxRunner, thus always use try/finally.
{CODE()}
observer.start();
try {
observer.startObserving(someBotId);
// do your work here
observer.stop();
} finally {
if (observer.inState(IAgentStateUp.class)) observer.kill();
}
{CODE}
Cheers!
Jimmy
--
Reply Link: <http://diana.ms.mff.cuni.cz/main/tiki-view_forum_thread.php?forumId=4&comments_reply_threadId=4&comments_parentId=446&post_reply=1#form>
More information about the Pogamut-list
mailing list