Class: Shogi::Cell
- Inherits:
-
Object
- Object
- Shogi::Cell
- Defined in:
- lib/shogi/cell.rb
Constant Summary collapse
- USI_VERTICAL_LABELS =
{ "1" => "a", "2" => "b", "3" => "c", "4" => "d", "5" => "e", "6" => "f", "7" => "g", "8" => "h", "9" => "i", }
Instance Attribute Summary collapse
-
#piece ⇒ Object
Returns the value of attribute piece.
-
#turn ⇒ Object
Returns the value of attribute turn.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
-
#initialize(x, y, piece = nil, turn = nil) ⇒ Cell
constructor
A new instance of Cell.
- #piece_csa ⇒ Object
- #piece_usi ⇒ Object
- #place_csa ⇒ Object
- #place_usi ⇒ Object
Constructor Details
#initialize(x, y, piece = nil, turn = nil) ⇒ Cell
Returns a new instance of Cell.
18 19 20 21 22 23 |
# File 'lib/shogi/cell.rb', line 18 def initialize(x, y, piece=nil, turn=nil) @x = x @y = y @piece = piece @turn = turn end |
Instance Attribute Details
#piece ⇒ Object
Returns the value of attribute piece.
16 17 18 |
# File 'lib/shogi/cell.rb', line 16 def piece @piece end |
#turn ⇒ Object
Returns the value of attribute turn.
17 18 19 |
# File 'lib/shogi/cell.rb', line 17 def turn @turn end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
15 16 17 |
# File 'lib/shogi/cell.rb', line 15 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
15 16 17 |
# File 'lib/shogi/cell.rb', line 15 def y @y end |
Instance Method Details
#piece_csa ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/shogi/cell.rb', line 33 def piece_csa if @piece "#{turn ? "+" : "-"}#{@piece.csa}" else " * " end end |
#piece_usi ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/shogi/cell.rb', line 41 def piece_usi if @piece if @turn @piece.usi else @piece.usi.downcase end else 1 end end |
#place_csa ⇒ Object
25 26 27 |
# File 'lib/shogi/cell.rb', line 25 def place_csa "#{x}#{y}" end |
#place_usi ⇒ Object
29 30 31 |
# File 'lib/shogi/cell.rb', line 29 def place_usi "#{x}#{USI_VERTICAL_LABELS[y]}" end |