Class: RubyGo::Game
- Inherits:
-
Object
- Object
- RubyGo::Game
- Defined in:
- lib/ruby-go/game.rb
Defined Under Namespace
Classes: IllegalMove
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
Instance Method Summary collapse
- #black_pass ⇒ Object
- #captures ⇒ Object
-
#initialize(board: 19) ⇒ Game
constructor
A new instance of Game.
- #passes ⇒ Object
- #place_black(x, y) ⇒ Object
- #place_white(x, y) ⇒ Object
- #save(name = "my_go_game") ⇒ Object
- #to_sgf ⇒ Object
- #undo ⇒ Object
- #white_pass ⇒ Object
Constructor Details
Instance Attribute Details
#board ⇒ Object (readonly)
Returns the value of attribute board.
3 4 5 |
# File 'lib/ruby-go/game.rb', line 3 def board @board end |
Instance Method Details
#black_pass ⇒ Object
35 36 37 |
# File 'lib/ruby-go/game.rb', line 35 def black_pass pass(:black) end |
#captures ⇒ Object
56 57 58 |
# File 'lib/ruby-go/game.rb', line 56 def captures moves.capture_count end |
#passes ⇒ Object
52 53 54 |
# File 'lib/ruby-go/game.rb', line 52 def passes moves.pass_count end |
#place_black(x, y) ⇒ Object
27 28 29 |
# File 'lib/ruby-go/game.rb', line 27 def place_black(x, y) play(Stone.new(x, y, :black)) end |
#place_white(x, y) ⇒ Object
31 32 33 |
# File 'lib/ruby-go/game.rb', line 31 def place_white(x, y) play(Stone.new(x, y, :white)) end |
#save(name = "my_go_game") ⇒ Object
12 13 14 15 |
# File 'lib/ruby-go/game.rb', line 12 def save(name="my_go_game") tree = SGF::Parser.new.parse(to_sgf) tree.save(name + '.sgf') end |
#to_sgf ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/ruby-go/game.rb', line 17 def to_sgf sgf = "(;GM[1]FF[4]CA[UTF-8]AP[jphager2]SZ[#{board.size}]PW[White]PB[Black]" moves.each do |move| sgf << move.played.to_sgf end sgf << ')' end |
#undo ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/ruby-go/game.rb', line 43 def undo move = moves.pop board.remove(move.played) move.captures.each do |stone| board.place(stone) end end |
#white_pass ⇒ Object
39 40 41 |
# File 'lib/ruby-go/game.rb', line 39 def white_pass pass(:white) end |