Class: Rudoku::Field
- Inherits:
-
Object
- Object
- Rudoku::Field
- Defined in:
- lib/rudoku.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#value ⇒ Object
Returns the value of attribute value.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #add(v) ⇒ Object
- #available_nrs ⇒ Object
-
#initialize(board, i, x, y) ⇒ Field
constructor
A new instance of Field.
- #mark ⇒ Object
- #marked? ⇒ Boolean
- #missing? ⇒ Boolean
- #nr_only_possible_in_this_field ⇒ Object
- #remove(v) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(board, i, x, y) ⇒ Field
Returns a new instance of Field.
199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/rudoku.rb', line 199 def initialize(board, i, x, y) @board = board @index = i @x = x @y = y @marked = false @row = @board.get_row(y) or raise @col = @board.get_col(x) or raise @block = @board.get_block(x, y) or raise end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
197 198 199 |
# File 'lib/rudoku.rb', line 197 def block @block end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
197 198 199 |
# File 'lib/rudoku.rb', line 197 def index @index end |
#value ⇒ Object
Returns the value of attribute value.
197 198 199 |
# File 'lib/rudoku.rb', line 197 def value @value end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
197 198 199 |
# File 'lib/rudoku.rb', line 197 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
197 198 199 |
# File 'lib/rudoku.rb', line 197 def y @y end |
Instance Method Details
#add(v) ⇒ Object
236 237 238 239 240 |
# File 'lib/rudoku.rb', line 236 def add(v) @block.add(v) @row.add(v) @col.add(v) end |
#available_nrs ⇒ Object
246 247 248 |
# File 'lib/rudoku.rb', line 246 def available_nrs @row.available_nrs & @col.available_nrs & @block.available_nrs end |
#mark ⇒ Object
211 212 213 |
# File 'lib/rudoku.rb', line 211 def mark @marked = true end |
#marked? ⇒ Boolean
215 216 217 |
# File 'lib/rudoku.rb', line 215 def marked? @marked end |
#missing? ⇒ Boolean
242 243 244 |
# File 'lib/rudoku.rb', line 242 def missing? @value.nil? end |
#nr_only_possible_in_this_field ⇒ Object
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/rudoku.rb', line 254 def nr_only_possible_in_this_field neighbours = block.missing_fields.reject{|m| m == self} available_nrs.each do |nr| # iterate over all neighbours and check if theres a Nr (nr) # which can't be anywere else if neighbours.all?{|n| not n.available_nrs.include?(nr) } # okay, nr isn't possible in all the other missing # fields in the neighbourhood, that means it can only be # on f return nr end end nil end |
#remove(v) ⇒ Object
230 231 232 233 234 |
# File 'lib/rudoku.rb', line 230 def remove(v) @block.remove(v) @row.remove(v) @col.remove(v) end |
#to_s ⇒ Object
250 251 252 |
# File 'lib/rudoku.rb', line 250 def to_s x.to_s + ":" + y.to_s end |