Robo Home | Teams | Changes | Preferences | AllPages

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:

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();
	for(int i = 0; i < teammates.length; i++){
	teammates = (String[]) v.toArray();
	}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 text of this page | View other revisions
Last edited September 14, 2007 2:17 EST by Starrynte (diff)