Class: ChessValidator::Piece

Inherits:
Object
  • Object
show all
Defined in:
lib/piece.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#colorObject

Returns the value of attribute color.



5
6
7
# File 'lib/piece.rb', line 5

def color
  @color
end

#defendersObject

Returns the value of attribute defenders.



5
6
7
# File 'lib/piece.rb', line 5

def defenders
  @defenders
end

#move_potentialObject

Returns the value of attribute move_potential.



5
6
7
# File 'lib/piece.rb', line 5

def move_potential
  @move_potential
end

#piece_typeObject

Returns the value of attribute piece_type.



5
6
7
# File 'lib/piece.rb', line 5

def piece_type
  @piece_type
end

#positionObject

Returns the value of attribute position.



5
6
7
# File 'lib/piece.rb', line 5

def position
  @position
end

#square_indexObject

Returns the value of attribute square_index.



5
6
7
# File 'lib/piece.rb', line 5

def square_index
  @square_index
end

#targetsObject

Returns the value of attribute targets.



5
6
7
# File 'lib/piece.rb', line 5

def targets
  @targets
end

#valid_movesObject

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