Loading...
 

PogamutUT2004


Determining which team to spawn a bot into during initialization

In Pogamut2, this was easy. In postPrepareAgent(), I could get the number of players on each team through the memory field and initialize the starting team before the bot spawned.

I've searched for something similar in Pogamut3. I've probably overlooked something but I can't seem to find anything that is helpful, at least in the early stages of the bot's life.

I've tried e.g. getWorldView().getAll(Player.class) in varoius phases of initialization only to finally realize it only returns visible players from the bot's perspective...
I'm assuming this also goes for all the sensor modules and wrappers.

I looked into the Observer classes after remembering one of my earlier questions. I tried doing something like:
observer = factory.newAgent(new SocketConnectionAddress("127.0.0.1", 3002));
observer.getWorldView().addEventListener(PlayerListObtained.class, new IWorldEventListener(){...});
observer.getAct().act(new GetPlayers());
to no avail (Listener was supposed to write to both log and stderr). I don't see the game server reporting any connections from the Observer either.

Is there any way to communicate directly with the server and get a complete list of players during initialization? I would prefer the programmatic control of team selection instead of letting UT team balancing do the work.

Cheers,
Simon
(Sorry for the convoluted post)
Hi Simon!

Yes, no problem (except, it is currently hidden). All you need to do is to hook the listener to PlayerListObtained event, see JavaDoc The listener can be set up via getWorldView().addEventListener(PlayerListObtained.class, playerListListener) where playerListListener is of type IWorldEventListener ... remember that you have to store the reference to that listener, otherwise it will be a subject for GC!

This event is raised before the getInitializeCommand() is called therefore you may obtain how many players are inside the game.

To make it more comfortable - we're going to extend the Players agent module to take PlayerListObtained into the account may be even providing method
getTeamBalance() to provide a number of a team to connect into.

Best,
Jakub aka Jimmy
Unfortunately we can't slip Player.class into worldview early due to some inconsistencies inside agent modules that would crash :-( ... I'm going to fix that as well of course... so now, please use the PlayerListObtained event/listener solution.

Thanks!

Jimmy
Thanks for the feedback.

I think that what I had actually done before is the same as what you describe.

I did, however, create the Observer directly through the Factory, without ever calling start or anything on it..

I tried to run it again with observer.start(), without any improvements. I added a global event listener as well:

IUT2004Observer observer = new UT2004ObserverRunner(new UT2004ObserverFactory(), "ObserverTest", "localhost", 3002).startAgent();

IWorldEventListener listObtainedListener = new IWorldEventListener() {
public void notify(PlayerListObtained event) {
System.out.println("Received PlayerListObtained event in Observer");
observedPlayers = event.getPlayers();
for(Player player :observedPlayers) {
System.out.println(" player = " + player.getName() + " : " + player.getTeam());
}
}
};
IWorldEventListener globalListener = new IWorldEventListener() {
int updateEvents = 0;

public void notify(IWorldEvent event) {
if(!(event instanceof WorldObjectUpdatedEvent && ((WorldObjectUpdatedEvent) event).getObject() instanceof InfoMessage)) {
System.err.println("event = " + event);
}
else if(++updateEvents % 1000 == 0) {
System.err.println("event = " + event);
}
}
};
observer.getWorldView().addEventListener(PlayerListObtained.class, listObtainedListener);
observer.getWorldView().addEventListener(IWorldEvent.class, globalListener);

(I filtered the global listener since the amount of update info messages is astounding :-) too bad there's no Code tags in the forum)

In any case, now I see the Observer connecting to the server in the server console and it definitely receives events. I can see in the logs that the bots are happily running around and performing whatever their simple logic can handle.
But I still don't see any PlayerListObtained events, no matter how much I call observer.getAct().act(new GetPlayers()).

Can you see what I'm doing wrong?

(Btw. I reported an issue to the Mantis. Took me a while to figure out why the ObserverRunner caused a show-stopping UnexpectedMessageException, since I assumed that my observer properties would work without manually inserting the host and port in the ObserverRunner constructor. I might have overstepped my bounds by reporting it as a crash, since the Pogamut platform actually quits gracefully. Sorry for that, couldn't edit it)
While writing the above comment, I realized that you might have meant to perform the operations not on the Observer but on the Bot.
After posting, I tried this and the bot does indeed receive the PlayerListObtained event. So now I'm happy that I have a way to proceed with this.

It does lead me to the question of whether the Observer works as intended, though? It might just have been an error on my part, but it's not immediately clear to me why the Observer can't receive the event as well.

My error or is it a bug?
Hi Simon!

Cool you've made it :-)

UT2004Observer is more or less Alpha version.
Observer is meant to observer single player only! And does not have a support for doing so (it would take a while to dig it up inside GB2004 documentation). So I won't tell you whether its behavior was correct or not for now. It will be revisited this summer for sure ;-) The only thing I can tell is, we did not test any of Agent modules together with the observer.

Best,
Jimmy
 

News

News RSS RSS feed for News link



Pogamut

Quarterly RSS RSS feed for quarterly reports

Acknowledgement

This work is supported by GA UK 1053/2007/A-INF/MFF (2007-8), GA UK 351/2006/A-INF/MFF (2006-8), the Ministry of Education of the Czech Republic (grant MSM0021620838) (2008-9), by the Program "Information Society" under project 1ET100300517 (2006-9), and the project Integration of IT Tools into Education of Humanities (2006-8) and by the project CZ.2.17/3.1.00/31162, which are financed by the European Social Fund, the state budget of the Czech Republic, and by the budget of Municipal House Prague.