http://home.comcast.net/~kokyunage/robocode/communication.jar
The files belong in a package named wiki.team.communication. The version can be obtained by calling String getVersion() on an instance of a Communique implementation. At this point, the version is "Beta 1.0", and there is no JavaDoc? available, but the code examples below should illustrate their usage.
Usage examples:
Sending and Receiving: (these methods exist in my event handling layer)
protected void processAllEvents() { Iterator<? extends Event> iterator; // ... // I was going by an old API in which TeamRobot does not have a getMessageEvents() iterator = this.getAllEvents().iterator(); while( iterator.hasNext() ) { Event e = iterator.next(); if( e instanceof MessageEvent ) { this.process( (MessageEvent)e ); } } this.processTeamMessage( this.communiques ); // ... } protected abstract void processTeamMessage( List<Communique> communiques ); public void prepareCommunique( Communique communique ) { this.communiques.add( communique ); } public void transmitCommuniques() { try { this.broadcastMessage( CommuniqueFactory.packageCommuniques( this.communiques ) ); } catch( IOException ex ) { ExceptionHandler.handleException( ex ); } this.communiques.clear(); } private List<Communique> communiques = new ArrayList<Communique>();
Using Communique data : (these methods exist in my 'foundation' layer, between the event handling and my specific bot (Ugluk, Banzai, etc) ).
In the examples below, I haven't really done much to illustrate the larger formats (yet).
protected void processTeamMessage( List<Communique> communiques ) { Iterator<Communique> iterator = communiques.iterator(); while( iterator.hasNext() ) { Communique c = iterator.next(); if( c instanceof CommuniquePersonalData ) consoleTick( c.toString() ); else if( c instanceof CommuniqueMyBullet ) consoleTick( c.toString() ); else if( c instanceof CommuniqueEnemyScan ) consoleTick( c.toString() ); else if( c instanceof CommuniqueEnemyWave ) consoleTick( c.toString() ); else if( c instanceof CommuniqueMyRadarTarget ) { CommuniqueMyRadarTarget mr = ( CommuniqueMyRadarTarget ) c; System.out.println( c.getSender() + " is scanning " + mr.name ); } else if( c instanceof CommuniqueMyBulletTarget ) { CommuniqueMyBulletTarget mb = ( CommuniqueMyBulletTarget ) c; System.out.println( c.getSender() + " is aiming for " + mb.name ); } else if( c instanceof CommuniqueSuggestedRadarTarget ) { CommuniqueSuggestedRadarTarget tr = ( CommuniqueSuggestedRadarTarget ) c; System.out.println( c.getSender() + " suggests scanning " + tr.name ); } else if( c instanceof CommuniqueSuggestedBulletTarget ) { CommuniqueSuggestedBulletTarget tb = ( CommuniqueSuggestedBulletTarget ) c; System.out.println( c.getSender() + " suggests aiming for " + tb.name ); } else if( c instanceof CommuniqueOther ) { CommuniqueOther na = ( CommuniqueOther ) c; System.out.println( c.getSender() + " says " + na.message ); } else if( c instanceof CommuniqueNotAvailable ) { CommuniqueNotAvailable na = ( CommuniqueNotAvailable ) c; System.out.println( c.getSender() + " tries to communicate " + na.message ); } else { System.out.println( c.getSender() + " fails to communicate." ); } iterator.remove(); } }
Constructors for the Communique implementations take all values in the message format, in the order shown, with the exception of the two character message type code (which is implicit).
-- Martin Pedersen
Here is a link to the source in a zip file. http://home.comcast.net/~kokyunage/robocode/wiki.team.communication.zip Please see the new wiki for comments on usage. -- Martin