Help - Robocode .NET

87 views
Skip to first unread message

Eduardo Silveira

unread,
Apr 25, 2015, 5:08:44 AM4/25/15
to robo...@googlegroups.com
Hello, I am new in Robocode. I'm using the .NET api Robocode. I changed the location of the Robocode .net api installation directory. When I run the battle runner the following exception: Can not load java class for robocode.control.events.BattleEvent from ClassLoader sun.misc.Launcher$AppClassLoader@c387f44.

See my source below the battle runner:


using System;
using Robocode;
using Robocode.Control;
using Robocode.Control.Events;

class BattleRunner
{
    static void Main(string[] args)
    {
        // Create the RobocodeEngine
        RobocodeEngine engine = new RobocodeEngine("C:\\Users\\auditorio\\Desktop\\robocode"); // Run from C:\Robocode

        // Add battle event handlers
        engine.BattleCompleted += new BattleCompletedEventHandler(BattleCompleted);
        engine.BattleMessage += new BattleMessageEventHandler(BattleMessage);
        engine.BattleError += new BattleErrorEventHandler(BattleError);

        // Show the Robocode battle view
        engine.Visible = true;

        // Disable log messages from Robocode
        RobocodeEngine.LogMessagesEnabled = false;

        // 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);

        // Run our specified battle and let it run till it is over
        engine.RunBattle(battleSpec, true /* wait till the battle is over */);

        // Cleanup our RobocodeEngine
        engine.Close();
    }

    // Called when the battle is completed successfully with battle results
    private static void BattleCompleted(BattleCompletedEvent e)
    {
        Console.WriteLine("-- Battle has completed --");

        // Print out the sorted results with the robot names
        Console.WriteLine("Battle results:");
        foreach (BattleResults result in e.SortedResults)
        {
            Console.WriteLine("  " + result.TeamLeaderName + ": " + result.Score);
        }
    }

    // Called when the game sends out an information message during the battle
    private static void BattleMessage(BattleMessageEvent e)
    {
        Console.WriteLine("Msg> " + e.Message);
    }

    // Called when the game sends out an error message during the battle
    private static void BattleError(BattleErrorEvent e)
    {
        Console.WriteLine("Err> " + e.Error);
    }
}

Can anyone help me?

Regards,


fnl

unread,
Apr 26, 2015, 5:10:50 AM4/26/15
to robo...@googlegroups.com
Robocode .NET is running on top of a Java Virtual Machine (JVM), which cannot locate a class from a .jar file under [robocode dir]\libs, where [robocode dir] is where Robocode is installed.

In your BattleRunner, you point to: C:\\Users\\auditorio\\Desktop\\robocode

This means that the [robocode dir] is located on your desktop?

I recommend that you install both Robocode (setup jar file) and Robocode .NET plugin into C:\robocode, and the point BattleRunner to C:\\robocode.

Best regards,
- Flemming
Reply all
Reply to author
Forward
0 new messages