Beispiel #1
0
    static void Main(string[] args)
    {
        // Create the RobocodeEngine
        RobocodeEngine engine = new RobocodeEngine("C:\\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();
    }
 /// <summary>
 /// Creates a new BattleSpecification with the given settings.
 /// </summary>
 /// <param name="numRounds">The number of rounds in this battle.</param>
 /// <param name="inactivityTime">The inactivity time allowed for the robots before
 /// they will loose energy.</param>
 /// <param name="gunCoolingRate">The gun cooling rate for the robots.</param>
 /// <param name="battlefieldSize">The battlefield size.</param>
 /// <param name="robots">The robots participating in this battle.</param>
 public BattleSpecification(int numRounds, long inactivityTime, double gunCoolingRate, BattlefieldSpecification battlefieldSize, RobotSpecification[] robots)
 {
     this.numRounds = numRounds;
     this.inactivityTime = inactivityTime;
     this.gunCoolingRate = gunCoolingRate;
     this.battlefieldWidth = battlefieldSize.Width;
     this.battlefieldHeight = battlefieldSize.Height;
     this.robots = robots;
 }
Beispiel #3
0
        public BattleRunner(String roboPath = @"C:\robocode")
        {
            _engine = new RobocodeEngine(roboPath);
            // Show the Robocode battle view
            _engine.Visible = true;

            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();
        }
Beispiel #4
0
 /// <summary>
 /// Creates a new BattleSpecification with the given settings.
 /// </summary>
 /// <param name="battlefieldSize">The battlefield size.</param>
 /// <param name="numRounds">The number of rounds in this battle.</param>
 /// <param name="inactivityTime">The inactivity time allowed for the robots before
 /// they will loose energy.</param>
 /// <param name="gunCoolingRate">The gun cooling rate for the robots.</param>
 /// <param name="sentryBorderSize">The sentry border size for a <see cref="Robocode.IBorderSentry">BorderSentry</see>.</param>
 /// <param name="hideEnemyNames">Flag specifying if enemy names are hidden from robots.</param>
 /// <param name="robots">The robots participating in this battle.</param>
 /// <param name="initialSetups">The initial position and heading of the robots, where the indices matches the indices from the <paramref name="robots"/>.</param>
 public BattleSpecification(BattlefieldSpecification battlefieldSize, int numRounds, long inactivityTime, double gunCoolingRate, int sentryBorderSize, bool hideEnemyNames, RobotSpecification[] robots, RobotSetup[] initialSetups)
 {
     if (battlefieldSize == null)
     {
         throw new ArgumentException("battlefieldSize cannot be null");
     }
     if (robots == null)
     {
         throw new ArgumentException("robots cannot be null");
     }
     if (robots.Length < 1)
     {
         throw new ArgumentException("robots.Length must be > 0");
     }
     if (initialSetups != null && initialSetups.Length != robots.Length)
     {
         throw new ArgumentException("initialSetups.Length must be == robots.Length");
     }
     if (numRounds < 1)
     {
         throw new ArgumentException("numRounds must be >= 1");
     }
     if (inactivityTime < 1)
     {
         throw new ArgumentException("inactivityTime must be >= 1");
     }
     if (gunCoolingRate < 0.1)
     {
         throw new ArgumentException("inactivityTime must be >= 0.1");
     }
     if (sentryBorderSize < 50)
     {
         throw new ArgumentException("sentryBorderSize must be >= 50");
     }
     this.battlefieldWidth  = battlefieldSize.Width;
     this.battlefieldHeight = battlefieldSize.Height;
     this.numRounds         = numRounds;
     this.inactivityTime    = inactivityTime;
     this.gunCoolingRate    = gunCoolingRate;
     this.sentryBorderSize  = sentryBorderSize;
     this.hideEnemyNames    = hideEnemyNames;
     this.robots            = robots;
     this.initialSetups     = initialSetups;
 }
Beispiel #5
0
 /// <summary>
 /// Creates a new BattleSpecification with the given settings.
 /// </summary>
 /// <param name="battlefieldSize">The battlefield size.</param>
 /// <param name="numRounds">The number of rounds in this battle.</param>
 /// <param name="inactivityTime">The inactivity time allowed for the robots before
 /// they will loose energy.</param>
 /// <param name="gunCoolingRate">The gun cooling rate for the robots.</param>
 /// <param name="sentryBorderSize">The sentry border size for a <see cref="Robocode.IBorderSentry">BorderSentry</see>.</param>
 /// <param name="hideEnemyNames">Flag specifying if enemy names are hidden from robots.</param>
 /// <param name="robots">The robots participating in this battle.</param>
 public BattleSpecification(BattlefieldSpecification battlefieldSize, int numRounds, long inactivityTime, double gunCoolingRate, int sentryBorderSize, bool hideEnemyNames, RobotSpecification[] robots) :
     this(battlefieldSize, numRounds, inactivityTime, gunCoolingRate, 100, hideEnemyNames, robots, null)
 {
 }
Beispiel #6
0
 /// <summary>
 /// Creates a new BattleSpecification with the given settings.
 /// </summary>
 /// <param name="numRounds">The number of rounds in this battle.</param>
 /// <param name="inactivityTime">The inactivity time allowed for the robots before
 /// they will loose energy.</param>
 /// <param name="gunCoolingRate">The gun cooling rate for the robots.</param>
 /// <param name="battlefieldSize">The battlefield size.</param>
 /// <param name="robots">The robots participating in this battle.</param>
 public BattleSpecification(int numRounds, long inactivityTime, double gunCoolingRate, BattlefieldSpecification battlefieldSize, RobotSpecification[] robots) :
     this(numRounds, inactivityTime, gunCoolingRate, false, battlefieldSize, robots)
 {
 }
Beispiel #7
0
 /// <summary>
 /// Creates a new BattleSpecification with the given number of rounds,
 /// battlefield size, and robots. Inactivity time for the robots defaults to
 /// 450, and the gun cooling rate defaults to 0.1.
 /// </summary>
 /// <param name="numRounds">The number of rounds in this battle.</param>
 /// <param name="battlefieldSize">The battlefield size.</param>
 /// <param name="robots">The robots participating in this battle.</param>
 public BattleSpecification(int numRounds, BattlefieldSpecification battlefieldSize, RobotSpecification[] robots) :
     this(numRounds, 450, .1, battlefieldSize, robots)
 {
 }
 /// <summary>
 /// Creates a new BattleSpecification with the given settings.
 /// </summary>
 /// <param name="battlefieldSize">The battlefield size.</param>
 /// <param name="numRounds">The number of rounds in this battle.</param>
 /// <param name="inactivityTime">The inactivity time allowed for the robots before
 /// they will loose energy.</param>
 /// <param name="gunCoolingRate">The gun cooling rate for the robots.</param>
 /// <param name="sentryBorderSize">The sentry border size for a <see cref="Robocode.IBorderSentry">BorderSentry</see>.</param>
 /// <param name="hideEnemyNames">Flag specifying if enemy names are hidden from robots.</param>
 /// <param name="robots">The robots participating in this battle.</param>
 public BattleSpecification(BattlefieldSpecification battlefieldSize, int numRounds, long inactivityTime, double gunCoolingRate, int sentryBorderSize, bool hideEnemyNames, RobotSpecification[] robots) :
     this(battlefieldSize, numRounds, inactivityTime, gunCoolingRate, 100, hideEnemyNames, robots, null)
 {
 }
 /// <summary>
 /// Creates a new BattleSpecification with the given settings.
 /// </summary>
 /// <param name="numRounds">The number of rounds in this battle.</param>
 /// <param name="inactivityTime">The inactivity time allowed for the robots before
 /// they will loose energy.</param>
 /// <param name="gunCoolingRate">The gun cooling rate for the robots.</param>
 /// <param name="battlefieldSize">The battlefield size.</param>
 /// <param name="robots">The robots participating in this battle.</param>
 public BattleSpecification(int numRounds, long inactivityTime, double gunCoolingRate, BattlefieldSpecification battlefieldSize, RobotSpecification[] robots) :
     this(numRounds, inactivityTime, gunCoolingRate, false, battlefieldSize, robots)
 {
 }
Beispiel #10
0
 /// <summary>
 /// Creates a new BattleSpecification with the given number of rounds,
 /// battlefield size, and robots. Inactivity time for the robots defaults to
 /// 450, and the gun cooling rate defaults to 0.1.
 /// </summary>
 /// <param name="numRounds">The number of rounds in this battle.</param>
 /// <param name="battlefieldSize">The battlefield size.</param>
 /// <param name="robots">The robots participating in this battle.</param>
 public BattleSpecification(int numRounds, BattlefieldSpecification battlefieldSize, RobotSpecification[] robots) :
     this(numRounds, 450, .1, battlefieldSize, robots)
 {
 }
Beispiel #11
0
 /// <summary>
 /// Creates a new BattleSpecification with the given settings.
 /// </summary>
 /// <param name="battlefieldSize">The battlefield size.</param>
 /// <param name="numRounds">The number of rounds in this battle.</param>
 /// <param name="inactivityTime">The inactivity time allowed for the robots before
 /// they will loose energy.</param>
 /// <param name="gunCoolingRate">The gun cooling rate for the robots.</param>
 /// <param name="sentryBorderSize">The sentry border size for a <see cref="Robocode.IBorderSentry">BorderSentry</see>.</param>
 /// <param name="hideEnemyNames">Flag specifying if enemy names are hidden from robots.</param>
 /// <param name="robots">The robots participating in this battle.</param>
 /// <param name="initialSetups">The initial position and heading of the robots, where the indices matches the indices from the <paramref name="robots"/>.</param>
 public BattleSpecification(BattlefieldSpecification battlefieldSize, int numRounds, long inactivityTime, double gunCoolingRate, int sentryBorderSize, bool hideEnemyNames, RobotSpecification[] robots, RobotSetup[] initialSetups)
 {
     if (battlefieldSize == null)
     {
         throw new ArgumentException("battlefieldSize cannot be null");
     }
     if (robots == null)
     {
         throw new ArgumentException("robots cannot be null");
     }
     if (robots.Length < 1)
     {
         throw new ArgumentException("robots.Length must be > 0");
     }
     if (initialSetups != null && initialSetups.Length != robots.Length)
     {
         throw new ArgumentException("initialSetups.Length must be == robots.Length");
     }
     if (numRounds < 1)
     {
         throw new ArgumentException("numRounds must be >= 1");
     }
     if (inactivityTime < 1)
     {
         throw new ArgumentException("inactivityTime must be >= 1");
     }
     if (gunCoolingRate < 0.1)
     {
         throw new ArgumentException("inactivityTime must be >= 0.1");
     }
     if (sentryBorderSize < 50)
     {
         throw new ArgumentException("sentryBorderSize must be >= 50");
     }
     this.battlefieldWidth = battlefieldSize.Width;
     this.battlefieldHeight = battlefieldSize.Height;
     this.numRounds = numRounds;
     this.inactivityTime = inactivityTime;
     this.gunCoolingRate = gunCoolingRate;
     this.sentryBorderSize = sentryBorderSize;
     this.hideEnemyNames = hideEnemyNames;
     this.robots = robots;
     this.initialSetups = initialSetups;
 }
Beispiel #12
0
 /// <summary>
 /// Creates a new BattleSpecification with the given settings.
 /// </summary>
 /// <param name="numRounds">The number of rounds in this battle.</param>
 /// <param name="inactivityTime">The inactivity time allowed for the robots before
 /// they will loose energy.</param>
 /// <param name="gunCoolingRate">The gun cooling rate for the robots.</param>
 /// <param name="hideEnemyNames">Flag specifying if enemy names are hidden from robots.</param>
 /// <param name="battlefieldSize">The battlefield size.</param>
 /// <param name="robots">The robots participating in this battle.</param>
 public BattleSpecification(int numRounds, long inactivityTime, double gunCoolingRate, bool hideEnemyNames, BattlefieldSpecification battlefieldSize, RobotSpecification[] robots)
 {
     this.numRounds         = numRounds;
     this.inactivityTime    = inactivityTime;
     this.gunCoolingRate    = gunCoolingRate;
     this.hideEnemyNames    = hideEnemyNames;
     this.battlefieldWidth  = battlefieldSize.Width;
     this.battlefieldHeight = battlefieldSize.Height;
     this.robots            = robots;
 }
 /// <summary>
 /// Creates a new BattleSpecification with the given settings.
 /// </summary>
 /// <param name="numRounds">The number of rounds in this battle.</param>
 /// <param name="inactivityTime">The inactivity time allowed for the robots before
 /// they will loose energy.</param>
 /// <param name="gunCoolingRate">The gun cooling rate for the robots.</param>
 /// <param name="sentryBorderSize">The sentry border size for a <see cref="Robocode.IBorderSentry">BorderSentry</see>.</param>
 /// <param name="hideEnemyNames">Flag specifying if enemy names are hidden from robots.</param>
 /// <param name="battlefieldSize">The battlefield size.</param>
 /// <param name="robots">The robots participating in this battle.</param>
 public BattleSpecification(int numRounds, long inactivityTime, double gunCoolingRate, int sentryBorderSize, bool hideEnemyNames, BattlefieldSpecification battlefieldSize, RobotSpecification[] robots)
 {
     this.numRounds = numRounds;
     this.inactivityTime = inactivityTime;
     this.gunCoolingRate = gunCoolingRate;
     this.sentryBorderSize = sentryBorderSize;
     this.hideEnemyNames = hideEnemyNames;
     this.battlefieldWidth = battlefieldSize.Width;
     this.battlefieldHeight = battlefieldSize.Height;
     this.robots = robots;
 }