class Cell
Cell.rb
Created on September 23, 2013
A class that contains the logic for a single cell in a sudoku puzzle.
Public Class Methods
new(*args)
click to toggle source
# File lib/phg_sudoku_solver/cell.rb, line 11 def initialize *args @fixed_value = -1 @possible_values = [] if args.size==1 case args[0].class.to_s when "Array" @possible_values = args[0] when "Fixnum" @fixed_value = args[0] end end end
Public Instance Methods
add_possible_value(val)
click to toggle source
# File lib/phg_sudoku_solver/cell.rb, line 29 def add_possible_value(val) @possible_values.push(val) if @possible_values.count > 1 @fixed_value = -1 end end
contains_possible_value(x)
click to toggle source
# File lib/phg_sudoku_solver/cell.rb, line 55 def contains_possible_value(x) @possible_values.include?(x) end
copy()
click to toggle source
# File lib/phg_sudoku_solver/cell.rb, line 59 def copy() c = Cell.new() c.set_fixed_value(@fixed_value) c.set_possible_values(@possible_values) c end
get_fixed_value()
click to toggle source
# File lib/phg_sudoku_solver/cell.rb, line 47 def get_fixed_value() @fixed_value end
get_possible_values()
click to toggle source
# File lib/phg_sudoku_solver/cell.rb, line 51 def get_possible_values() @possible_values end
reset_possible_values()
click to toggle source
# File lib/phg_sudoku_solver/cell.rb, line 25 def reset_possible_values() @possible_values = [] end
set_fixed_value(val)
click to toggle source
# File lib/phg_sudoku_solver/cell.rb, line 40 def set_fixed_value(val) @fixed_value = val if val>0 @possible_values = [] end end
set_possible_values(val)
click to toggle source
# File lib/phg_sudoku_solver/cell.rb, line 36 def set_possible_values(val) @possible_values = val end