Java exceptions with bot controlling several "sub-bots&

AI discussion, ideas, and SDK help.
Post Reply
_hugo_
Lux Newbie
Posts: 2
Joined: Wed Dec 24, 2008 2:08 pm
Location: Montreal

Java exceptions with bot controlling several "sub-bots&

Post by _hugo_ » Wed Dec 31, 2008 10:58 am

I've been slowly getting to know about the bots SDK, and as a first attempt at bot-writing, I've written a very simple bot that just randomly switches control of the bot's action to other hard "sub-bots", such as Reaper, Killbot, EvilPixie and others (kind of like Chimera). To do this, I simply create instances of those "sub-bots" in the setPrefs() method, and I call their setPrefs method with the given newID and theboard values, as follows:

Code: Select all

public void setPrefs( int newID, Board theboard )
	{
	ID = newID;

	board = theboard;
	countries = board.getCountries();

	numCountries = countries.length;
	numContinents = board.getNumberOfContinents();
	
	agents = new LuxAgent[5];
	agents[0] = new Killbot();
	agents[1] = new Boscoe();
	agents[2] = new Quo();
	agents[3] = new Reaper();
	agents[4] = new EvilPixie();
	for( int i=0; i<agents.length; i++)
	    agents[i].setPrefs(newID, theboard);
	}
Then, in placeArmies(), attackPhase(), moveArmies() and fortifyPhase(), I randomly select one of the sub-bots to take action, by calling the associated method of the sub-bot.

Unfortunately, my problem right now is that I keep getting java.lang.NullPointerException errors. My problem seems to be similar actually to that reported here: http://sillysoft.net/forums/viewtopic.php?p=55385. I also get this sort of exception sometimes:

java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1176)
at com.sillysoft.lux.B.A(Unknown Source)
at com.sillysoft.lux.B.A(Unknown Source)
at com.sillysoft.lux.Board.attack(Unknown Source)
at com.sillysoft.lux.Board.attack(Unknown Source)
at com.sillysoft.lux.agent.SmartAgentBase.attackForCard(Unknown Source)
at com.sillysoft.lux.agent.SmartAgentBase.attackForCard(Unknown Source)
at com.sillysoft.lux.agent.BetterPixie.attackPhase(Unknown Source)
at com.sillysoft.lux.agent.Vulture.attackPhase(Unknown Source)
at com.sillysoft.lux.B._(Unknown Source)
at com.sillysoft.lux.B.P(Unknown Source)
at com.sillysoft.lux.B.run(Unknown Source)
at java.lang.Thread.run(Thread.java:613)


Has anyone ever stumbled on this issue and found a way to resolve it? That would be great, as my idea for a new AI bot is centered around the use of other sub-bots...

Thanks!

User avatar
Bertrand
Reaper Creator
Posts: 568
Joined: Mon Nov 28, 2005 4:35 pm
Location: Montreal

Re: Java exceptions with bot controlling several "sub-b

Post by Bertrand » Thu Jan 01, 2009 7:42 am

_hugo_ wrote:Then, in placeArmies(), attackPhase(), moveArmies() and fortifyPhase(), I randomly select one of the sub-bots to take action, by calling the associated method of the sub-bot.
Sorry _hugo_, but that will never work. Advanced bots like Reaper use global variables to communicate between those methods. By randomly switching between bots, you are messing up this process.

If you want to use a slave-bot, calling each and every method in the right order is mandatory. You then, in effect, become that slave bot, and what's the point of doing that?

If you want to combine features of the built-in bots, then the best way is to start with the source code of one of them. That's what I did with Reaper: he is a very heavily modified version of Angry!

Post Reply