Class: Binary_Puzzle_Solver::RowSummary
- Inherits:
-
Object
- Object
- Binary_Puzzle_Solver::RowSummary
- Defined in:
- lib/binary_puzzle_solver/base.rb
Overview
A summary for a row or column.
Instance Attribute Summary collapse
-
#half_limit ⇒ Object
readonly
Returns the value of attribute half_limit.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
Instance Method Summary collapse
- #are_both_full ⇒ Object
- #are_both_not_exceeded ⇒ Object
- #find_full_value ⇒ Object
- #get_count(value) ⇒ Object
- #inc_count(value) ⇒ Object
-
#initialize(limit) ⇒ RowSummary
constructor
A new instance of RowSummary.
- #is_full(value) ⇒ Object
Constructor Details
#initialize(limit) ⇒ RowSummary
Returns a new instance of RowSummary.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/binary_puzzle_solver/base.rb', line 101 def initialize (limit) @limit = limit if (limit % 2 != 0) raise RuntimeError, "Limit must be even" end @half_limit = limit / 2 @counts = { Cell::ZERO => 0, Cell::ONE => 0, } return end |
Instance Attribute Details
#half_limit ⇒ Object (readonly)
Returns the value of attribute half_limit.
100 101 102 |
# File 'lib/binary_puzzle_solver/base.rb', line 100 def half_limit @half_limit end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
100 101 102 |
# File 'lib/binary_puzzle_solver/base.rb', line 100 def limit @limit end |
Instance Method Details
#are_both_full ⇒ Object
141 142 143 |
# File 'lib/binary_puzzle_solver/base.rb', line 141 def are_both_full() return (is_full(Cell::ZERO) and is_full(Cell::ONE)) end |
#are_both_not_exceeded ⇒ Object
136 137 138 139 |
# File 'lib/binary_puzzle_solver/base.rb', line 136 def are_both_not_exceeded() return (get_count(Cell::ZERO) <= half_limit() and get_count(Cell::ONE) <= half_limit()) end |
#find_full_value ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/binary_puzzle_solver/base.rb', line 145 def find_full_value() if are_both_full() return nil elsif (is_full(Cell::ZERO)) return Cell::ZERO elsif (is_full(Cell::ONE)) return Cell::ONE else return nil end end |
#get_count(value) ⇒ Object
118 119 120 |
# File 'lib/binary_puzzle_solver/base.rb', line 118 def get_count (value) return @counts[value] end |
#inc_count(value) ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/binary_puzzle_solver/base.rb', line 126 def inc_count (value) new_val = (@counts[value] += 1) if (new_val > half_limit()) raise GameIntegrityException, "Too many #{value}" end return end |
#is_full(value) ⇒ Object
122 123 124 |
# File 'lib/binary_puzzle_solver/base.rb', line 122 def is_full(value) return (get_count(value) == half_limit()) end |