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)
Link
Instance Public methods
corner?(row, col)
Link
count_disk(disk)
Link
count_point(row, col, my_disk)
Link
count_point_to(row, col, my_disk, dir_y, dir_x)
Link
# 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)
Link
man_disk()
Link
notify_observers(*arg)
Link
other_disk(disk)
Link
put_disk(row, col, disk)
Link
reset()
Link
# 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)
Link
# 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
search(my_disk)
Link
# 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