Class: SudokuSolver::Grid
- Inherits:
-
CellularMap::Zone
- Object
- CellularMap::Zone
- SudokuSolver::Grid
- Defined in:
- lib/sudoku_solver/grid.rb
Instance Attribute Summary collapse
-
#dimension ⇒ Object
readonly
Returns the value of attribute dimension.
-
#possibilities ⇒ Object
readonly
Returns the value of attribute possibilities.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #[](x, y) ⇒ Object
-
#each ⇒ Object
:nodoc:.
-
#initialize(dimension) ⇒ Grid
constructor
A new instance of Grid.
- #solved? ⇒ Boolean
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
#dimension ⇒ Object (readonly)
Returns the value of attribute dimension.
19 20 21 |
# File 'lib/sudoku_solver/grid.rb', line 19 def dimension @dimension end |
#possibilities ⇒ Object (readonly)
Returns the value of attribute possibilities.
19 20 21 |
# File 'lib/sudoku_solver/grid.rb', line 19 def possibilities @possibilities end |
#size ⇒ Object (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 |
#each ⇒ Object
: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
48 49 50 |
# File 'lib/sudoku_solver/grid.rb', line 48 def solved? ! self.detect { |c| c.content.nil? || c.content.length != 1 } end |