| |
- builtins.object
-
- Grid
- Square
class Grid(builtins.object) |
|
A Grid is a square array containing Squares. |
|
Methods defined here:
- __init__(self, size, array=None)
- Instantiate a grid from a size and maybe an array of characters.
If an array is provided, the grid will be filled with squares
with state corresponding to the character in the array.
:param size: The size of the grid (either width or length).
:type size: int
:param array: The array used to fill the grid.
:type array: list
- __repr__(self)
- solve(self)
- Solves the grid using 'three in a row', 'same number of red and blue
on the same line or column' and, later, 'no identical line or column'.
- solve_different_lines_or_columns(self)
- Solves the grid implementing the fact that there isn't two identical
lines or columns.
:return: True if a square has been modified, else False.
:rtype: bool
.. warning:: Function still not finished. DOESN'T WORK.
- solve_same_number(self)
- Solves the grid implementing the fact that there is always the same
number of red and blue on the same line or column.
:return: True if a square has been modified, else False.
:rtype: bool
- solve_threes(self)
- Solves the grid recursively to prevent 'three in a row'.
:return: True if a square has been modified, else False.
:rtype: bool
- square(self, horiz, vert)
- Used to get a specific square in the grid.
:param horiz: The horizontal position of the square to get.
:type horiz: int
:param vert: The vertical position of the square to get.
:type vert: int
:return: The square at the given position
:rtype: Square
- squares_on_column(self, col_number)
- Returns the squares on a column specified by the number
(starting from zero).
:param col_number: The column to get.
:type col_number: int
:return: The list containing the squares on the required column.
:rtype: list
- squares_on_line(self, line_number)
- Returns the squares on a line specified by the number
(starting from zero).
:param line_number: The line to get.
:type line_number: int
:return: The list containing the squares on the required line.
:rtype: list
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- squares
- A method to get the squares in the grid.
:return: The squares in the grid.
:rtype: list
|
class Square(builtins.object) |
|
Represents a square in the grid.
A square can be either Red, Blue, or Nothing, depending on the text
written in it and displayed ('R', 'B' or ' '). |
|
Methods defined here:
- __eq__(self, other)
- __hash__(self)
- __init__(self, grid, vert, horiz, state=' ', base=False)
- __repr__(self)
- all_next_horiz(self)
- Get the list of all next squares, horizontally.
:return: A list containing all the next squares horizontally.
:rtype: list
.. seealso:: next_horiz()
.. warning:: The square must be part of a grid.
- all_next_vert(self)
- Get the list of all next squares, vertically.
:return: A list containing all the next squares vertically.
:rtype: list
.. seealso:: next_vert()
.. warning:: The square must be part of a grid.
- all_prev_horiz(self)
- Get the list of all previous squares, horizontally.
:return: A list containing all the previous squares horizontally.
:rtype: list
.. seealso:: prev_horiz()
.. warning:: The square must be part of a grid.
- all_prev_vert(self)
- Get the list of all previous squares, vertically.
:return: A list containing all the previous squares vertically.
:rtype: list
.. seealso:: prev_vert()
.. warning:: The square must be part of a grid.
- is_empty(self)
- Simply tells if the square contains nothing or not.
:return: True if the square contains ' ', else False.
:rtype: bool
:Example:
>>> Square(None, 0, 0, ' ').is_empty()
True
>>> Square(None, 0, 0, 'R').is_empty()
False
- next_horiz(self)
- A method to get the next square horizontally.
:return: The next square, horizontally.
:rtype: Square
.. warning:: The square must be part of a grid
- next_vert(self)
- A method to get the next square vertically.
:return: The next square, vertically.
:rtype: Square
.. warning:: The square must be part of a grid
- opposite_state(self)
- Returns the opposite state of the current Square.
The opposite state of 'R' is 'B', and vice-versa.
The opposite state of ' ' is ' '.
:return: The opposite state of the current square.
:rtype: str
:Example:
>>> Square(None, 0, 0, 'R').opposite_state()
'B'
>>> Square(None, 0, 0, ' ').opposite_state()
' '
- prev_horiz(self)
- A method to get the previous square horizontally.
:return: The previous square, horizontally.
:rtype: Square
.. warning:: The square must be part of a grid
- prev_vert(self)
- A method to get the previous square vertically.
:return: The previous square, vertically.
:rtype: Square
.. warning:: The square must be part of a grid
- same_column(self)
- List of squares in the same column.
Does not include the considered square.
:return: The list of the squares in the same column.
.. seealso:: all_prev_vert(), all_next_vert()
.. warning:: The square must be part of a grid.
- same_line(self)
- List of squares in the same line.
Does not include the considered square.
:return: The list of the squares in the same line.
.. seealso:: all_prev_horiz(), all_next_horiz()
.. warning:: The square must be part of a grid.
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- state
- Allow to get square state.
:return: The square state. Either ' ', 'R' or 'B'
| |