- C
- G
- M
- N
- O
- P
- R
- S
| DIRECTIONS | = | [ [-1, -1], [-1, 0], [-1, 1], [ 0, -1], [ 0, 1], [ 1, -1], [ 1, 0], [ 1, 1] ] |
| [RW] | com_disk |
Source: show
# File ext/tk/sample/tcltklib/sample2.rb, line 46 def initialize(othello) @othello = othello reset end
Source: show
# File ext/tk/sample/tcltklib/sample2.rb, line 152 def corner?(row, col) return (row == 0 && col == 0) || (row == 0 && col == 7) || (row == 7 && col == 0) || (row == 7 && col == 7) end
Source: show
# File ext/tk/sample/tcltklib/sample2.rb, line 113 def count_disk(disk) num = 0 @data.each do |rows| rows.each do |d| if d == disk num += 1 end end end return num end
Source: show
# File ext/tk/sample/tcltklib/sample2.rb, line 144 def count_point(row, col, my_disk) count = 0 DIRECTIONS.each do |dir| count += count_point_to(row, col, my_disk, *dir) end return count end
Source: show
# File ext/tk/sample/tcltklib/sample2.rb, line 125 def count_point_to(row, col, my_disk, dir_y, dir_x) return 0 if @data[row][col] != EMPTY count = 0 loop do row += dir_y col += dir_x break if row < 0 || col < 0 || row > 7 || col > 7 case @data[row][col] when my_disk return count when other_disk(my_disk) count += 1 when EMPTY break end end return 0 end
Source: show
# File ext/tk/sample/tcltklib/sample2.rb, line 80 def get_disk(row, col) return @data[row][col] end
Source: show
# File ext/tk/sample/tcltklib/sample2.rb, line 72 def man_disk return - @com_disk end
Source: show
# File ext/tk/sample/tcltklib/sample2.rb, line 51 def notify_observers(*arg) if @observer_peers != nil super(*arg) end end
Source: show
# File ext/tk/sample/tcltklib/sample2.rb, line 76 def other_disk(disk) return - disk end
Source: show
# File ext/tk/sample/tcltklib/sample2.rb, line 104 def put_disk(row, col, disk) @data[row][col] = disk changed notify_observers(row, col) DIRECTIONS.each do |dir| reverse_to(row, col, disk, *dir) end end
Source: show
# File ext/tk/sample/tcltklib/sample2.rb, line 57 def reset @data = [ [EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY], [EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY], [EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY], [EMPTY, EMPTY, EMPTY, WHITE, BLACK, EMPTY, EMPTY, EMPTY], [EMPTY, EMPTY, EMPTY, BLACK, WHITE, EMPTY, EMPTY, EMPTY], [EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY], [EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY], [EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY] ] changed notify_observers end
Source: show
# File ext/tk/sample/tcltklib/sample2.rb, line 84 def reverse_to(row, col, my_disk, dir_y, dir_x) y = row x = col begin y += dir_y x += dir_x if y < 0 || x < 0 || y > 7 || x > 7 || @data[y][x] == EMPTY return end end until @data[y][x] == my_disk begin @data[y][x] = my_disk changed notify_observers(y, x) y -= dir_y x -= dir_x end until y == row && x == col end
Source: show
# File ext/tk/sample/tcltklib/sample2.rb, line 159 def search(my_disk) max = 0 max_row = nil max_col = nil for row in 0 .. 7 for col in 0 .. 7 buf = count_point(row, col, my_disk) if (corner?(row, col) && buf > 0) || max < buf max = buf max_row = row max_col = col end end end return max_row, max_col end