Methods
C
G
M
N
O
P
R
S
Included Modules
Constants
DIRECTIONS = [ [-1, -1], [-1, 0], [-1, 1], [ 0, -1], [ 0, 1], [ 1, -1], [ 1, 0], [ 1, 1] ]
 
Attributes
[RW] com_disk
Class Public methods
new(othello)
# File ext/tk/sample/tcltklib/sample2.rb, line 47
def initialize(othello)
   @othello = othello
   reset
end
Instance Public methods
corner?(row, col)
# File ext/tk/sample/tcltklib/sample2.rb, line 153
def corner?(row, col)
   return (row == 0 && col == 0) ||
      (row == 0 && col == 7) ||
      (row == 7 && col == 0) ||
      (row == 7 && col == 7)
end
count_disk(disk)
# File ext/tk/sample/tcltklib/sample2.rb, line 114
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
count_point(row, col, my_disk)
# File ext/tk/sample/tcltklib/sample2.rb, line 145
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
count_point_to(row, col, my_disk, dir_y, dir_x)
# File ext/tk/sample/tcltklib/sample2.rb, line 126
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
get_disk(row, col)
# File ext/tk/sample/tcltklib/sample2.rb, line 81
def get_disk(row, col)
   return @data[row][col]
end
man_disk()
# File ext/tk/sample/tcltklib/sample2.rb, line 73
def man_disk
   return - @com_disk
end
notify_observers(*arg)
# File ext/tk/sample/tcltklib/sample2.rb, line 52
def notify_observers(*arg)
   if @observer_peers != nil
      super(*arg)
   end
end
other_disk(disk)
# File ext/tk/sample/tcltklib/sample2.rb, line 77
def other_disk(disk)
   return - disk
end
put_disk(row, col, disk)
# File ext/tk/sample/tcltklib/sample2.rb, line 105
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
reset()
# File ext/tk/sample/tcltklib/sample2.rb, line 58
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
reverse_to(row, col, my_disk, dir_y, dir_x)
# File ext/tk/sample/tcltklib/sample2.rb, line 85
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
# File ext/tk/sample/tcltklib/sample2.rb, line 160
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