diff --git a/sources/solver_0hh1.html b/sources/solver_0hh1.html new file mode 100644 index 0000000..d1065d1 --- /dev/null +++ b/sources/solver_0hh1.html @@ -0,0 +1,311 @@ + +Python: module solver_0hh1 + + + + + +
 
+ 
solver_0hh1
index
/home/gaugendre/Projects/python/0hh1-solver/sources/solver_0hh1.py
+

# 0h h1 Solver. Solves grids of 0h h1 game.
+# Copyright (C) 2015  Gabriel Augendre <gabriel@augendre.info>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.

+

+ + + + + +
 
+Modules
       
sys
+

+ + + + + +
 
+Classes
       
+
builtins.object +
+
+
Grid +
Square +
+
+
+

+ + + + + + + +
 
+class Grid(builtins.object)
   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'
+
+

+ + + + + +
 
+Functions
       
non_space_element(line)
Returns the number of non space characters in a string.

+:param line: The line where to count characters.
+:type line: str
+:return: The number of non space characters.
+:rtype: str

+:Example:

+>>> non_space_element('Ceci est un test')
+13
+
solve_three_square(square)
Prevent 'three in a row'.

+Checks before and after the square if there are two squares of the
+same color in order to prevent 'three in a row'.

+:param square: The Square to check
+:type square: Square
+:return: A boolean : True if something has been done, else False.
+:rtype: bool
+
string_from_list(line)
Makes a string from a line of squares.

+:param line: A line (list) of squares to make a string from.
+:type line: list
+:return: A string containing all the states of the squares in the list.
+:rtype: str

+.. warning:: The items of the list must be squares or have an attribute
+              called 'state'.
+

+ + + + + +
 
+Author
       gaugendre
+ \ No newline at end of file diff --git a/sources/solver_0hh1.py b/sources/solver_0hh1.py index 4691d8b..a899162 100644 --- a/sources/solver_0hh1.py +++ b/sources/solver_0hh1.py @@ -27,7 +27,7 @@ def string_from_list(line): :return: A string containing all the states of the squares in the list. :rtype: str - .. warnings:: The items of the list must be squares or have an attribute + .. warning:: The items of the list must be squares or have an attribute called 'state'. """ string = "" @@ -46,6 +46,7 @@ def non_space_element(line): :rtype: str :Example: + >>> non_space_element('Ceci est un test') 13 """ @@ -84,7 +85,7 @@ class Square: :return: The next square, horizontally. :rtype: Square - .. warnings:: The square must be part of a grid + .. warning:: The square must be part of a grid """ if not self.grid or self.horiz == self.grid.size - 1: return None @@ -97,7 +98,7 @@ class Square: :return: The previous square, horizontally. :rtype: Square - .. warnings:: The square must be part of a grid + .. warning:: The square must be part of a grid """ if not self.grid or self.horiz == 0: return None @@ -110,7 +111,7 @@ class Square: :return: The next square, vertically. :rtype: Square - .. warnings:: The square must be part of a grid + .. warning:: The square must be part of a grid """ if not self.grid or self.vert == self.grid.size - 1: return None @@ -123,7 +124,7 @@ class Square: :return: The previous square, vertically. :rtype: Square - .. warnings:: The square must be part of a grid + .. warning:: The square must be part of a grid """ if not self.grid or self.vert == 0: return None @@ -173,10 +174,11 @@ class Square: :rtype: str :Example: + >>> Square(None, 0, 0, 'R').opposite_state() - 'B + 'B' >>> Square(None, 0, 0, ' ').opposite_state() - ' '' + ' ' """ if self.state == 'R': return 'B' @@ -193,6 +195,7 @@ class Square: :rtype: bool :Example: + >>> Square(None, 0, 0, ' ').is_empty() True >>> Square(None, 0, 0, 'R').is_empty() @@ -208,7 +211,7 @@ class Square: :rtype: list .. seealso:: prev_horiz() - .. warnings:: The square must be part of a grid. + .. warning:: The square must be part of a grid. """ h_prev = self.prev_horiz() all_prev_horiz_list = [] @@ -226,7 +229,7 @@ class Square: :rtype: list .. seealso:: next_horiz() - .. warnings:: The square must be part of a grid. + .. warning:: The square must be part of a grid. """ h_next = self.next_horiz() all_next_horiz_list = [] @@ -243,7 +246,7 @@ class Square: :rtype: list .. seealso:: prev_vert() - .. warnings:: The square must be part of a grid. + .. warning:: The square must be part of a grid. """ v_prev = self.prev_vert() all_prev_vert_list = [] @@ -260,7 +263,7 @@ class Square: :rtype: list .. seealso:: next_vert() - .. warnings:: The square must be part of a grid. + .. warning:: The square must be part of a grid. """ v_next = self.next_vert() all_next_vert_list = [] @@ -277,7 +280,7 @@ class Square: :return: The list of the squares in the same line. .. seealso:: all_prev_horiz(), all_next_horiz() - .. warnings:: The square must be part of a grid. + .. warning:: The square must be part of a grid. """ line_list = [] line_list.extend(self.all_prev_horiz()) @@ -293,7 +296,7 @@ class Square: :return: The list of the squares in the same column. .. seealso:: all_prev_vert(), all_next_vert() - .. warnings:: The square must be part of a grid. + .. warning:: The square must be part of a grid. """ line_list = [] line_list.extend(self.all_prev_vert()) @@ -420,7 +423,7 @@ class Grid: :param array: The array to replace the squares. :type array: list - .. warnings:: The array must be a list containing + .. warning:: The array must be a list containing lists of characters (square array). """ squares = [] @@ -564,7 +567,7 @@ class Grid: :return: True if a square has been modified, else False. :rtype: bool - .. warnings:: Function still not finished. DOESN'T WORK. + .. warning:: Function still not finished. DOESN'T WORK. """ for square in self.square_list: line = string_from_list(square.same_line())