Class: JustChess::Rook

Inherits:
Piece
  • Object
show all
Defined in:
lib/just_chess/pieces/rook.rb

Overview

Rook

The piece that moves any number of squares orthogonally.

Instance Attribute Summary

Attributes inherited from Piece

#has_moved, #id, #player_number

Instance Method Summary collapse

Methods inherited from Piece

#as_json, #can_move?, #capture_squares, #has_not_moved?, #initialize, #move_squares, #moved, #opponent, #potential_capture_squares, #type

Constructor Details

This class inherits a constructor from JustChess::Piece

Instance Method Details

#destinations(square, game_state) ⇒ SquareSet

All the squares that the piece can move to and/or capture.

Parameters:

  • square (Square)

    the origin square.

  • game_state (GameState)

    the current game state.

Returns:



19
20
21
# File 'lib/just_chess/pieces/rook.rb', line 19

def destinations(square, game_state)
  game_state.squares.orthogonal(square).unoccupied_or_occupied_by_opponent(player_number).unblocked(square, game_state.squares)
end