Class: ChessVwong::Piece

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

Direct Known Subclasses

Bishop, King, Knight, Pawn, Queen, Rook

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_space, color) ⇒ Piece

Returns a new instance of Piece.



5
6
7
8
9
10
11
# File 'lib/chess_vwong/piece.rb', line 5

def initialize(current_space, color)
  @current_space = current_space
  @color = color
  @turns = 0
  @neighbours = []
  @ep_kill = []
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



3
4
5
# File 'lib/chess_vwong/piece.rb', line 3

def color
  @color
end

#current_spaceObject

Returns the value of attribute current_space.



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

def current_space
  @current_space
end

#ep_killObject

Returns the value of attribute ep_kill.



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

def ep_kill
  @ep_kill
end

#neighboursObject

Returns the value of attribute neighbours.



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

def neighbours
  @neighbours
end

#turnsObject

Returns the value of attribute turns.



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

def turns
  @turns
end

Instance Method Details

#characterObject



18
19
20
# File 'lib/chess_vwong/piece.rb', line 18

def character
  color
end

#valid_space?(space) ⇒ Boolean

Ensuring the pieces can’t go off board

Returns:

  • (Boolean)


14
15
16
# File 'lib/chess_vwong/piece.rb', line 14

def valid_space?(space)
  true if space.all? { |coordinate| coordinate >= 1 && coordinate < 9 }
end