[Home]Teams/IdentifyingTheBots

Robo Home | Teams | Changes | Preferences | AllPages

Showing revision 4
Some times is important to have your bots identified (pe. if you want to send them messages). The problem is that you have to build the identificator, and every bot will try to do it on its own, so you need some logic to get them coordinated. The easier way is to use the bot number that robocode assigns to every one of your bots.

The following function does it:

static public int getBotNumber(String name) {
 	String n = "0";
 	int low = name.indexOf("(")+1; int hi = name.lastIndexOf(")");
 	if (low >= 0 && hi >=0) { n = name.substring(low, hi); }
 	return Integer.parseInt(n);
}
Note that I have not tested it when there is more than one class of bots in a team. -- Albert


It won't work if there is more than one class of bots in a team because for each type the numbering starts back at 1. For example:

ExampleTeam
LeaderBot (no number if there is only one of them)
BigBadBot 1
BigBadBot 2
SmallGoodBot 1
SmallGoodBot 2

So how do you deal with a situation like this?

if(getEnergy()>199.0){ //220 if leader is a droid, 200 otherwise.
	String[] teammates = getTeammates();
	Vector v = new Vector();
	v.add(getName());
	for(int i = 0; i < teammates.length; i++){
		v.add(teammates[i]);
	}
	
	teammates = (String[]) v.toArray();
	try{
		broadcastMessage(teammates);
	}catch(Exception e){}
}

Then just have all bots store the String[] message and do lookups in that array to get the ID of a bot. (Bot ID = position in array)

--David Alves

Or you could just make sure all of the bots on your team have the same name plus a number... like have Bot1, Bot2, etc. You could know that Bot1 was the leader, but its name would be the same... it's a question of simplicity over choosing a name... --Bayen, on returning to the wiki!!


Robo Home | Teams | Changes | Preferences | AllPages
Edit revision 4 of this page | View other revisions | View current revision
Edited September 13, 2007 22:41 EST by pool-71-244-98-194.phlapa.fios.verizon.net (diff)
Search: