From: Edwin van Leeuwen Date: 2005-11-25T06:51:45+09:00 Subject: Re: RRobots - ducks, armed and dangerous 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 -- Posted via http://www.ruby-forum.com/.