Forum: Ruby RRobots - ducks, armed and dangerous

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A9c4658e9e475e13d790ae419acf01b6?d=identicon&s=25 SimonKroeger (Guest)
on 2005-11-24 14:08
(Received via mailing list)
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)
0b561a629b87f0bbf71b45ee5a48febb?d=identicon&s=25 dave (Guest)
on 2005-11-24 14:33
(Received via mailing list)
Simon announced:
> RRobots v0.1
> ...
> RRobots is a simulation environment for robots...

Looks great, Simon - I can't wait to try it out!

Cheers,
Dave
784481e009179262d133db1f1eb3bfb1?d=identicon&s=25 Edwin Van leeuwen (blackedder)
on 2005-11-24 14:49
SimonKroeger wrote:
>(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
467c7c87ad5b36859a7644b9198b490a?d=identicon&s=25 leslie (Guest)
on 2005-11-24 15:01
(Received via mailing list)
Great work!
A9c4658e9e475e13d790ae419acf01b6?d=identicon&s=25 SimonKroeger (Guest)
on 2005-11-24 15:05
(Received via mailing list)
Edwin van Leeuwen wrote:

> 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
733436f59b64e31c1dd78fc0d29f3cdb?d=identicon&s=25 nohmad (Guest)
on 2005-11-24 15:25
(Received via mailing list)
On 11/24/05, Simon Kröger <SimonKroeger@gmx.de> wrote:
> controlled by ruby scripts. All robots are equal (well at the moment,
>      turn_radar 1 if time == 0
>
>    heading             #your robots heading, 0 pointing east, 90 pointing
>    accelerate(param)   #accelerate (max speed is 8,
>                        #per tick
> degrees if you turn your body, gun and radar in the same direction) but
> the classes have to be defined in files with the same name.
>
> 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.

--- rrobots.rb.orig     2005-11-24 23:14:55.000000000 +0900
+++ rrobots.rb  2005-11-24 23:15:20.000000000 +0900
@@ -136,15 +136,15 @@
 %w{red green}.each do |color|
        bodies, guns, radars = [], [], []
        36.times do |i|
-               bodies << TkPhotoImage.new(:file =>
"images\\#{color}_body#{(i*10).to_s.rjust(3, '0')}.gif")
-               guns << TkPhotoImage.new(:file =>
"images\\#{color}_turret#{(i*10).to_s.rjust(3, '0')}.gif")
-               radars << TkPhotoImage.new(:file =>
"images\\#{color}_radar#{(i*10).to_s.rjust(3, '0')}.gif")
+               bodies << TkPhotoImage.new(:file =>
"images/#{color}_body#{(i*10).to_s.rjust(3, '0')}.gif")
+               guns << TkPhotoImage.new(:file =>
"images/#{color}_turret#{(i*10).to_s.rjust(3, '0')}.gif")
+               radars << TkPhotoImage.new(:file =>
"images/#{color}_radar#{(i*10).to_s.rjust(3, '0')}.gif")
        end
        colors << TkRobot.new(bodies << bodies[0], guns << guns[0],
radars << radars[0])
 end

 bum = (0..14).map do |i|
-  TkPhotoImage.new(:file => "images\\explosion#{i.to_s.rjust(2,
'0')}.gif")
+  TkPhotoImage.new(:file => "images/explosion#{i.to_s.rjust(2,
'0')}.gif")
 end

 robots, bullets, explosions = {}, {}, {}
@@ -177,4 +177,4 @@
   end
 }).start

-Tk.mainloop
\ No newline at end of file
+Tk.mainloop
733436f59b64e31c1dd78fc0d29f3cdb?d=identicon&s=25 nohmad (Guest)
on 2005-11-24 15:38
(Received via mailing list)
On 11/24/05, Simon Kröger <SimonKroeger@gmx.de> wrote:
>
> v0.1.1 is ready for download.
> (and hopefully realy platform independent)
>

My screenshot:
http://static.flickr.com/26/66471832_4ceaf3b81b_o.png
A9c4658e9e475e13d790ae419acf01b6?d=identicon&s=25 SimonKroeger (Guest)
on 2005-11-24 15:50
(Received via mailing list)
Gyoung-Yoon Noh wrote:

> --
> http://nohmad.sub-port.net

Hehe, nice!

and thanks for the feedback.

Simon
7f891fbe8e3bae7f9fe375407ce90d9d?d=identicon&s=25 hhausman (Guest)
on 2005-11-24 20:48
(Received via mailing list)
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
	include Robot
	def tick events
		@rapid_fire = 0 if @rapid_fire.nil?
		@last_seen = 0 if @last_seen.nil?
		@turn_speed  = 3 if @turn_speed.nil?

		if time - @last_seen > 200
			@turn_speed *= -1
			@last_seen = time
		end

		turn @turn_speed

		if( @rapid_fire > 0 )
			fire 0.84
			turn_gun -(@turn_speed / @turn_speed) *2
			@rapid_fire = @rapid_fire - 1
		else
			turn_gun @turn_speed * 1.25
		end

		if( !events['robot_scanned'].empty? )
			@turn_speed *= -1
			@last_seen = time
			@rapid_fire = 20
		end
		@last_hit = time unless events['got_hit'].empty?
		if @last_hit && time - @last_hit < 20
			accelerate(-1)
		else
			accelerate 1
		end
	end
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
33eda546f35b0667856505f21f940529?d=identicon&s=25 reinder (Guest)
on 2005-11-24 20:56
(Received via mailing list)
In article <4385BB50.5000408@gmx.de>,
 Simon Kröger <SimonKroeger@gmx.de> wrote:

> 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
A9c4658e9e475e13d790ae419acf01b6?d=identicon&s=25 SimonKroeger (Guest)
on 2005-11-24 21:45
(Received via mailing list)
Harold Hausman wrote:
> 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.

> 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
A9c4658e9e475e13d790ae419acf01b6?d=identicon&s=25 SimonKroeger (Guest)
on 2005-11-24 21:53
(Received via mailing list)
Reinder Verlinde wrote:

> In article <4385BB50.5000408@gmx.de>,
>  Simon Kröger <SimonKroeger@gmx.de> wrote:
>
>
>>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...

Would make me happy too :)

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

> Reinder

cheers

Simon
784481e009179262d133db1f1eb3bfb1?d=identicon&s=25 Edwin Van leeuwen (blackedder)
on 2005-11-24 22:51
hhausman wrote:
> 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
2dc2228d8db84b46bdd834b0515a26a1?d=identicon&s=25 lyndon.samson (Guest)
on 2005-11-24 23:06
(Received via mailing list)
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?
0b561a629b87f0bbf71b45ee5a48febb?d=identicon&s=25 dave (Guest)
on 2005-11-25 01:59
(Received via mailing list)
"Simon Kröger" <SimonKroeger@gmx.de> wrote in message
news:43862881.10605@gmx.de...
Reinder Verlinde wrote:

> In article <4385BB50.5000408@gmx.de>,
>  Simon Kröger <SimonKroeger@gmx.de> wrote:
>
>
>>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...

Would make me happy too :)

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

> Reinder

cheers

Simon
0b561a629b87f0bbf71b45ee5a48febb?d=identicon&s=25 dave (Guest)
on 2005-11-25 02:15
(Received via mailing list)
(Sorry for the blank post)

Simon Kröger wrote:
> 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
2f6686bd2c6bb633a1cbf7b5a73c8491?d=identicon&s=25 Mickael Faivre-Macon (micktaiwan)
on 2005-11-25 02:47
(Received via mailing list)
> 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 :)
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2005-11-25 02:51
(Received via mailing list)
On Nov 24, 2005, at 2:51 PM, Simon Kröger wrote:

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

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.

James Edward Gray II
Ec9233451f7c6ba37a83388b87a1f565?d=identicon&s=25 gavin (Guest)
on 2005-11-25 05:08
(Received via mailing list)
On Nov 24, 2005, at 8:05 AM, Simon Kröger wrote:
>   velocity            #your velocity (-8/8)

Minor nitpick - as a scalar, this should really be called "speed".
Velocity indicates a magnitude and direction (a vector), while speed
is a pure rate measurement.
0b561a629b87f0bbf71b45ee5a48febb?d=identicon&s=25 dave (Guest)
on 2005-11-25 05:24
(Received via mailing list)
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
7f891fbe8e3bae7f9fe375407ce90d9d?d=identicon&s=25 hhausman (Guest)
on 2005-11-25 05:28
(Received via mailing list)
On 11/24/05, Simon Kröger <SimonKroeger@gmx.de> wrote:
> Harold Hausman wrote:
> > 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.

no, you're too cool. ;)

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

I've seen some code for circular lists (Gavin K?) that might be a more
efficient way to manage @battlefield.bullets than a hash,  but as far
as optimizing the TK stuff, I haven't the foggiest. I'm super
interested in this game improving though, thanks again for taking the
lead on this, that thread went on too long for *someone* not to put
the rubber to the road.

Keep up the good work,
-Harold
Cd63f8e74588c4c149231d24f1c31256?d=identicon&s=25 flecktone (Guest)
on 2005-11-25 10:55
(Received via mailing list)
On 11/24/05, Simon Kröger <SimonKroeger@gmx.de> wrote:
> v0.1.1 is ready for download.

Hi,

I added a little status display in the canvas so each robot's health
is shown - easier to have it all in one window rather than having the
health in the terminal window.

Diff attached, against 0.1.1
C61aed46b48311ca90c2d4e9a3b10757?d=identicon&s=25 jannis (Guest)
on 2005-11-25 13:57
(Received via mailing list)
Hi,

I converted a new explosion animation based on the robocode one but
with alpha dithering.

http://www.harderweb.de/jix/ml/exppack.zip
A9c4658e9e475e13d790ae419acf01b6?d=identicon&s=25 SimonKroeger (Guest)
on 2005-11-25 15:38
(Received via mailing list)
Jannis Harder wrote:

> Hi,
>
> I converted a new explosion animation based on the robocode one but
> with alpha dithering.
>
> http://www.harderweb.de/jix/ml/exppack.zip
>
> --
> Jannis

Hehe, nice!

i like it.

cheers

Simon
784481e009179262d133db1f1eb3bfb1?d=identicon&s=25 Edwin Van leeuwen (blackedder)
on 2005-11-25 15:42
micktaiwan wrote:
>> 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 :)

Yeah SittingDuck is a though one, it seems only NervousDuck is really
good against sittingDuck.

Another nice feature to add would be a benchmark method. You let two
bots fight 50 times without any screen output, and publish the results.
Nicest would even be to have the output of one of the ongoing fights on
screen (to keep you from getting bored) while in the background it's
running the other matches.
A9c4658e9e475e13d790ae419acf01b6?d=identicon&s=25 SimonKroeger (Guest)
on 2005-11-25 16:26
(Received via mailing list)
Terje Tjervaag wrote:

>
> Diff attached, against 0.1.1
>
> --
> Terje

Thanks,

patch accepted (with minor tweak)

cheers

Simon
Ec9233451f7c6ba37a83388b87a1f565?d=identicon&s=25 gavin (Guest)
on 2005-11-25 16:34
(Received via mailing list)
Feature request: support an arbitrary number of bots on the field,
instead of 2. Most of the time bots will probably be designed for 1-1
battles, but it would be cool to see how tactics differ as you add more
enemies to the field.

Ooh, and then perhaps the concept of same-team bots (radar would show
the bot as 'friendly') so you could have multiple instances of two bots
on the field.
A9c4658e9e475e13d790ae419acf01b6?d=identicon&s=25 SimonKroeger (Guest)
on 2005-11-25 17:11
(Received via mailing list)
> [...]
 > 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 hope i got it. Would you download v0.1.2 and try it?

cheers

Simon
7f891fbe8e3bae7f9fe375407ce90d9d?d=identicon&s=25 hhausman (Guest)
on 2005-11-25 17:19
(Received via mailing list)
Just downloaded it. It's killer... Absolutely rockin'

No excuses now, lets see some bots (:

here's a quasi interesting bot, doesn't display the modicum of
intelligence that the BotOne does, but still wins a fair ammount.
Behold, CheeseBot:

#Begin Listing

require 'robot'

class CheeseBot
	include Robot
	def tick events
		@stage = 1 if @stage.nil?
		@direction = -1 if @direction.nil?
		fire 1
		case @stage
			when 1
				accelerate @direction
				if( heading < 90 )
					turn 90 - heading
				elsif( heading > 90 )
					turn heading - 90
				else
					@stage = 2
				end
			when 2
				accelerate @direction
				if y > @battlefield.height - (size*2)
					@stage = 3
					@temp_time = time
				end
			when 3
				accelerate @direction
				if( (@temp_time + 9) >= time )
					turn 10
					turn_gun -10
				else
					@stage = 4
				end
			when 4
				accelerate @direction
				if( (time > @temp_time+30) && (x > (@battlefield.width - (size*2))
|| x < (size*2)) )
					@direction *= -1
					@temp_time = time
				end
		end
	end
end

#End Listing
#Beware the word wrap. heh

Thanks again and long live rrobots.rb,
-Harold
A47f52ca49a1db1ab137d60d962574b8?d=identicon&s=25 ces.fci (Guest)
on 2005-11-25 20:17
(Received via mailing list)
Another robot to play with...

require 'robot'
class Testing
    include Robot
    def initialize bf
        super(bf)
        @saw_robot = false
    end
    def tick events
        accelerate 1
        if @saw_robot
            direction = time%2==0 ? -1 : 1
            turn_gun 20*direction
            turn 1*direction
            @saw_robot = false
        else
            turn_gun 10
            turn 2
        end
        if !events['robot_scanned'].empty?
            fire 1
            @saw_robot=true
        end
    end
end

---

this robot may have problems if it gets stuck in a corner or along the
side but so far it has seemed effective against those posted.
A9c4658e9e475e13d790ae419acf01b6?d=identicon&s=25 SimonKroeger (Guest)
on 2005-11-26 00:51
(Received via mailing list)
I wasted my time creating my first real bot (should have fixed
more bugs instead) and named it quite arrogant 'Killer':
(found one very anoying bug with the scanner pointing east, fixed
it, new version v0.1.3)

-------------------------------------------------------------------
require 'robot'

class Killer
   include Robot

   def min_max value, m
     value-= 360 if value > 180
     value+= 360 if value < -180
     value = -m if value < -m
     value = m if value > m
     return value
   end

   def tick events
     @dist = 1000 if @dist.nil?
     @target_heading = 0 if @target_heading.nil?
     @radar_range = 60 if @radar_range.nil?
     @approach = false if @approach.nil?

     if !events['robot_scanned'].empty?
       @dist = events['robot_scanned'].first.first
       @target_heading = (radar_heading - @radar_range * 0.5 + 360.0) %
360 if @radar_range.abs < 10
       @radar_range = (@radar_range.abs > 0.5) ? -@radar_range * 0.5 :
-@radar_range
     else
       @radar_range *= -2 if (@radar_range.abs < 60)
     end

     fire 3 if @radar_range.abs < 10

     @approach = true if (@dist < 200 || @dist > 500)
     @approach = false if (@dist > 250 && @dist < 300)

     if @approach
       turn_body = min_max(@target_heading - heading, 10)
       accelerate(@dist > 275 ? 1 : -1)
     else
       turn_body = min_max(@target_heading - heading + 90, 10)
       accelerate((time / 100) % 2 * 2 - 1)
     end

     gun = min_max(@target_heading - gun_heading - turn_body, 30)
     radar = min_max(@radar_range - gun - turn_body, 60)

     turn(turn_body)
     turn_gun(gun)
     turn_radar(radar)
   end
end
-------------------------------------------------------------------

cheers

Simon
A7c9c275318af9e1e3812fab9660cd7c?d=identicon&s=25 jeff.darklight (Guest)
on 2005-11-26 01:15
(Received via mailing list)
I think this has grown enough that there needs to be a separate website
&
mailing list for RRobots...

j.

On 11/25/05, Simon Kröger <SimonKroeger@gmx.de> wrote:
>    include Robot
>      @dist = 1000 if @dist.nil?
>      else
>        accelerate(@dist > 275 ? 1 : -1)
>      turn_radar(radar)
>    end
> end
> -------------------------------------------------------------------
>
> cheers
>
> Simon
>
>


--
"Remember. Understand. Believe. Yield! -> http://ruby-lang.org"

Jeff Wood
A52b0e1c5d982f2512a03c5dbfd033d6?d=identicon&s=25 rasputnik (Guest)
on 2005-11-26 12:28
(Received via mailing list)
Damn. I had some free time until I found this.
Brilliant work !
A9c4658e9e475e13d790ae419acf01b6?d=identicon&s=25 SimonKroeger (Guest)
on 2005-11-26 23:45
(Received via mailing list)
Jeff Wood wrote:

> I think this has grown enough that there needs to be a separate website &
> mailing list for RRobots...
>
> j.

true,

and there is a first version online:

http://rrobots.rubyforge.org/index.html

I would like to see new robots in the forum and move most of the
discussion there. (i read your post as a polite way of saying: please
reduce the noise to ruby-talk, or am i completely wrong?)

cheers

Simon
A7c9c275318af9e1e3812fab9660cd7c?d=identicon&s=25 jeff.darklight (Guest)
on 2005-11-27 00:02
(Received via mailing list)
I"m saying there's been a lot of traffic on the topic over the past
few days which shows a group with a focused interest, maybe you don't
want the noise from the rest of the list ... Enjoy your ducks in peace
so to say.

j.

On 11/26/05, Simon Kröger <SimonKroeger@gmx.de> wrote:
>
>
>
>


--
"Remember. Understand. Believe. Yield! -> http://ruby-lang.org"

Jeff Wood
Dd54c22454b4e3c21cadf3bdb5192e28?d=identicon&s=25 kero (Guest)
on 2005-11-27 17:35
(Received via mailing list)
> I"m saying there's been a lot of traffic on the topic over the past
> few days which shows a group with a focused interest, maybe you don't
> want the noise from the rest of the list ... Enjoy your ducks in peace
> so to say.

And you'll have to continue making noisy, shooting ducks on this list.
Otherwise you're unlikely to entice me to make one, too (in between
the other stuff I do).

Bye,
Kero.
A9c4658e9e475e13d790ae419acf01b6?d=identicon&s=25 SimonKroeger (Guest)
on 2005-11-27 23:08
(Received via mailing list)
Kero wrote:
> Bye,
> Kero.

Maybe this can entice you: :)

After a lot of Bugfixes and implementing slugfests of up to 8 robots,
this is RRobots v0.2.
The robot interface didn't change so all your creations should still
work. If you need some challenge look in the forums, good bots are
starting to apear there.

http://rrobots.rubyforge.org/screenshots.html

and if you want to download:

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

cheers

Simon
This topic is locked and can not be replied to.