Class: Gomasio::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/gomasio/game.rb

Defined Under Namespace

Classes: Command, Status

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size: 19, order: Gomasio::Disk.black) {|_self| ... } ⇒ Game

Returns a new instance of Game.

Yields:

  • (_self)

Yield Parameters:

  • _self (Gomasio::Game)

    the object that the method was called on



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

#orderObject (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

#boardObject



51
52
53
# File 'lib/gomasio/game.rb', line 51

def board
  @board.to_matrix
end

#ready?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/gomasio/game.rb', line 47

def ready?
  @players.count == 2
end

#runObject



56
57
58
# File 'lib/gomasio/game.rb', line 56

def run
  @runloop.resume
end

#sizeObject



42
43
44
# File 'lib/gomasio/game.rb', line 42

def size
  @board.size
end