Method: Board#initialize
- Defined in:
- lib/gorb/board.rb
#initialize(black = nil, white = nil, handicap = 0, komi = 6.5, size = "19x19") ⇒ Board
Initialize a new Board instance. Requires two Player objects, a handicap, a komi and a size as arguments. The handicap should be an integer from 0 to 9. Komi can be negative. Size should be either 9x9, 13x13 or 19x19.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gorb/board.rb', line 11 def initialize(black=nil, white=nil, handicap=0, komi=6.5, size="19x19") @black = black ||= Player.new("Black") @white = white ||= Player.new("White") @komi = komi @size = size @groups = [] @hashes = [] @turn = black @dead_groups = [] raise ArgumentError, "Incorrect handicap" if handicap < 0 or handicap > 9 @handicap = handicap @komi = 0.5 if handicap > 0 @turn = white if handicap > 1 if size == "9x9" @letters = %w{A B C D E F G H J} handicap_stones = %w{G7 C3 G3 C7 E5 C5 G5 E7 E3} elsif size == "13x13" @letters = %w{A B C D E F G H J K L M N} handicap_stones = %w{K10 D4 K4 D10 G7 D7 K7 G10 G4} elsif size == "19x19" @letters = %w{A B C D E F G H J K L M N O P Q R S T} handicap_stones = %w{Q16 D4 Q4 D16 K10 D10 Q10 K16 K4} else raise ArgumentError, "Incorrect board size" end case @handicap when 2..5, 7, 9 handicap_stones[0..(@handicap-1)].each {|s| self.add_stone(s, :black)} when 6, 8 handicap_stones[0..@handicap].each {|s| self.add_stone(s, :black)} self.remove_stone(handicap_stones[4]) # Middle stone end end |