Class: ConsoleShogi::Player
- Inherits:
-
Object
- Object
- ConsoleShogi::Player
- Defined in:
- lib/console_shogi/player.rb
Instance Attribute Summary collapse
-
#komadai ⇒ Object
readonly
Returns the value of attribute komadai.
-
#teban ⇒ Object
readonly
Returns the value of attribute teban.
Instance Method Summary collapse
- #capture_piece!(piece) ⇒ Object
- #gote? ⇒ Boolean
-
#initialize(teban: nil) ⇒ Player
constructor
A new instance of Player.
- #sente? ⇒ Boolean
- #win? ⇒ Boolean
- #win_image ⇒ Object
Constructor Details
Instance Attribute Details
#komadai ⇒ Object (readonly)
Returns the value of attribute komadai.
5 6 7 |
# File 'lib/console_shogi/player.rb', line 5 def komadai @komadai end |
#teban ⇒ Object (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
17 18 19 |
# File 'lib/console_shogi/player.rb', line 17 def gote? teban == Teban::GOTE end |
#sente? ⇒ Boolean
13 14 15 |
# File 'lib/console_shogi/player.rb', line 13 def sente? teban == Teban::SENTE end |
#win? ⇒ Boolean
21 22 23 |
# File 'lib/console_shogi/player.rb', line 21 def win? komadai.pieces.any? {|p| p.class == Ohsho } end |
#win_image ⇒ Object
25 26 27 |
# File 'lib/console_shogi/player.rb', line 25 def win_image File.read("images/#{teban}_shori.png") end |