Recording RoboCode battles from Java API

[email protected] Fri, 4 Mar 2016 02:05:31 -0800 (PST)
Newsgroups gmane.comp.java.robocode
Message-ID <[email protected]>
Hello everyone

I'm trying to record battles from the java API. I would like to trigger 
battles inside Java and then, at the end of the run, be able to see the 
replay only of the battles i'm interested in.

This is my code:

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

import robocode.control.*;
import net.sf.robocode.battle.events.BattleEventDispatcher;
import net.sf.robocode.io.Logger;
import net.sf.robocode.recording.BattleRecordFormat;
import net.sf.robocode.recording.RecordManager;
import net.sf.robocode.serialization.SerializableOptions;
import net.sf.robocode.settings.SettingsManager;

public class BattleRunner {
     
    // Path configuration
    public static String roboCodePath = 
"/home/andrea/git/AttProgIA_2016/RoboCode";

    private static String recordFile = "/tmp/testingLOL.xml";
    
    // Recording 
    private static SettingsManager settingsManager = new SettingsManager();
    private static BattleEventDispatcher battleEventDispatcher = new 
BattleEventDispatcher();
    private static RecordManager recordManager = new 
RecordManager(settingsManager);
 
    public static void main(String[] args) {
 

        // Disable log messages from Robocode
        RobocodeEngine.setLogMessagesEnabled(false);

        // Create the RobocodeEngine
        RobocodeEngine engine = new RobocodeEngine(new 
java.io.File(roboCodePath));

 
        // Setup the battle specification
 
        int numberOfRounds = 5;
        BattlefieldSpecification battlefield = new 
BattlefieldSpecification(800, 600); // 800x600
        RobotSpecification[] selectedRobots = 
engine.getLocalRepository("sample.RamFire,sample.Corners");
 
        BattleSpecification battleSpec = new 
BattleSpecification(numberOfRounds, battlefield, selectedRobots);

        // *********************
        Logger.setLogListener(battleEventDispatcher);
        recordManager.attachRecorder(battleEventDispatcher);
        
 
        // Show the Robocode battle view
        engine.setVisible(false);
        
        // *********************
               
        // Run our specified battle and let it run till it is over
        engine.runBattle(battleSpec, true); // waits till the battle 
finishes
 
        // Save the recording
        
        recordManager.saveRecord(recordFile, BattleRecordFormat.XML, new 
SerializableOptions(false));
        // Cleanup our RobocodeEngine
        engine.close();
 
        // Make sure that the Java VM is shut down properly
        System.exit(0);
     }
 }

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Unfortunately all i get it's:

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

No robocode.properties. Using defaults.
Exception in thread "Application Thread" java.lang.NullPointerException
    at 
net.sf.robocode.recording.RecordManager.saveRecord(RecordManager.java:344)
    at BattleRunner.main(BattleRunner.java:57)

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Which i really don't understand... battles run properly (i tried to print 
the results and it works correctly), but as soon as i try to save the 
record i receive this null pointer exception. It looks like the recordInfo 
variable inside RecordManager it's not initialized properly...

Can you give me a hint? It's really annoying, and unfortunately i can't 
find any documentation or examples online...

Thank you

Andrea

-- 
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.