class Rubykon::EyeDetector

Public Instance Methods

candidate_eye_color(identifier, board) click to toggle source
# File lib/rubykon/eye_detector.rb, line 9
def candidate_eye_color(identifier, board)
  neighbor_colors = board.neighbour_colors_of(identifier)
  candidate_eye_color = neighbor_colors.first
  return false if candidate_eye_color == Board::EMPTY
  if neighbor_colors.all? {|color| color == candidate_eye_color}
    candidate_eye_color
  else
    nil
  end
end
is_eye?(identifier, board) click to toggle source
# File lib/rubykon/eye_detector.rb, line 3
def is_eye?(identifier, board)
  candidate_eye_color = candidate_eye_color(identifier, board)
  return false unless candidate_eye_color
  is_real_eye?(identifier, board, candidate_eye_color)
end

Private Instance Methods

is_real_eye?(identifier, board, candidate_eye_color) click to toggle source
# File lib/rubykon/eye_detector.rb, line 21
def is_real_eye?(identifier, board, candidate_eye_color)
  enemy_color = Game.other_color(candidate_eye_color)
  enemy_count = board.diagonal_colors_of(identifier).count(enemy_color)
  (enemy_count < 1) || (!board.on_edge?(identifier) && enemy_count < 2)
end