Class: Gomasio::Game
- Inherits:
-
Object
- Object
- Gomasio::Game
- Defined in:
- lib/gomasio/game.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
- #<<(other) ⇒ Object
- #board ⇒ Object
-
#initialize(size: 19, order: Gomasio::Disk.black) {|_self| ... } ⇒ Game
constructor
A new instance of Game.
- #ready? ⇒ Boolean
- #run ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(size: 19, order: Gomasio::Disk.black) {|_self| ... } ⇒ Game
Returns a new instance of Game.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gomasio/game.rb', line 20 def initialize(size: 19, order: Gomasio::Disk.black) @board = Gomasio::Board.new(size) @order = order yield self if block_given? @runloop = Fiber.new do @board.clear runloop end end |
Instance Attribute Details
#order ⇒ Object (readonly)
Returns the value of attribute order.
5 6 7 |
# File 'lib/gomasio/game.rb', line 5 def order @order end |
Instance Method Details
#<<(other) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/gomasio/game.rb', line 33 def <<(other) fail ArgumentError.new unless other[:player].is_a? Gomasio::Player fail ArgumentError.new unless other[:order].is_a? Gomasio::Disk @players ||= {} @players[other[:order]] = other[:player] end |
#board ⇒ Object
51 52 53 |
# File 'lib/gomasio/game.rb', line 51 def board @board.to_matrix end |
#ready? ⇒ Boolean
47 48 49 |
# File 'lib/gomasio/game.rb', line 47 def ready? @players.count == 2 end |
#run ⇒ Object
56 57 58 |
# File 'lib/gomasio/game.rb', line 56 def run @runloop.resume end |
#size ⇒ Object
42 43 44 |
# File 'lib/gomasio/game.rb', line 42 def size @board.size end |