class OthelloRuby::Game::User
Public Class Methods
new(color)
click to toggle source
# File lib/othello_ruby.rb, line 162 def initialize(color) @color = color end
Public Instance Methods
count(bord)
click to toggle source
# File lib/othello_ruby.rb, line 193 def count(bord) count = 0 case @color when bord.first_move_color bord = bord.black when bord.passive_move_color bord = bord.white else nil end 64.times do |i| count += 1 if bord[i] == 1 end count end
set(bord, coordinate)
click to toggle source
# File lib/othello_ruby.rb, line 166 def set(bord, coordinate) bit_string = convert_to_number(coordinate) case @color when bord.first_move_color patterns = get_reverse_pattern(bord.black, bord.white, bit_string) when bord.passive_move_color patterns = get_reverse_pattern(bord.white, bord.black, bit_string) else patterns = [] end if patterns.empty? nil else pattern = patterns.inject(&:|) case @color when bord.first_move_color bord.black ^= (bit_string | pattern) bord.white ^= pattern when bord.passive_move_color bord.white ^= (bit_string | pattern) bord.black ^= pattern else nil end end end
Private Instance Methods
convert_to_number(coordinate)
click to toggle source
# File lib/othello_ruby.rb, line 210 def convert_to_number(coordinate) bit_string = 0 if coordinate =~ /[1-8][A-H]|[A-H][1-8]/i row, col = coordinate.slice(/[1-8][A-H]|[A-H][1-8]/i).split("").partition{|item| item.match(/[1-8]/)} bit_string = 1 << (REPLACE[col.first.downcase] + (8 * (row.first.to_i - 1))) else end bit_string end