-- Movement strategy in which the Mobile follows
-- Stooge's trail.

class
  BLOODHOUND
inherit
  STRATEGY

creation
  make

feature{NONE}

  next_cell : GAME_CELL
  -- Where I want my `mobile' to go next.

  next_spoor : INTEGER
  -- The spoor in `next_cell'

  second_cell : GAME_CELL
  -- I'll try this one if the first one doesn't
  -- work out.

  find_best_direction is
  -- Look around me for traces of the Stooge, remember
  -- the location with the most recent trace if any.
  do
    next_cell := Void
    next_spoor := spoor
    second_cell := Void
    compare( mobile.northwest.north )
    compare( mobile.northeast.north )
    compare( mobile.northeast.east )
    compare( mobile.southeast.east )
    compare( mobile.southeast.south )
    compare( mobile.southwest.south )
    compare( mobile.southwest.west )
    compare( mobile.northwest.west )
  end

  compare( c : GAME_CELL ) is
  -- compare my `spoor' to that of `c', set `next_cell' and
  -- `next_spoor' accordingly.
  do
    if c.spoor > next_spoor then
      next_cell := c
      next_spoor := next_cell.spoor
    end
    if c.spoor = spoor then
      second_cell := c
    end
  end

  go_there( c : GAME_CELL ) is
  -- Go in direction of `c' if possible.
  do
    if c = mobile.northeast.north or
       c = mobile.northwest.north then
      mobile.try_north
    elseif c = mobile.northeast.east or
       c = mobile.southeast.east then
      mobile.try_east
    elseif c = mobile.southeast.south or
       c = mobile.southwest.south then
      mobile.try_south
    elseif c = mobile.southwest.west or
       c = mobile.northwest.west then
      mobile.try_west
    end
  end


feature

  spoor : INTEGER

  init_spoor is
  -- Set `spoor' to 0
  do
    spoor := 0
  ensure
    spoor = 0
  end

  try_move is
  -- Try to follow the trail of the Stooge.
  do
    find_best_direction
    if next_cell /= Void then
      go_there( next_cell )
      if mobile.success then
        spoor := next_cell.spoor
      else
        go_there( second_cell )
      end
    end
  end	

end -- class BLOODHOUND
