Forum: Ruby Basic OO ideas

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.
Greg C. (Guest)
on 2006-04-21 06:45
(Received via mailing list)
HI all,

Still struggling with writing a basic bot for rrobots.  Thought I
would ask for some advice - given the following information, how (and
why) would you structure your classes and methods (general info fine,
not asking anyone to write code for me):

#state:  Things I can check/read from
#       team
#       battlefield_height
#       battlefield_width
#       energy
#       gun_heading
#       gun_heat
#       heading
#       size
#       radar_heading
#       time
#       game_over
#       speed
#       x
#       y
#actions:  Things I can change/set
#       accelerate
#       stop
#       fire
#       turn
#       turn_gun
#       turn_radar
#       broadcast
#       say
#events:  More things I can check/read from
#       got_hit
#       robot_scanned
#       broadcasts

Here's a basic outline I wrote - am I on the right track?

require 'robot'

class GoofeyDuck4
   include Robot

  def initialize
    @status = [
              'got_hit' => 0,
              'found' => 0,
             ]
  end

  def tick events

    bot = Bot.new

    got_hit = 1 if (!events['events'].empty?)
    found = 1 if  (!events['robot_scanned'].empty?)

    turn_radar(bot.radar.dir)
    turn_gun(bot.gun.dir)
    turn(bot.tank.dir)
    accelerate(bot.tank.speed)
    fire(bot.gun.fire)

  end

end

class Bot

  def radar

  end

  def gun

  end

  def tank

  end

end


Thanks!

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