Class: ConsoleShogi::Player

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(teban: nil) ⇒ Player

Returns a new instance of Player.



7
8
9
10
11
# File 'lib/console_shogi/player.rb', line 7

def initialize(teban: nil)
  @teban = teban
  # TODO Komadai, Piece, Player が循環してる
  @komadai = Komadai.new
end

Instance Attribute Details

#komadaiObject (readonly)

Returns the value of attribute komadai.



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

def komadai
  @komadai
end

#tebanObject (readonly)

Returns the value of attribute teban.



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

def teban
  @teban
end

Instance Method Details

#capture_piece!(piece) ⇒ Object



29
30
31
32
# File 'lib/console_shogi/player.rb', line 29

def capture_piece!(piece)
  piece.teban = teban
  komadai.put(piece: piece)
end

#gote?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/console_shogi/player.rb', line 17

def gote?
  teban == Teban::GOTE
end

#sente?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/console_shogi/player.rb', line 13

def sente?
  teban == Teban::SENTE
end

#win?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/console_shogi/player.rb', line 21

def win?
  komadai.pieces.any? {|p| p.class == Ohsho }
end

#win_imageObject



25
26
27
# File 'lib/console_shogi/player.rb', line 25

def win_image
  File.read("images/#{teban}_shori.png")
end