Build the best - destroy the rest!

Monday 22 February 2010

Get started with Robocode for .NET robots

The biggest news for Robocode in a long time is the support for .NET robots.
So if you want to get started with .NET programming in a fun way, here is your chance to try it out and challenge your skills.

Get started by reading our two tutorials for .NET robots here:These two tutorials contains everything needed to get started with programming .NET robots for Robocode.

If you are already familiar with programming Robocode robots in Java, you might be interested in extending your skills into .NET as well. You can read about the differences between .NET and Java robots here.

Download Robocode 1.7.2.0 Beta from here
Download Robocode .NET plugin 1.7.2.0 Beta from here

Monday 15 February 2010

Robocode .NET - introduction

Visible Robot differences


between Java and brand new .NET API for Robocode robots.

  • Namespaces start with uppercase Robocode.AdvancedRobot instead of robocode.AdvancedRobot from Java.

  • Methods start with uppercase AdvancedRobot.Execute() instead of AdvancedRobot.execute() from Java.

  • Getter and setter methods are represented by properties BulletHitEvent.VictimEnergy instead of BulletHitEvent.getVictimEnergy() from Java.

  • Droids are marked with Robocode.IDroid interface instead of robocode.Droid from java.

  • Painting robot uses Robocode.IGraphics interface, which is similar to System.Drawing.Graphics.

  • Robocode.Condition could be implemented by delegate, see SampleCs.Target.

  • Interactive robot should use Robocode.Keys constants, see SampleCs.Interactive.

  • team Robot messages should be binary serializable and marked with [Serializable] attribute.

  • .NET robot pays more work to submit each turn into battle (to overcome the interop layer). We will probably adjust CPU time given to robot to keep fair competition. The ratio Java/.NET is for discussion yet.

  • Access to files is done thru AdvancedRobot.GetDataFile() which returns System.IO.Stream

  • there is difference in implementation of floating point between CLR & JVM. The JVM uses strictfp - rounding after each operation, which is more portable. Whereas CLR uses FPU wide registers to achieve better speed and precision. If you recursively recompute same numbers, it will produce a little bit different result. Nothing to worry about.

  • System.Threading.Thread is banned, use Robocode.Thread instead.


About the implementation


Two years ago, when we came with the idea of introducing .NET for Robocode we had no idea what so ever how much work it would require from us. :-O
We had raw idea that the main problem is speed. Robocode version 1.6 and below used shared state in RobotPeer between Battle thread and Robot thread.
Each call on the Robot API was synchronized to one big mutex. Now imagine that each call from a .NET robot will come through interop layer and then through synchronization in Java. Our estimate was that we would need 10.000 calls per second across CLR/transport/JVM boundaries to satisfy all calls which robot does on RobotAPI. That's not very realistic!


After several trials and failures we came to idea that we will make communication between robot and battle chunky rather than chatty. We cache all commands from robot till end of turn (Execute) and then we send it to battle as a message.
The other way around it's the same. At end of turn, the battle produces a message for each robot. The message contains all the information a robot could ever ask for, i.e., all the events, positions - everything. The message is used by robot as cache for all queries on the Robot API.
And that's big success. The Java version of Robocode speedup about 10x in version 1.6.2. This design as well allows for .NET robot to cross the CLR/JVM boundary just once per turn! The messages are serializable to binary form, so the interface between robot and battle could be reused for C++/Delphi/Python/Ruby/Basic/Foxpro :-D robots in the future.


So now, how to connect two virtual machines? Webservice or tcp - slooow, named pipe - slow, COM - yeah maybe, but COM registration, JNI & PIvoke & C++ & in same process - that would be almost it.
In the end as by-product of need for Robocode, I started off new opensource project - jni4net. It's is fast intraprocess bridge, without any native code and it's object oriented. It's generally useful for .NET+Java solutions.


There were challenges about sandboxing the robot in .NET. We use AppDomain, CAS security and static code analysis to prevent you from cheating.


There is plenty of work ahead. I would not name it now, because we would like to hear from you, what you think we should improve?

Enjoy!

Robocode 1.7.2.0 Beta - The ".NET robots are now supported" release

We are proud to announce the 1.7.2.0 Beta release of Robocode, which is the first version to support .NET robots via using a plugin for Robocode. A lot of hard work has been put into the .NET support by Pavel Savara.

With the .NET plugin for Robocode, Java and .NET robots can participate in the same battles in the same time.

You can read our first article on the RoboWiki about
how to create a .NET robot with Visual Studio and run it in Robocode.

If you want to know the differences between the Robot API for Java and the new one for .NET, you should read this article.

We have also added lots of pending features and of course made some changes to Robocode as well.

We encourage everybody to test this Beta version as much as possible and report any bugs found at our Bugs Tracker at SourceForge. Then we will do everything we can to fix issues before the final release of version 1.7.2.0.

Bugfixes


  • Bug [2930266] - Robot static data isn't being GCed after battle.

  • Bug [2931445] - Removing directories from "development options" doesn't work.

  • Bug in RobotClassLoader causing ClassNotFoundException for some robots during robot class load.

  • Fixed a NullPointerException occuring when Robocode is (re)loading the robot repository after a developer path has been removed.

  • Bug [2935451] - Version ordering is somewhat strange with letters.

  • Bug [2930256] - Robot console text sometimes disappears.

  • Bug [2928688] - morbid.MorbidPriest_1.0 fails to load.

New features


  • .NET Robocode plugin. It is now possible to code robots in .NET and let them engage in Robocode battles.

  • Req [2816882] - onRoundEnded(). It is now possible for robots to get notified when a round has ended. The onRoundEnded() event handler received a new RoundEndedEvent that contains information about the number of turns in the round and total turns in the whole battle when the event occurred.

  • The robocode.control.RoundEndedEvent in the Control API has been extended with a new method named getTotalTurns() similar to the new robocode.RoundEndedEvent for the Robot API.

  • Req [2931696] - RateControlRobot vs. TeamRobot. The RateControlRobot is now a TeamRobot meaning that it can participate in team battles.

  • Req [2931684] - Skipped turn events. Added getSkippedTurn() method on the SkippedTurnEvent class, which returns the turn that was skipped. The getTime() returns the time when the SkippedTurnEvent was processed by the robot, which is always later when the robot is skipping turns. The message "SYSTEM: you skipped turn" has been improved, so it will tell which turn that was skipped like "SYSTEM: john.Doh skipped turn 43".

  • Req [2342293] - Screenshot of battleview. Press Ctrl+T on Windows and Linux, and Command+T for Mac OS in order to take a screenshot of the battleview. The screenshot will be saved in the Robocode folder named "screenshots", and the filename will be a timestamp for when the screenshot was taken.

  • Req [2496661] - Launch Robocode from .battle (battle specification) and .br (battle record) files.

  • Req [2659612] - Add option to prevent speedup when minimized. This new View Option can now be set in the Preferences by putting a check mark into "Prevent speedup when minimized".

  • Req [2643438] - Renamed /robots/.robotcache to /robots/.data

Changes


  • Browser support has been improved for Mac OS, Unix and Linux, which in most cases did not work properly.

    • In previous versions of Robocode, the browser.sh was used to start up the user's prefered browser. The browser.sh file is not being used anymore. Hence, this file can safely be removed from your robocode installation dir.

    • Now, Robocode will start up a browser under Mac OS, Unix and Linux with no use of scripts.

  • The Development Options dialog in the Preferences has been improved:

    • Changed from using single interval selection to multi selection interval.

    • Adding an existing path is ignored.

    • The list of path is automatically sorted.


Download Robocode 1.7.2.0 Beta from here
Download Robocode .NET plugin 1.7.2.0 Beta from here