So, some potentially exciting news.
I've read a lot about the attempt to implement bots in alternative JVM languages, and I think I've succeeded in doing it for JavaScript, within the following constraints:
1. unmodified Rhino 1.7R3,2. unmodified Robocode,
3. No Robocode plugins,
4. Robocode security enabled
It appears to work but as people run the meleerumble we'll know more. I am running it without obvious incident.Below is the bot's source code, which is based on the MyFirstRobot tutorial. It dispenses with the normal Java source files and properties file; it generates those at build time from the JavaScript code.
I implemented the embedding using the SLIME project at http://code.google.com/p/slime/ which provides a framework for embedding Rhino (among other JavaScript engines). The basic approach exposes the appropriate part of the Robocode API to the bot as a series of JavaScript host objects and methods.
It does not allow the use of server-side Java objects and classes directly, which would run headlong into the security manager's prohibition of reflection. So the bot is not directly exposed to the script. And currently the bot must be written entirely in JavaScript. Only the APIs required by MyFirstRobot are supported so far. :)It loads the scripts from the robot's data directory. Since MyFirstRobot is a Robot, and my JavaScript robots extend AdvancedRobot so that they can load their scripts, I implemented my own really simple FiringAssistance, which is actually not very good, but puts the bot approximately on par with MyFirstRobot, with some differences in logic I am still learning to understand.The framework embeds Rhino within the robot itself, so there is an entire JavaScript interpreter bundled with the bot, for better or worse. Obviously a piece of low-level code like that can have strange side effects as it interacts with the enclosing runtime, so I wanted to warn you to be on the lookout for it.Here's the bot code; feel free to suggest simple improvements to the firing assistance (I am still learning it).* * *
var turningGun = false;robot.properties = {description: "JavaScript/Rhino/SLIME Proof-of-Concept Robot","java.source.included": false,version: "1.0",
}robot.run = function() {while(true) {ahead(100);if (!turningGun) turnGunRight(360);back(100);if (!turningGun) turnGunRight(360);}};robot.onScannedRobot = function(e) {turningGun = true;var aim = getHeading() + e.bearing;while (aim < 0) aim += 360;while (aim > 360) aim -= 360;turnGunRight(aim - getGunHeading());fire(1);turningGun = false;}
--
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 robocode+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
So, some potentially exciting news.I've read a lot about the attempt to implement bots in alternative JVM languages, and I think I've succeeded in doing it for JavaScript, within the following constraints:1. unmodified Rhino 1.7R3,2. unmodified Robocode,
3. No Robocode plugins,4. Robocode security enabled
Nice!I would like to understand what are security implications.
--
So, some potentially exciting news.
I've read a lot about the attempt to implement bots in alternative JVM languages, and I think I've succeeded in doing it for JavaScript, within the following competition-compatible constraints:
1. unmodified Rhino 1.7R3,2. unmodified Robocode,
3. No Robocode plugins,
4. No classpath changes (Rhino included in bot),
5. Robocode security enabled
It appears to work but as people run the meleerumble we'll know more. I am running it without obvious incident.Below is the bot's source code, which is based on the MyFirstRobot tutorial. It dispenses with the normal Java source files and properties file; it generates those at build time from the JavaScript code.
I implemented the embedding using the SLIME project at http://code.google.com/p/slime/ which provides a framework for embedding Rhino (among other JavaScript engines). The basic approach exposes the appropriate part of the Robocode API to the bot as a series of JavaScript host objects and functions.
It does not allow the use of server-side Java objects and classes directly, which would run headlong into the security manager's prohibition of reflection. So the bot is not directly exposed to the script. And currently the bot must be written entirely in JavaScript. Only the APIs required by MyFirstRobot are supported so far. :)It loads the scripts from the robot's data directory. Since MyFirstRobot is a Robot, and my JavaScript robots extend AdvancedRobot so that they can load their scripts, I implemented my own really simple FiringAssistance, which is actually not very good, but puts the bot approximately on par with MyFirstRobot, with some differences in logic I am still learning to understand.The framework embeds Rhino within the robot itself, so there is an entire JavaScript interpreter bundled with the bot, for better or worse. Obviously a piece of low-level code like that can have strange side effects as it interacts with the enclosing runtime, so I wanted to warn you to be on the lookout for it.Here's the bot code; feel free to suggest simple improvements to the firing assistance (I am still learning it).* * *
var turningGun = false;robot.properties = {description: "JavaScript/Rhino/SLIME Proof-of-Concept Robot","java.source.included": false,version: "1.0",
"author.name": "David P. Caldwell <da...@look.in.source.code>"
}robot.run = function() {while(true) {ahead(100);if (!turningGun) turnGunRight(360);back(100);if (!turningGun) turnGunRight(360);}};robot.onScannedRobot = function(e) {turningGun = true;var aim = getHeading() + e.bearing;while (aim < 0) aim += 360;while (aim > 360) aim -= 360;turnGunRight(aim - getGunHeading());fire(1);turningGun = false;}
Hi David,
Do you know if Slime could be used for exposing the complete Robot API for Robocode?
Perhaps Robocode needs to be modified to support JavaScript even better? :-)If so, this is something I will look into for a future version of Robocode. :-)
Isn't the JAR name, including the version number, part of the path of
the data directory after bots are extracted from JARs? I remember it
used to be something like
robocode/robots/.data/voidious.Diamond_1.8.22_/voidious would have
Diamond.class, Diamond.data in it. If multiple versions of the same
bot are sharing data dirs now, that would be a surprise to me. (Of
course before packaging, they would always go to eg
robocode/robots/voidious/Diamond.data.)