Module: Rook

Extended by:
Rook
Includes:
Moves
Included in:
BlackRook, Rook, WhiteRook
Defined in:
lib/rook.rb

Instance Method Summary collapse

Methods included from Moves

#diagonal, #horizontal, #move, #vertical

Instance Method Details

#illegal(board, x, y) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rook.rb', line 6

def illegal(board,x,y)
  possible_moves = []

  7.times do |coord|
    possible_moves += Board.board_safe(
      horizontal(coord) + vertical(coord) 
    )
  end

  if not(possible_moves.any? {|move| move == [x,y]})
    raise Game::IllegalMove, "#{x},#{y} is not a possible move" 
  elsif board.at(x,y).friend_of?(self)
    raise Game::IllegalMove, "#{x},#{y} is occupied by a friend"
  elsif jumped?(board,x,y) 
    raise Game::IllegalMove, "Rooks cannot jump" 
  else
    :legal_move
  end
end