class Rook
Rook
piece for a game of chess
Public Class Methods
new(color, position)
click to toggle source
Initializes a new rook piece with color and position.
@param [String] color A string denoting the color of the piece. @param [Array<Integer>] position An integer array of length 2 denoting the location of the piece on the board.
Calls superclass method
ChessPiece::new
# File lib/chess_pieces/rook.rb, line 13 def initialize(color, position) @move_tree_template = build_rook_move_tree super(color == 'white' ? '♜'.white : '♖', color, position, 5) end
Protected Instance Methods
build_rook_move_tree()
click to toggle source
Builds the Rook's move tree. The Rook
can move horizontally and vertically as far as the board permits.
@return [MoveTree] move_tree_template A move tree template for the rook.
# File lib/chess_pieces/rook.rb, line 25 def build_rook_move_tree move_tree = MoveTree.new([0, 0]) # Build in each of the four directions the rook can go. move_tree.root.add_child(build_directional_tree_nodes([1, 0])) move_tree.root.add_child(build_directional_tree_nodes([-1, 0])) move_tree.root.add_child(build_directional_tree_nodes([0, 1])) move_tree.root.add_child(build_directional_tree_nodes([0, -1])) move_tree end