[ANN] RRobots - ducks, armed and dangerous

S

Simon Kröger

RRobots v0.1

First there was CRobots, followed by PRobots and many others,
recently (well also years ago) Robocode emerged and finally
this is RRobots bringing all the fun to the ruby community.

What is he talking about?

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. All robots are equal (well at the moment,
maybe this will change) except for the ai.

A simple robot script may look like this:
----------------------- code -----------------------
require 'robot'

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
----------------------- code -----------------------

all you need to implement is the tick method which should
accept a hash of events occured turing the last tick.

By including Robot you get all this methods to controll 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
velocity #your velocity (-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

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 simmilar 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 precission you have to turn your radar slower.

RRobots is implemented in pure ruby using a tk ui and should run on all
platforms that have ruby and tk. (until now it's tested on windows only)

To start a match call e.g.

ruby rrobots.rb SittingDuck NervousDuck

the classes have to be defined in files with the same name.
(SittingDuck.rb and NervousDuck.rb for the example above)

You can download the 0.1 release from rubyforge:

http://rubyforge.org/frs/?group_id=1109

The best way to help and keep me motivated would be to post some cool
bots here (along with the bug-reports and feature requests)

cheers

Simon

(and thanks to the robocode project for the nice graphics)
 
E

Edwin van Leeuwen

SimonKroeger said:
(along with the bug-reports and feature requests)

Just tried it out, and here is the first bug report. You use \\ for the
images dir, this doesn't work on unix based platforms (all except
windows?). If you replace these with / it should work on all platforms
(including windows).

After replacing these it worked fine though, and great graphics :) I
might start building some robots :)

Edwin
 
S

Simon Kröger

Edwin said:
Just tried it out, and here is the first bug report. You use \\ for the
images dir, this doesn't work on unix based platforms (all except
windows?). If you replace these with / it should work on all platforms
(including windows).

After replacing these it worked fine though, and great graphics :) I
might start building some robots :)

Edwin

Doh!

Lazy me.

v0.1.1 is ready for download.
(and hopefully realy platform independent)

cheers

Simon
 
G

Gyoung-Yoon Noh

RRobots v0.1

First there was CRobots, followed by PRobots and many others,
recently (well also years ago) Robocode emerged and finally
this is RRobots bringing all the fun to the ruby community.

What is he talking about?

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. All robots are equal (well at the moment,
maybe this will change) except for the ai.

A simple robot script may look like this:
----------------------- code -----------------------
require 'robot'

class NervousDuck
include Robot

def tick events
turn_radar 1 if time =3D=3D 0
turn_gun 30 if time < 3
accelerate 1
turn 2
fire 3 unless events['robot_scanned'].empty?
end
end
----------------------- code -----------------------

all you need to implement is the tick method which should
accept a hash of events occured turing the last tick.

By including Robot you get all this methods to controll 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 <=3D 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
velocity #your velocity (-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

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 simmilar 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 precission you have to turn your radar slower.

RRobots is implemented in pure ruby using a tk ui and should run on all
platforms that have ruby and tk. (until now it's tested on windows only)

To start a match call e.g.

ruby rrobots.rb SittingDuck NervousDuck

the classes have to be defined in files with the same name.
(SittingDuck.rb and NervousDuck.rb for the example above)

You can download the 0.1 release from rubyforge:

http://rubyforge.org/frs/?group_id=3D1109

The best way to help and keep me motivated would be to post some cool
bots here (along with the bug-reports and feature requests)

cheers

Simon

(and thanks to the robocode project for the nice graphics)

Really great work!

It runs on my Linux desktop very well by only modifying image path. :)
However, ruby can handle unix style path separator(/) on other platforms,
(If I am wrong, correct me.) though 'File.join' will be better for that use=
 
H

Harold Hausman

You get a gold star on the chart for the day!

Today we can all be thankful for rrobots.rb.

Here's the listing of my first bot, affectionately titled BotOne. He
lays a savage beat down on the aptly named NervousBot, but he is by no
means invincible.

#Begin listing

require 'robot'

class BotOne
=09include Robot
=09def tick events
=09=09@rapid_fire =3D 0 if @rapid_fire.nil?
=09=09@last_seen =3D 0 if @last_seen.nil?
=09=09@turn_speed =3D 3 if @turn_speed.nil?
=09=09
=09=09if time - @last_seen > 200
=09=09=09@turn_speed *=3D -1
=09=09=09@last_seen =3D time
=09=09end
=09=09
=09=09turn @turn_speed
=09=09
=09=09if( @rapid_fire > 0 )
=09=09=09fire 0.84
=09=09=09turn_gun -(@turn_speed / @turn_speed) *2
=09=09=09@rapid_fire =3D @rapid_fire - 1
=09=09else
=09=09=09turn_gun @turn_speed * 1.25
=09=09end

=09=09if( !events['robot_scanned'].empty? )
=09=09=09@turn_speed *=3D -1
=09=09=09@last_seen =3D time
=09=09=09@rapid_fire =3D 20
=09=09end
=09=09@last_hit =3D time unless events['got_hit'].empty?
=09=09if @last_hit && time - @last_hit < 20
=09=09=09accelerate(-1)
=09=09else
=09=09=09accelerate 1
=09=09end
=09end
end

#End listing

This bot prefers long matches, as he fires low power shots. This, on
my machine at least exposes some performance problems associated with
shooting a lot. Matching a couple of rapid firing bots brings the app
to it's knees after only a few thousand ticks. My first idea where
maybe that the bullets were not being cleaned up properly, but looking
at the source it looks like they are being remove from the hash and
canvas, so I don't know.

Barring that though, this is brilliant!

One thousand thanks,
-Harold
 
R

Reinder Verlinde

Simon Kröger said:
The best way to help and keep me motivated would be to post some cool
bots here (along with the bug-reports and feature requests)

It looks cool. Now only if I could find time to write a bot or series of
bots...

Here is a tiny bug report/feature request. The first I did was:

ruby rrobots.rb SittingDuck.rb NervousDuck.rb

result:

Error loading SittingDuck.rb!
usage: rrobots.rb <FirstRobotClassName> <SecondRobotClassName>
the names of the rb files have to match the class names of
the robots e.g. 'ruby rrobots.rb SittingDuck NervousDuck'

This is easily corrected, but I think the code c/should be smart enough
to notice that the '.rb' extensions already are there (with tab
completion, typing the '.rb' is easier than not typing it)

I also have the first security breach to report. I do not think you
intend that the following should be valid inside a robot:

@battlefield.robots.each do |other|
puts "robot #{other}: x #{other.x}, y #{other.y}"
end

If a robot can do that, the radar seems extremely limited.

Reinder
 
S

Simon Kröger

Harold said:
You get a gold star on the chart for the day!

Today we can all be thankful for rrobots.rb.
Here's the listing of my first bot, affectionately titled BotOne. He
lays a savage beat down on the aptly named NervousBot, but he is by no
means invincible.

to cool.
#Begin listing
[...]
#End listing

This bot prefers long matches, as he fires low power shots. This, on
my machine at least exposes some performance problems associated with
shooting a lot. Matching a couple of rapid firing bots brings the app
to it's knees after only a few thousand ticks. My first idea where
maybe that the bullets were not being cleaned up properly, but looking
at the source it looks like they are being remove from the hash and
canvas, so I don't know.

I will dive into that (i was able to finish the match, but it slows
down considerably) maybe i have to 'reuse' old bullets.
Barring that though, this is brilliant!

One thousand thanks,
-Harold

I'm realy glad to see someone enjoys this little game.

cheers

Simon
 
S

Simon Kröger

Reinder said:
=20
=20
=20
=20
It looks cool. Now only if I could find time to write a bot or series o= f=20
bots...

Would make me happy too :)
Here is a tiny bug report/feature request. The first I did was:
=20
ruby rrobots.rb SittingDuck.rb NervousDuck.rb
=20
result:
=20
Error loading SittingDuck.rb!
usage: rrobots.rb <FirstRobotClassName> <SecondRobotClassName>
the names of the rb files have to match the class names of
the robots e.g. 'ruby rrobots.rb SittingDuck NervousDuck'
=20
This is easily corrected, but I think the code c/should be smart enough= =20
to notice that the '.rb' extensions already are there (with tab=20
completion, typing the '.rb' is easier than not typing it)

Ok, will be in the next release.
I also have the first security breach to report. I do not think you=20
intend that the following should be valid inside a robot:
=20
@battlefield.robots.each do |other|
puts "robot #{other}: x #{other.x}, y #{other.y}"
end
=20
If a robot can do that, the radar seems extremely limited.

Robots are distributed as source code (i don't see another way anyway)
so nobody would want to compete against such a bot.
(You can search ObjectSpace and find the other robot, setting his energy
to -1, easy victory but without honour)
Maybe there is a way to protect against such strategies i didn't thought
of, any ideas?

cheers

Simon
 
E

Edwin van Leeuwen

hhausman said:
You get a gold star on the chart for the day!

Today we can all be thankful for rrobots.rb.

Here's the listing of my first bot, affectionately titled BotOne. He
lays a savage beat down on the aptly named NervousBot, but he is by no
means invincible.

After quite a bit of tweaking I'm also ready to release my aptly named
HuntingDuck. It will try to move closer to it's prey (while shooting it
ofcourse).

It seems to be about even with BotOne, but I as its creator might be
overproud :)

class HuntingDuck
include Robot
def initialize bf
super(bf)
@time_since=10
@direction=1
end
def rel_direction(from,to)
rel = to -from
if rel > 180
rel = -360 + rel
end
if rel < -180
rel = 360+rel
end
return rel
end
def rel_gun_heading
rel_direction(heading, gun_heading)
end
def tick events
accelerate 1
@direction = -@direction if Kernel.rand < 0.02
if !events['got_hit'].empty?
fire 2
turn -10*@direction
end
if !events['robot_scanned'].empty?
fire 3
@time_since=0
else
if @time_since < 15
if Kernel.rand < 0.5 && rel_gun_heading < 30
turn_gun 6
elsif rel_gun_heading > -30
turn_gun -6
else
turn_gun 6
end
fire 0.5
elsif @time_since < 100
turn 10*@direction
else
turn 5
end
end
@time_since += 1
end
end
 
L

Lyndon Samson

------=_Part_5671_7327024.1132869736807
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On
so nobody would want to compete against such a bot.
(You can search ObjectSpace and find the other robot, setting his energy
to -1, easy victory but without honour)
Maybe there is a way to protect against such strategies i didn't thought
of, any ideas?



Judicious use of freeze?

------=_Part_5671_7327024.1132869736807--
 
D

Dave Burt

Reinder said:
It looks cool. Now only if I could find time to write a bot or series of
bots...

Would make me happy too :)
Here is a tiny bug report/feature request. The first I did was:

ruby rrobots.rb SittingDuck.rb NervousDuck.rb

result:

Error loading SittingDuck.rb!
usage: rrobots.rb <FirstRobotClassName> <SecondRobotClassName>
the names of the rb files have to match the class names of
the robots e.g. 'ruby rrobots.rb SittingDuck NervousDuck'

This is easily corrected, but I think the code c/should be smart enough to
notice that the '.rb' extensions already are there (with tab completion,
typing the '.rb' is easier than not typing it)

Ok, will be in the next release.
I also have the first security breach to report. I do not think you intend
that the following should be valid inside a robot:

@battlefield.robots.each do |other|
puts "robot #{other}: x #{other.x}, y #{other.y}"
end

If a robot can do that, the radar seems extremely limited.

Robots are distributed as source code (i don't see another way anyway)
so nobody would want to compete against such a bot.
(You can search ObjectSpace and find the other robot, setting his energy
to -1, easy victory but without honour)
Maybe there is a way to protect against such strategies i didn't thought
of, any ideas?

cheers

Simon
 
D

Dave Burt

(Sorry for the blank post)
Robots are distributed as source code (i don't see another way anyway)
so nobody would want to compete against such a bot.
(You can search ObjectSpace and find the other robot, setting his energy
to -1, easy victory but without honour)
Maybe there is a way to protect against such strategies i didn't thought
of, any ideas?

$SAFE can stop this kind of thing. Run a thread for each robot, taint stuff
you don't want it to be able to mess with (e.g. the thread), untaint the
robot's code, and eval and run it under $SAFE=4.

Cheers,
Dave
 
M

Mickael Faivre-Macon

After quite a bit of tweaking I'm also ready to release my aptly named
HuntingDuck. It will try to move closer to it's prey (while shooting it
ofcourse).

It seems to be about even with BotOne, but I as its creator might be
overproud :)

Against SittingDuck, it performed very badly :)
 
J

James Edward Gray II

Robots are distributed as source code (i don't see another way anyway)
so nobody would want to compete against such a bot.
(You can search ObjectSpace and find the other robot, setting his =20
energy
to -1, easy victory but without honour)
Maybe there is a way to protect against such strategies i didn't =20
thought
of, any ideas?

Sure, move the communication to a client server architecture so you =20
can control this better. You've got to stop them running in the same =20=

process, to make it easier on yourself.

James Edward Gray II=
 
G

Gavin Kistner

velocity #your velocity (-8/8)

Minor nitpick - as a scalar, this should really be called "speed". =20
Velocity indicates a magnitude and direction (a vector), while speed =20
is a pure rate measurement.=
 
D

Dave Burt

JEGII:
Sure, move the communication to a client server architecture so you can
control this better. You've got to stop them running in the same
process, to make it easier on yourself.

Yes, that's the better way - easier than $SAFE.

Cheers,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top