Package sudoku :: Module cell :: Class Cell
[hide private]
[frames] | no frames]

Class Cell

object --+
         |
        Cell

The class Cell represents cells on a Sudoku chart. Each cell can have a positive integer stored in it, or be empty.

As long as a cell is empty, the cell object keeps track of the possible placing options that are available for the cell. That is, each cell knows which numbers can be legally placed in the cell (as per Sudoku game rules). Initially, the available placing options include consist of all the numbers from 1 to the size of the Sudoku chart the options can be reduced with the method remove_option.


See Also: Chart

Instance Methods [hide private]
 
__init__(self, chart_size)
Creates a new empty cell which has all the positive integers from 1 to the given chart size as possible options to fill the cell with.
int
get_number(self)
Returns the number in this cell, if there is one.
boolean
is_empty(self)
Determines if the cell is empty.
 
remove_option(self, option)
Marks the given number as no longer being a possible option for filling the cell.
boolean
set_number(self, number)
Fills the cell with the given number.
boolean
is_option(self, candidate)
Determines if the given number can be placed in the cell, i.e., if the number has not been marked with remove_option.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, chart_size)
(Constructor)

 

Creates a new empty cell which has all the positive integers from 1 to the given chart size as possible options to fill the cell with.

Parameters:
  • chart_size (int) - the size of the Sudoku chart the cell is in
Overrides: object.__init__

get_number(self)

 

Returns the number in this cell, if there is one.

Returns: int
cell contents, or a non-positive number if the cell is empty

is_empty(self)

 

Determines if the cell is empty.

Returns: boolean
a boolean value indicating if the cell is empty

remove_option(self, option)

 

Marks the given number as no longer being a possible option for filling the cell. (This method should be called when other cells on the same line or in the same region are filled, making it impossible to use the same number for this cell.)

Parameters:
  • option (int) - a number which can not be placed in the cell (must be between 1 and chart size)

set_number(self, number)

 

Fills the cell with the given number. This can only be done if the given number is one of the viable options for this cell.

Parameters:
  • number (int) - a number to be placed in the cell (must be between 1 and chart size)
Returns: boolean
a boolean value indicating if the operation was successful

See Also: #is_option

is_option(self, candidate)

 

Determines if the given number can be placed in the cell, i.e., if the number has not been marked with remove_option.

Parameters:
  • candidate (int) - a number between 1 and chart size
Returns: boolean
a boolean value indicating if the given candidate could be placed in the cell
See Also:
#remove_option(int), #set_oumber(int)