Class: ChessValidator::Piece
- Inherits:
-
Object
- Object
- ChessValidator::Piece
- Defined in:
- lib/piece.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#defenders ⇒ Object
Returns the value of attribute defenders.
-
#move_potential ⇒ Object
Returns the value of attribute move_potential.
-
#piece_type ⇒ Object
Returns the value of attribute piece_type.
-
#position ⇒ Object
Returns the value of attribute position.
-
#square_index ⇒ Object
Returns the value of attribute square_index.
-
#targets ⇒ Object
Returns the value of attribute targets.
-
#valid_moves ⇒ Object
Returns the value of attribute valid_moves.
Instance Method Summary collapse
- #get_color(char) ⇒ Object
- #get_position(square_index) ⇒ Object
-
#initialize(char, square_index) ⇒ Piece
constructor
A new instance of Piece.
Constructor Details
#initialize(char, square_index) ⇒ Piece
Returns a new instance of Piece.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/piece.rb', line 8 def initialize(char, square_index) @piece_type = char @square_index = square_index @color = get_color(char) @position = get_position(square_index) @valid_moves = [] @targets = [] @move_potential = [] @defenders = [] end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
5 6 7 |
# File 'lib/piece.rb', line 5 def color @color end |
#defenders ⇒ Object
Returns the value of attribute defenders.
5 6 7 |
# File 'lib/piece.rb', line 5 def defenders @defenders end |
#move_potential ⇒ Object
Returns the value of attribute move_potential.
5 6 7 |
# File 'lib/piece.rb', line 5 def move_potential @move_potential end |
#piece_type ⇒ Object
Returns the value of attribute piece_type.
5 6 7 |
# File 'lib/piece.rb', line 5 def piece_type @piece_type end |
#position ⇒ Object
Returns the value of attribute position.
5 6 7 |
# File 'lib/piece.rb', line 5 def position @position end |
#square_index ⇒ Object
Returns the value of attribute square_index.
5 6 7 |
# File 'lib/piece.rb', line 5 def square_index @square_index end |
#targets ⇒ Object
Returns the value of attribute targets.
5 6 7 |
# File 'lib/piece.rb', line 5 def targets @targets end |
#valid_moves ⇒ Object
Returns the value of attribute valid_moves.
5 6 7 |
# File 'lib/piece.rb', line 5 def valid_moves @valid_moves end |
Instance Method Details
#get_color(char) ⇒ Object
23 24 25 |
# File 'lib/piece.rb', line 23 def get_color(char) char == char.downcase ? 'b' : 'w' end |
#get_position(square_index) ⇒ Object
19 20 21 |
# File 'lib/piece.rb', line 19 def get_position(square_index) SQUARE_KEY[square_index] end |