Back on track.

The past couple of weeks I've been transitioning to a different job with a different schedule, that has thrown me for a bit of a loop. but I've tried to work on a couple of sites and I feel that I need a better understanding of HTML and CSS. So I am going to spend a bit of time this week, exploring HTML and CSS. I have a couple of website projects coming up shortly and I'll be updateing my blog as I make progress.

Ruby on rails, weekly round up.

This week has gone by fast.
I have accomplished a lot this week, unfortunately it wasn't all software development. Only 14.25 hours of it was was software development.
A bit short of my goal. I don't have my next weeks goals setup yet. The original business model for my website won't work out so i will have to make some adjustments. I am going to have a planning session on Monday afternoon and finish this blog post's details.

RTanque: Article # 5 "How to Avoid Brain Surgery"

How to Avoid Brain Surgery 

Changing how your bot thinks. 

Scalpel, forceps, knife, screwdriver... ...the brain surgeon keeps operating on the patient until, with a sense of surprise he realizes. Oops, there is no patient here! Now in real life that would never happen, but in this world of RTanque that is what can happen, and I am going to show you how you modify any bot to avoid brain surgery. All you need to do is redefine one method in brain, so that we can rename the tick! method. That way when the brain surgeon replaces your tick! method it won't matter because your not using that function to think any longer. So your bots tick! function will look something like this before we rename it.
 
  def tick!
      some_function_a
      some_function_b
  end
 
Which we will rewrite to say
 
  def some_hard_to_guess_name
     some_function_a
     some_function_b
  end

So now that you made this change your bots code, we also need to redefine the function in brain that calls tick! The name of this function is tick. What we will do is define the tick function in our code so that it will override the one in brain. the tick method in brain looks like this.

def tick(sensors)
  self.sensors = sensors
  RTanque::Bot::Command.new.tap do |empty_command|
    self.command = empty_command
    self.tick!
  end
end
 
Put the whole function in your bot's code, and then we change self.tick! to self.some_hard_to_guess_name like this.

def tick(sensors)
  self.sensors = sensors
  RTanque::Bot::Command.new.tap do |empty_command|
    self.command = empty_command
    self.some_hard_to_guess_name
  end
end
 
Let me explain what is going on. the tick function in the brain normally calls tick! but now because we define it locally, the local function will override the one built into the brain, and now call the some_hard_to_guess_name function. One important note: if you add this code to a brains surgeon bot you can now make make clones of your tank without your clones lobotomizing each other.
Here is what the BrainSurgeonBasicTargetingBot looks like after I added this feature.

class CloneableBrainSurgeonBasicTargetingBot < RTanque::Bot::Brain
  NAME = "#{self}"
  include RTanque::Bot::BrainHelper

  TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 1.5

  # drill open their skulls
  class RTanque::Bot
    attr_accessor :brain
  end

  def tick(sensors)
    self.sensors = sensors
    RTanque::Bot::Command.new.tap do |empty_command|
      self.command = empty_command
      self.some_hard_to_guess_name
    end
  end

  def some_hard_to_guess_name
    first_time do
      lobotomize_opponents
    end

    ## main logic goes here
    # use self.sensors to detect things
    # use self.command to control tank
    # self.arena contains the dimensions of the arena

    self.make_circles
    if we_have_target
      target = we_have_target
      track_target(target)
      aim_at_target(target)
      fire_at_target(target)
    else
      self.scan_with_radar
    end
  end

  def make_circles
    command.speed = MAX_BOT_SPEED # takes a value between -5 to 5 
    command.heading = sensors.heading + MAX_BOT_ROTATION
  end

  def we_have_target
    self.nearest_target
  end

  def nearest_target
    self.sensors.radar.min { |a,b| a.distance <=> b.distance }
  end

  def track_target(target)
    self.command.radar_heading = target.heading
  end
  
  def aim_at_target(target)
    self.command.turret_heading = target.heading
  end

  def fire_at_target(target)
      if self.pointing_at_target?(target)
        command.fire(MAX_FIRE_POWER)
      end
  end

  def pointing_at_target?(target)
    (target.heading.delta(sensors.turret_heading)).abs < TURRET_FIRE_RANGE
  end

  def scan_with_radar
    self.command.radar_heading = self.sensors.radar_heading + MAX_RADAR_ROTATION
  end

  private

  def first_time
    unless @first_time_guard
      yield
      @first_time_guard = "checked"
    end
  end

  def lobotomize_opponents
    ObjectSpace.each_object(RTanque::Bot) { |x|
     x.brain.class.send(:define_method, :tick!) {
      "#This is where you write the new tick!
      #method that you will use to replace your opponents
      #if you leave this blank you will make him brainless"
      } unless x.brain.class == self.class
    }

  end
end
class DroidSurgeon < CloneableBrainSurgeonBasicTargetingBot
NAME = "#{self}"
end
 
With this tank not only will you be protected from brain surgery, but you will also lobotomize all the other tanks in the field including the lobotimizer, if they have not taken similar steps to defend their brains.

Easter, Breaking 300, and the End of Class

Happy Easter! I completed the Berkeley classes this week. I got the bulk of my weekly agenda goals done. The one I didn't quite get all the way done was watch all the videos lectures. I have one lecture left to watch, and some bonus videos from the course. I racked up 20 hours study time this week, one short of my basic goal, but I still broke 300 hours this week, and I will make it up that hour, this week.

My Weekly Agenda Goals
  1. Publish 2 RTanque Articles
  2. Finish the bonus videos from class and the one lecture on deployment and security.
  3. Spend at Least 6 hours on the Michael Hartl's Ruby on Rails Tutorial.
  4. Create a mockup of what I want the Job application site to look like.
  5. Interview 3 local business owners on