Module: Chess::Pieces::RookMoves

Included in:
Queen, Rook
Defined in:
lib/chess/pieces/rook.rb

Overview

RookMoves

Instance Method Summary collapse

Instance Method Details

#east_moves(board, file, rank) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/chess/pieces/rook.rb', line 33

def east_moves(board, file, rank)
  east = board.east_pos(file, rank)

  moves = []
  while board.empty_at?(*east)
    moves << east if board.pos_in_range?(east)
    east = board.east_pos(*east)
  end
  moves << east if board.pos_in_range?(east) && board.enemy_at?(*east)
  moves
end

#north_moves(board, file, rank) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/chess/pieces/rook.rb', line 9

def north_moves(board, file, rank)
  north = board.north_pos(file, rank)

  moves = []
  while board.empty_at?(*north)
    moves << north if board.pos_in_range?(north)
    north = board.north_pos(*north)
  end
  moves << north if board.pos_in_range?(north) && board.enemy_at?(*north)
  moves
end

#south_moves(board, file, rank) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/chess/pieces/rook.rb', line 21

def south_moves(board, file, rank)
  south = board.south_pos(file, rank)

  moves = []
  while board.empty_at?(*south)
    moves << south if board.pos_in_range?(south)
    south = board.south_pos(*south)
  end
  moves << south if board.pos_in_range?(south) && board.enemy_at?(*south)
  moves
end

#west_moves(board, file, rank) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/chess/pieces/rook.rb', line 45

def west_moves(board, file, rank)
  west = board.west_pos(file, rank)

  moves = []
  while board.empty_at?(*west)
    moves << west if board.pos_in_range?(west)
    west = board.west_pos(*west)
  end
  moves << west if board.pos_in_range?(west) && board.enemy_at?(*west)
  moves
end