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(x, y) ⇒ Object
- #black_pass ⇒ Object
- #captures ⇒ Object
-
#initialize(board: 19) ⇒ Game
constructor
A new instance of Game.
- #passes ⇒ Object
- #save(name = "my_go_game") ⇒ Object
- #to_sgf ⇒ Object
- #undo ⇒ Object
- #view ⇒ Object
- #white(x, y) ⇒ 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(x, y) ⇒ Object
35 36 37 |
# File 'lib/ruby-go/game.rb', line 35 def black(x, y) play(Stone.new(x, y, :black)) end |
#black_pass ⇒ Object
43 44 45 |
# File 'lib/ruby-go/game.rb', line 43 def black_pass pass(:black) end |
#captures ⇒ Object
64 65 66 |
# File 'lib/ruby-go/game.rb', line 64 def captures moves.capture_count end |
#passes ⇒ Object
60 61 62 |
# File 'lib/ruby-go/game.rb', line 60 def passes moves.pass_count 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
51 52 53 54 55 56 57 58 |
# File 'lib/ruby-go/game.rb', line 51 def undo move = moves.pop board.remove(move.played) move.captures.each do |stone| board.place(stone) end end |
#view ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/ruby-go/game.rb', line 27 def view puts board puts " " + "_"*(board.size * 2) print " Prisoners || White: #{captures[:black]} |" puts " Black: #{captures[:white]}" puts " " + "-"*(board.size * 2) end |
#white(x, y) ⇒ Object
39 40 41 |
# File 'lib/ruby-go/game.rb', line 39 def white(x, y) play(Stone.new(x, y, :white)) end |
#white_pass ⇒ Object
47 48 49 |
# File 'lib/ruby-go/game.rb', line 47 def white_pass pass(:white) end |