From: Jeff Wood Date: 2005-11-26T09:15:28+09:00 Subject: Re: RRobots - ducks, armed and dangerous ------=_Part_6760_19258845.1132964121494 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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=F6ger wrote: > > 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-=3D 360 if value > 180 > value+=3D 360 if value < -180 > value =3D -m if value < -m > value =3D m if value > m > return value > end > > def tick events > @dist =3D 1000 if @dist.nil? > @target_heading =3D 0 if @target_heading.nil? > @radar_range =3D 60 if @radar_range.nil? > @approach =3D false if @approach.nil? > > if !events['robot_scanned'].empty? > @dist =3D events['robot_scanned'].first.first > @target_heading =3D (radar_heading - @radar_range * 0.5 + 360.0) % > 360 if @radar_range.abs < 10 > @radar_range =3D (@radar_range.abs > 0.5) ? -@radar_range * 0.5 : > -@radar_range > else > @radar_range *=3D -2 if (@radar_range.abs < 60) > end > > fire 3 if @radar_range.abs < 10 > > @approach =3D true if (@dist < 200 || @dist > 500) > @approach =3D false if (@dist > 250 && @dist < 300) > > if @approach > turn_body =3D min_max(@target_heading - heading, 10) > accelerate(@dist > 275 ? 1 : -1) > else > turn_body =3D min_max(@target_heading - heading + 90, 10) > accelerate((time / 100) % 2 * 2 - 1) > end > > gun =3D min_max(@target_heading - gun_heading - turn_body, 30) > radar =3D min_max(@radar_range - gun - turn_body, 60) > > turn(turn_body) > turn_gun(gun) > turn_radar(radar) > end > end > ------------------------------------------------------------------- > > cheers > > Simon > > -- "Remember. Understand. Believe. Yield! -> http://ruby-lang.org" Jeff Wood ------=_Part_6760_19258845.1132964121494--