RRobots is a simulation environment for robots, these robots have a scanner and a gun, can move forward and backwards and are entirely controlled by ruby scripts.
require 'rrobots' class NervousDuck include Robot def tick events turn_radar 1 if time == 0 turn_gun 30 if time < 3 accelerate 1 turn 2 fire 3 unless events['robot_scanned'].empty? end end
All you need to implement is the tick method which should accept a hash of events that occurred during the last tick.
The following methods are available to your bot:
battlefield_height #the height of the battlefield battlefield_width #the width of the battlefield energy #your remaining energy (if this drops below 0 you are dead) gun_heading #the heading of your gun, 0 pointing east, 90 pointing #north, 180 pointing west, 270 pointing south gun_heat #your gun heat, if this is above 0 you can't shoot heading #your robots heading, 0 pointing east, 90 pointing north, #180 pointing west, 270 pointing south size #your robots radius, if x <= size you hit the left wall radar_heading #the heading of your radar, 0 pointing east, #90 pointing north, 180 pointing west, 270 pointing south time #ticks since match start speed #your speed (-8/8) x #your x coordinate, 0...battlefield_width y #your y coordinate, 0...battlefield_height accelerate(param) #accelerate (max speed is 8, max accelerate is 1/-1, #negativ speed means moving backwards) stop #accelerates negativ if moving forward (and vice versa), #may take 8 ticks to stop (and you have to call it every tick) fire(power) #fires a bullet in the direction of your gun, #power is 0.1 - 3, this power will heat your gun turn(degrees) #turns the robot (and the gun and the radar), #max 10 degrees per tick turn_gun(degrees) #turns the gun (and the radar), max 30 degrees per tick turn_radar(degrees) #turns the radar, max 60 degrees per tick dead #true if you are dead say(msg) #shows msg above the robot on screen broadcast(msg) #broadcasts msg to all bots (they receive 'broadcasts' #events with the msg and rough direction)
These methods are intentionally of very basic nature, you are free to unleash the whole power of ruby to create higher level functions. (e.g. move_to, fire_at and so on)
Some words of explanation: The gun is mounted on the body, if you turn the body the gun will follow. In a similar way the radar is mounted on the gun. The radar scans everything it sweeps over in a single tick (100 degrees if you turn your body, gun and radar in the same direction) but will report only the distance of scanned robots, not the angle. If you want more precision you have to turn your radar slower.
Your ‘tick` method will be passed a hash as the argument. The possible keys it can contain are:
* "robot_scanned" - If there is another robot directly in front of your gun, this key will be the distance between you and that robot as a float. Otherwise it's nil. * "broadcast" - If another robot uses `broadcast`, this will contain the message they send and the rough direction it came from (as a string "north", "east", "west" or "south").
RRobots is implemented in pure ruby using a Gosu ui and should run on all platforms that have ruby and Gosu.
# assuming Mac OS X with homebrew because reasons $ brew install sdl2 $ brew install gosu $ git clone [email protected]:urug/rrobots.git $ cd rrobots $ bundle $ bundle exec rrobots examples/NervousDuck.rb examples/NervousDuck.rb
To start a match call:
Usage: rrobots [options] file1 file2 ... --resolution x,y X and Y resolution --match N Replay match number N --timeout N Maximum number of ticks for a match --teams N Splits robots into N teams --[no-]gui Run the match with the GUI -h, --help Show this message
If you want to run a tournament call:
Usage: tournament [options] file1 file2 ... --resolution x,y X and Y resolution --matches N Number of times each robot fights each other robot N --timeout N Maximum number of ticks for a match --dir N All robots from this directory will be matched against each other -h, --help Show this message
The names of the rb files have to match the class names of the robots.
Each robot is matched against each other 1on1. The results are available as yaml or html files.