class Rchess::Paths::Pawn

Public Instance Methods

paths() click to toggle source
# File lib/rchess/paths/pawn.rb, line 4
def paths
  [move_forward, take_piece, move_2_if_first_move].select{|path| !path.empty?}
end

Private Instance Methods

move_2_if_first_move() click to toggle source
# File lib/rchess/paths/pawn.rb, line 10
def move_2_if_first_move
  if piece_first_move?
    [{x: 0, y: 2*srcDirection}, {x: 0, y: 2*srcDirection}]
  else
    []
  end
end
move_forward() click to toggle source
# File lib/rchess/paths/pawn.rb, line 32
def move_forward
  [{x: 0, y: direction}].select do |delta|
    dstCoord = self.coord.apply_delta(delta)
    dstPiece = self.board.piece_at_coord(dstCoord)
    dstPiece.nil?
  end
end
piece_first_move?() click to toggle source
# File lib/rchess/paths/pawn.rb, line 18
def piece_first_move?
  self.coord.y == 1 && self.srcDirection == 1 || self.coord.y == 6 && self.srcDirection == -1
end
take_piece() click to toggle source
# File lib/rchess/paths/pawn.rb, line 22
def take_piece
  #TODO: remove the color notion, there is only 1 piece that goes up and one that goes down
  [{x: 1, y: direction}, {x: -1, y: srcDirection}].select do |delta|
    dstCoord = self.coord.apply_delta(delta)
    dstBox = self.board.box_at_coord(dstCoord)
    self.board.direction_for_coord(coord) #TODO: implement - talk about boxes not pieces
    !dstPiece.nil? && dstPiece.direction != srcPiece.direction
  end
end