Class: Binary_Puzzle_Solver::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/binary_puzzle_solver/base.rb

Constant Summary collapse

UNKNOWN =
-1
ZERO =
0
ONE =
1
VALID_STATES =
{UNKNOWN => true, ZERO => true, ONE => true}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Cell

Returns a new instance of Cell.



62
63
64
65
66
67
68
69
# File 'lib/binary_puzzle_solver/base.rb', line 62

def initialize (params={})
    @state = UNKNOWN
    if params.has_key?('state') then
        set_state(params[:state])
    end

    return
end

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



60
61
62
# File 'lib/binary_puzzle_solver/base.rb', line 60

def state
  @state
end

Class Method Details

.get_state_char(val) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/binary_puzzle_solver/base.rb', line 83

def self.get_state_char(val)
    if val == ZERO
        return '0'
    elsif val == ONE
        return '1'
    else
        raise RuntimeError, "get_state_char() called on Unset state"
    end
end

Instance Method Details

#get_charObject



93
94
95
# File 'lib/binary_puzzle_solver/base.rb', line 93

def get_char()
    return Cell.get_state_char(state)
end

#set_state(new_state) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/binary_puzzle_solver/base.rb', line 71

def set_state (new_state)
    if (not VALID_STATES.has_key?(new_state))
        raise RuntimeError, "Invalid state " + new_state.to_s;
    end
    if (@state != UNKNOWN)
        raise RuntimeError, "Cannot reassign a value to the already set state."
    end
    @state = new_state

    return
end