Skip to content
LiveScript (JavaScript) implementation of robocode, original from http://gumuz.nl/projects/robojs/
LiveScript
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
img
robot
.gitignore
LICENSE
Makefile
README.md
base-robot.ls
battle.ls
index.html
log.ls
package.json
stage0.html
stage1.html
stage2.html
stage3.html

README.md

robocode-js

LiveScript (Javascript) implementation of Robocode. Original from http://gumuz.nl/projects/robojs/

Creating a robot is even simpler

importScripts('base-robot.js')

class TestRobot1 extends BaseRobot
  onIdle: ->
    @turn_turret_left 30
    @move_forwards 100
      if Math.random! > 0.5
        @turn_right 30
      else
        @turn_left 30

  onWallCollide: ->
    @move_opposide 10
    @turn_left 90

  onEnemySpot: ->
    @shoot!

  onHit: ->
    for d from 20 to 30
      @move_backwards d
      @turn_right d

bot = new TestRobot1("My test robot")

Advanced:

  onEnemySpot: ->
    @my-var = @enemy-spot # remember it
    @shoot!

TODO: need more bot actions and callback events

Robot HOWTO

Available info:

  • Self info

    • @me.id
    • @me.x
    • @me.y
    • @me.hp
    • @me.angle - Your current angle (tank angle + turret angle)
    • @me.tank_angle
    • @me.turret_angle
  • Enemy info

    • @enemy-spot[N].id
    • @enemy-spot[N].hp
    • @enemy-spot[N].angle - The angle (direction) to the enemy

Sequential Actions:

  • @turn_left (angle)
  • @turn_right (angle)
  • @move_forwards (distance)
  • @move_backwards (distance)
  • @move_opposide (distance) - This action can only be used in OnWallCollide()

Parallel Actions:

  • @turn_turret_left (angle)
  • @turn_turret_right (angle)
  • @shoot()
  • @yell(message)

Events:

  • OnIdle() - Triggered when idle (MUST implement)
  • OnWallCollide() - When the tank collide the wall
  • OnHit() - When hit by a bullet
  • OnEnemySpot() - When your turret is directly face to an enemy (there seems no reason not to fire!)

Build from LiveScript

  • To compile from LiveScript, first, install nodejs from http://nodejs.org/
  • Second, make sure you got npm and run command exetable on your console. (If you are on MS Windows, make sure the PATH environment variable is setting correct to run npm and node)
  • If you have make command, i.e. on Linux or Mac OSX, just go to the repository root directory and type make, everything will be done.
  • If you do not have make command, run the following command manually. (haven't test on MS Windows.)
    • npm install
    • node_modules/.bin/lsc -c *.ls
    • node_modules/.bin/lsc -c -b log.ls
    • node_modules/.bin/lsc -c robot/*.ls
  • Done. Use your browser to open index.html file.

Run directly without compiling anything

  • switch to gh-pages branch, you will got everything to run this program.

    git checkout gh-pages

Note

  • google-chrome is not allow to run a web worker of a local javascript file. Please use the --allow-file-access-from-files option to start chrome. If you run this project on a web server, this won't be a problem.

Licensing

  • Source Codes: MIT
  • ARTs: Eclipse Public License (EPL).
  • Read LICENSE file for detail

Credits

  • Thanks Guyon at Gumuz for this great project.
  • Thanks to Martain Chen, Tim Chen, BinBin Tasi, Sid Wang, Louh Ren-Shan and 豬大寶 for mathematic support.
You can’t perform that action at this time.