back to main

JS Robots

What is it?

It's a JavaScript reimagining of Tom Poindexter's seminal CROBOTS game. You program a script to control a robot and then put your robot up to fight against other CPU or human controlled robots each with various scripts!

Main differences between JS Robots and original CROBOTS

Overview:

  1. Arena size
  2. Coordinate system
  3. Compass system
  4. Simple Boolean detection of "in explosion or not"
  5. Uses floats internally (heading, speed, scan and damage are integer)
  6. No virtual machine proper (ie. loops are out of the question!)

Details:

  1. The arena is a square of 500 units by 500 units
  2. The top-left of the arena is (0,0). The bottom-right is (499,499).
  3. The compass system is oriented so that due north (up) is 0 degrees, 90 is east, 180 is south, 270 is west. One degree west (left) of due north is 359.
    	                         315    0    45
    	                             \  |  /
    	                              \ | /
    	                        270 --- x --- 90
    	                              / | \
    	                             /  |  \
    	                         225   180   135
    	
  4. There is no reduced damage for being further away from the centre of an explosion. Rather it is 10 points damage if you are anywhere in the explosion.

Basic instructions

Robot script API

Per robot methods

Need to prefix these with this.

Utility functions

Damage table

Damage accumulates thusly:

CaseDamage
Hit wall2 (and speed down to zero)
Hit other robot2 each (and speed down to zero)
Caught in explosion10

Usage notes

To remember things between iterations, save it to a member variable thusly: this.somethingToRemember = whatever();

Robot object methods are documented (above) and internal housekeeping methods / members are prefixed with a '_' [underscore]. Avoid these names in your scripts and you will be fine.

In your robot script, any and all JavaScript functions / objects / methods are available. The static methods of the Math object might be especially useful. Take a look at the JavaScript guide on DevGuru. Be sure you don't, for example, alert() anything out though because it will end in tears!

You can define a reusable method for your robot thusly:
//Define this.reusableMethod = function(speed) { this.whatever = something(); this.drive(90, speed); }; this.scan(this.scanAngle, 5); //Other stuff here //Use this.reusableMethod(100);
A semicolon after the method definition is required.

Bugs

There's a pretty irritating bug which we call the quick getaway bug. Basically, if your robot's speed is zero due to colliding with another robot, then you need to drive() away as soon as possible in the code rather than waiting for the next iteration. See the presets for examples.

Possibly related to the above, there's also the jitterbug bug. A robot will occasionally jitter back and forth when in front of a wall or other robot.

Another irritating bug is that starting the game again after a stop or game win isn't perfect unfortunately. Best to reload the URL [fixed!]

Release history

VersionDateNotes
1.0gh9 November 2011First GitHub open source version. As live JS Robots but packaged to run locally from File --> Open in the browser (ie. no backend technologies and no sending scores to Twitter)

Licence

This JS Robots software source code is released under the terms of the BSD "New BSD License". Please see the LICENCE text file in the root folder of the source code.

v1.0ghCopyright © 2009 ~ 2011 Warp Asylum Ltd (UK)