Class: SudokuSolver::Grid

Inherits:
CellularMap::Zone
  • Object
show all
Defined in:
lib/sudoku_solver/grid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dimension) ⇒ Grid

Returns a new instance of Grid.



21
22
23
24
25
26
27
# File 'lib/sudoku_solver/grid.rb', line 21

def initialize(dimension)
  @dimension = dimension
  @width = @dimension ** 2
  @size = (0..(@width - 1))
  @possibilities = (1..@width)
  super(@size, @size, CellularMap::Map.new)
end

Instance Attribute Details

#dimensionObject (readonly)

Returns the value of attribute dimension.



19
20
21
# File 'lib/sudoku_solver/grid.rb', line 19

def dimension
  @dimension
end

#possibilitiesObject (readonly)

Returns the value of attribute possibilities.



19
20
21
# File 'lib/sudoku_solver/grid.rb', line 19

def possibilities
  @possibilities
end

#sizeObject (readonly)

Returns the value of attribute size.



19
20
21
# File 'lib/sudoku_solver/grid.rb', line 19

def size
  @size
end

Instance Method Details

#[](x, y) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/sudoku_solver/grid.rb', line 29

def [](x, y)
  cell = super
  if cell.is_a? CellularMap::Cell
    cell.extend Cell
    cell.grid = self
  end
  cell
end

#eachObject

:nodoc:



38
39
40
41
42
43
44
45
46
# File 'lib/sudoku_solver/grid.rb', line 38

def each # :nodoc:
  super { |cell|
    if cell.is_a? CellularMap::Cell
      cell.extend Cell
      cell.grid = self
    end
    yield cell
  }
end

#solved?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/sudoku_solver/grid.rb', line 48

def solved?
  ! self.detect { |c| c.content.nil? || c.content.length != 1 }
end