Class: Chess::Pieces::Queen

Inherits:
Piece
  • Object
show all
Includes:
BishopMoves, RookMoves
Defined in:
lib/chess/pieces/queen.rb

Overview

Queen

Instance Attribute Summary

Attributes inherited from Piece

#color, #pos, #valid_moves

Instance Method Summary collapse

Methods included from BishopMoves

#north_east_moves, #north_west_moves, #south_east_moves, #south_west_moves

Methods included from RookMoves

#east_moves, #north_moves, #south_moves, #west_moves

Methods inherited from Piece

#black?, #initialize, #white?

Constructor Details

This class inherits a constructor from Chess::Pieces::Piece

Instance Method Details

#bishop_moves(board, file, rank) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/chess/pieces/queen.rb', line 34

def bishop_moves(board, file, rank)
  moves = []
  moves += north_west_moves(board, file, rank)
  moves += north_east_moves(board, file, rank)
  moves += south_west_moves(board, file, rank)
  moves += south_east_moves(board, file, rank)
  moves
end

#possible_moves(board) ⇒ Array

all possible_moves of Queen

Parameters:

Returns:

  • (Array)

    possible_moves_arr



16
17
18
19
20
21
22
23
# File 'lib/chess/pieces/queen.rb', line 16

def possible_moves(board)
  file = @pos[0]
  rank = @pos[1]
  moves = []
  moves += rook_moves(board, file, rank)
  moves += bishop_moves(board, file, rank)
  moves
end

#rook_moves(board, file, rank) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/chess/pieces/queen.rb', line 25

def rook_moves(board, file, rank)
  moves = []
  moves += north_moves(board, file, rank)
  moves += south_moves(board, file, rank)
  moves += west_moves(board, file, rank)
  moves += east_moves(board, file, rank)
  moves
end