class Rchess::Paths::Base

Attributes

board[RW]
coord[R]

Public Class Methods

new(params) click to toggle source
# File lib/rchess/path.rb, line 7
def initialize(params)
  @coord = params.fetch(:coord)
  @board = params.fetch(:board)
end
threaten_destinations_from_coord(coord, board) click to toggle source
# File lib/rchess/path.rb, line 28
def self.threaten_destinations_from_coord(coord, board)
  params = { coord: coord, board: board }
  [
    Paths::Pawn.new(params).destinations, Paths::Bishop.new(params).destinations, Paths::Knight.new(params).destinations, Paths::Rook.new(params).destinations
  ].flatten(1)
end

Public Instance Methods

destinations() click to toggle source
# File lib/rchess/path.rb, line 20
def destinations
  @destinations ||= self.paths.map{ |path| apply_delta_to_path(path).delete_if{ |coord| coord.x < 0 || coord.y < 0 } }
end
paths() click to toggle source
# File lib/rchess/path.rb, line 24
def paths
  raise NotImplementedError.new("You must implement paths")
end
srcBox() click to toggle source
# File lib/rchess/path.rb, line 12
def srcBox
  @srcBox ||= @bord.box_at_coord(@coord)
end
srcDirection() click to toggle source
# File lib/rchess/path.rb, line 16
def srcDirection
  @srcDirection ||= srcBox.downcase == srcBox ? -1 : 1 #:up or :down
end

Private Instance Methods

apply_delta_to_path(path) click to toggle source
# File lib/rchess/path.rb, line 37
def apply_delta_to_path(path)
  path.map{ |delta| self.coord.apply_delta(delta) }
end