Class: Shogi::Cell

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#pieceObject

Returns the value of attribute piece.



16
17
18
# File 'lib/shogi/cell.rb', line 16

def piece
  @piece
end

#turnObject

Returns the value of attribute turn.



17
18
19
# File 'lib/shogi/cell.rb', line 17

def turn
  @turn
end

#xObject (readonly)

Returns the value of attribute x.



15
16
17
# File 'lib/shogi/cell.rb', line 15

def x
  @x
end

#yObject (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_csaObject



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_usiObject



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_csaObject



25
26
27
# File 'lib/shogi/cell.rb', line 25

def place_csa
  "#{x}#{y}"
end

#place_usiObject



29
30
31
# File 'lib/shogi/cell.rb', line 29

def place_usi
  "#{x}#{USI_VERTICAL_LABELS[y]}"
end