Class: RubyGo::Moves

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-go/moves.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMoves

Returns a new instance of Moves.



5
6
7
8
9
# File 'lib/ruby-go/moves.rb', line 5

def initialize
  @internal_moves = []
  @pass_count = 0
  @capture_count = { black: 0, white: 0 }
end

Instance Attribute Details

#capture_countObject (readonly)

Returns the value of attribute capture_count.



3
4
5
# File 'lib/ruby-go/moves.rb', line 3

def capture_count
  @capture_count
end

#internal_movesObject (readonly)

Returns the value of attribute internal_moves.



3
4
5
# File 'lib/ruby-go/moves.rb', line 3

def internal_moves
  @internal_moves
end

#pass_countObject (readonly)

Returns the value of attribute pass_count.



3
4
5
# File 'lib/ruby-go/moves.rb', line 3

def pass_count
  @pass_count
end

Instance Method Details

#capture(stone) ⇒ Object



45
46
47
48
# File 'lib/ruby-go/moves.rb', line 45

def capture(stone)
  current.captures << stone
  capture_count[stone.color] += 1
end

#currentObject



29
30
31
# File 'lib/ruby-go/moves.rb', line 29

def current
  internal_moves[-1]
end

#each(&block) ⇒ Object



21
22
23
# File 'lib/ruby-go/moves.rb', line 21

def each(&block)
  internal_moves.each(&block)
end

#pass(pass) ⇒ Object



16
17
18
19
# File 'lib/ruby-go/moves.rb', line 16

def pass(pass)
  @pass_count += 1
  internal_moves << Move.new(pass)
end

#play(played) ⇒ Object



11
12
13
14
# File 'lib/ruby-go/moves.rb', line 11

def play(played)
  @pass_count += 0
  internal_moves << Move.new(played)
end

#popObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ruby-go/moves.rb', line 33

def pop
  move = internal_moves.pop

  move.captures.each do |stone|
    capture_count[stone.color] -= 1
  end

  @pass_count -= 1 if move.empty?

  move
end

#prevObject



25
26
27
# File 'lib/ruby-go/moves.rb', line 25

def prev
  internal_moves[-2]
end