Class: RGnuchess::Board::Piece
- Inherits:
-
Object
- Object
- RGnuchess::Board::Piece
- Defined in:
- lib/rgnuchess.rb
Overview
Piece represents a single chess piece on a board
Constant Summary collapse
- Pieces =
{"P"=>:pawn,"R"=>:rook,"N"=>:knight,"B"=>:bishop,"K"=>:king,"Q"=>:queen,"."=>:empty}
- Pieces_reverse =
Pieces.invert
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#piece ⇒ Object
readonly
Returns the value of attribute piece.
Class Method Summary collapse
-
.parse(char) ⇒ Object
parse a character of gnuchess output from a board into a piece.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(color = :white, piece = :empty) ⇒ Piece
constructor
A new instance of Piece.
- #to_s ⇒ Object
Constructor Details
#initialize(color = :white, piece = :empty) ⇒ Piece
Returns a new instance of Piece.
119 120 121 |
# File 'lib/rgnuchess.rb', line 119 def initialize( color=:white, piece=:empty ) @color, @piece = color, piece end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
133 134 135 |
# File 'lib/rgnuchess.rb', line 133 def color @color end |
#piece ⇒ Object (readonly)
Returns the value of attribute piece.
133 134 135 |
# File 'lib/rgnuchess.rb', line 133 def piece @piece end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object
122 123 124 |
# File 'lib/rgnuchess.rb', line 122 def ==(other) other.color==@color && other.piece==:piece end |
#to_s ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/rgnuchess.rb', line 125 def to_s s=Pieces_reverse[@piece] if @color==:white s else s.downcase end end |