311 lines
19 KiB
HTML
311 lines
19 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||
|
<html><head><title>Python: module solver_0hh1</title>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
</head><body bgcolor="#f0f0f8">
|
||
|
|
||
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
|
||
|
<tr bgcolor="#7799ee">
|
||
|
<td valign=bottom> <br>
|
||
|
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>solver_0hh1</strong></big></big></font></td
|
||
|
><td align=right valign=bottom
|
||
|
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/gaugendre/Projects/python/0hh1-solver/sources/solver_0hh1.py">/home/gaugendre/Projects/python/0hh1-solver/sources/solver_0hh1.py</a></font></td></tr></table>
|
||
|
<p><tt># 0h h1 Solver. Solves grids of 0h h1 game.<br>
|
||
|
# Copyright (C) 2015 Gabriel Augendre <gabriel@augendre.info><br>
|
||
|
#<br>
|
||
|
# This program is free software: you can redistribute it and/or modify<br>
|
||
|
# it under the terms of the GNU General Public License as published by<br>
|
||
|
# the Free Software Foundation, either version 3 of the License, or<br>
|
||
|
# (at your option) any later version.<br>
|
||
|
#<br>
|
||
|
# This program is distributed in the hope that it will be useful,<br>
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
|
||
|
# GNU General Public License for more details.<br>
|
||
|
#<br>
|
||
|
# You should have received a copy of the GNU General Public License<br>
|
||
|
# along with this program. If not, see <<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>>.</tt></p>
|
||
|
<p>
|
||
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
||
|
<tr bgcolor="#aa55cc">
|
||
|
<td colspan=3 valign=bottom> <br>
|
||
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
|
||
|
|
||
|
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
|
||
|
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="sys.html">sys</a><br>
|
||
|
</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
|
||
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
||
|
<tr bgcolor="#ee77aa">
|
||
|
<td colspan=3 valign=bottom> <br>
|
||
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
|
||
|
|
||
|
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
|
||
|
<td width="100%"><dl>
|
||
|
<dt><font face="helvetica, arial"><a href="builtins.html#object">builtins.object</a>
|
||
|
</font></dt><dd>
|
||
|
<dl>
|
||
|
<dt><font face="helvetica, arial"><a href="solver_0hh1.html#Grid">Grid</a>
|
||
|
</font></dt><dt><font face="helvetica, arial"><a href="solver_0hh1.html#Square">Square</a>
|
||
|
</font></dt></dl>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<p>
|
||
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
||
|
<tr bgcolor="#ffc8d8">
|
||
|
<td colspan=3 valign=bottom> <br>
|
||
|
<font color="#000000" face="helvetica, arial"><a name="Grid">class <strong>Grid</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
|
||
|
|
||
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
||
|
<td colspan=2><tt>A <a href="#Grid">Grid</a> is a square array containing Squares.<br> </tt></td></tr>
|
||
|
<tr><td> </td>
|
||
|
<td width="100%">Methods defined here:<br>
|
||
|
<dl><dt><a name="Grid-__init__"><strong>__init__</strong></a>(self, size, array=None)</dt><dd><tt>Instantiate a grid from a size and maybe an array of characters.<br>
|
||
|
If an array is provided, the grid will be filled with squares<br>
|
||
|
with state corresponding to the character in the array.<br>
|
||
|
:param size: The size of the grid (either width or length).<br>
|
||
|
:type size: int<br>
|
||
|
:param array: The array used to fill the grid.<br>
|
||
|
:type array: list</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Grid-__repr__"><strong>__repr__</strong></a>(self)</dt></dl>
|
||
|
|
||
|
<dl><dt><a name="Grid-solve"><strong>solve</strong></a>(self)</dt><dd><tt>Solves the grid using 'three in a row', 'same number of red and blue<br>
|
||
|
on the same line or column' and, later, 'no identical line or column'.</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Grid-solve_different_lines_or_columns"><strong>solve_different_lines_or_columns</strong></a>(self)</dt><dd><tt>Solves the grid implementing the fact that there isn't two identical<br>
|
||
|
lines or columns.<br>
|
||
|
<br>
|
||
|
:return: True if a square has been modified, else False.<br>
|
||
|
:rtype: bool<br>
|
||
|
<br>
|
||
|
.. warning:: Function still not finished. DOESN'T WORK.</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Grid-solve_same_number"><strong>solve_same_number</strong></a>(self)</dt><dd><tt>Solves the grid implementing the fact that there is always the same<br>
|
||
|
number of red and blue on the same line or column.<br>
|
||
|
<br>
|
||
|
:return: True if a square has been modified, else False.<br>
|
||
|
:rtype: bool</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Grid-solve_threes"><strong>solve_threes</strong></a>(self)</dt><dd><tt>Solves the grid recursively to prevent 'three in a row'.<br>
|
||
|
<br>
|
||
|
:return: True if a square has been modified, else False.<br>
|
||
|
:rtype: bool</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Grid-square"><strong>square</strong></a>(self, horiz, vert)</dt><dd><tt>Used to get a specific square in the grid.<br>
|
||
|
<br>
|
||
|
:param horiz: The horizontal position of the square to get.<br>
|
||
|
:type horiz: int<br>
|
||
|
:param vert: The vertical position of the square to get.<br>
|
||
|
:type vert: int<br>
|
||
|
:return: The square at the given position<br>
|
||
|
:rtype: <a href="#Square">Square</a></tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Grid-squares_on_column"><strong>squares_on_column</strong></a>(self, col_number)</dt><dd><tt>Returns the squares on a column specified by the number<br>
|
||
|
(starting from zero).<br>
|
||
|
<br>
|
||
|
:param col_number: The column to get.<br>
|
||
|
:type col_number: int<br>
|
||
|
:return: The list containing the squares on the required column.<br>
|
||
|
:rtype: list</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Grid-squares_on_line"><strong>squares_on_line</strong></a>(self, line_number)</dt><dd><tt>Returns the squares on a line specified by the number<br>
|
||
|
(starting from zero).<br>
|
||
|
<br>
|
||
|
:param line_number: The line to get.<br>
|
||
|
:type line_number: int<br>
|
||
|
:return: The list containing the squares on the required line.<br>
|
||
|
:rtype: list</tt></dd></dl>
|
||
|
|
||
|
<hr>
|
||
|
Data descriptors defined here:<br>
|
||
|
<dl><dt><strong>__dict__</strong></dt>
|
||
|
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
|
||
|
</dl>
|
||
|
<dl><dt><strong>__weakref__</strong></dt>
|
||
|
<dd><tt>list of weak references to the object (if defined)</tt></dd>
|
||
|
</dl>
|
||
|
<dl><dt><strong>squares</strong></dt>
|
||
|
<dd><tt>A method to get the squares in the grid.<br>
|
||
|
:return: The squares in the grid.<br>
|
||
|
:rtype: list</tt></dd>
|
||
|
</dl>
|
||
|
</td></tr></table> <p>
|
||
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
||
|
<tr bgcolor="#ffc8d8">
|
||
|
<td colspan=3 valign=bottom> <br>
|
||
|
<font color="#000000" face="helvetica, arial"><a name="Square">class <strong>Square</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
|
||
|
|
||
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
||
|
<td colspan=2><tt>Represents a square in the grid.<br>
|
||
|
A square can be either Red, Blue, or Nothing, depending on the text<br>
|
||
|
written in it and displayed ('R', 'B' or ' ').<br> </tt></td></tr>
|
||
|
<tr><td> </td>
|
||
|
<td width="100%">Methods defined here:<br>
|
||
|
<dl><dt><a name="Square-__eq__"><strong>__eq__</strong></a>(self, other)</dt></dl>
|
||
|
|
||
|
<dl><dt><a name="Square-__hash__"><strong>__hash__</strong></a>(self)</dt></dl>
|
||
|
|
||
|
<dl><dt><a name="Square-__init__"><strong>__init__</strong></a>(self, grid, vert, horiz, state=' ', base=False)</dt></dl>
|
||
|
|
||
|
<dl><dt><a name="Square-__repr__"><strong>__repr__</strong></a>(self)</dt></dl>
|
||
|
|
||
|
<dl><dt><a name="Square-all_next_horiz"><strong>all_next_horiz</strong></a>(self)</dt><dd><tt>Get the list of all next squares, horizontally.<br>
|
||
|
<br>
|
||
|
:return: A list containing all the next squares horizontally.<br>
|
||
|
:rtype: list<br>
|
||
|
<br>
|
||
|
.. seealso:: <a href="#Square-next_horiz">next_horiz</a>()<br>
|
||
|
.. warning:: The square must be part of a grid.</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Square-all_next_vert"><strong>all_next_vert</strong></a>(self)</dt><dd><tt>Get the list of all next squares, vertically.<br>
|
||
|
<br>
|
||
|
:return: A list containing all the next squares vertically.<br>
|
||
|
:rtype: list<br>
|
||
|
<br>
|
||
|
.. seealso:: <a href="#Square-next_vert">next_vert</a>()<br>
|
||
|
.. warning:: The square must be part of a grid.</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Square-all_prev_horiz"><strong>all_prev_horiz</strong></a>(self)</dt><dd><tt>Get the list of all previous squares, horizontally.<br>
|
||
|
<br>
|
||
|
:return: A list containing all the previous squares horizontally.<br>
|
||
|
:rtype: list<br>
|
||
|
<br>
|
||
|
.. seealso:: <a href="#Square-prev_horiz">prev_horiz</a>()<br>
|
||
|
.. warning:: The square must be part of a grid.</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Square-all_prev_vert"><strong>all_prev_vert</strong></a>(self)</dt><dd><tt>Get the list of all previous squares, vertically.<br>
|
||
|
<br>
|
||
|
:return: A list containing all the previous squares vertically.<br>
|
||
|
:rtype: list<br>
|
||
|
<br>
|
||
|
.. seealso:: <a href="#Square-prev_vert">prev_vert</a>()<br>
|
||
|
.. warning:: The square must be part of a grid.</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Square-is_empty"><strong>is_empty</strong></a>(self)</dt><dd><tt>Simply tells if the square contains nothing or not.<br>
|
||
|
<br>
|
||
|
:return: True if the square contains ' ', else False.<br>
|
||
|
:rtype: bool<br>
|
||
|
<br>
|
||
|
:Example:<br>
|
||
|
<br>
|
||
|
>>> <a href="#Square">Square</a>(None, 0, 0, ' ').<a href="#Square-is_empty">is_empty</a>()<br>
|
||
|
True<br>
|
||
|
>>> <a href="#Square">Square</a>(None, 0, 0, 'R').<a href="#Square-is_empty">is_empty</a>()<br>
|
||
|
False</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Square-next_horiz"><strong>next_horiz</strong></a>(self)</dt><dd><tt>A method to get the next square horizontally.<br>
|
||
|
<br>
|
||
|
:return: The next square, horizontally.<br>
|
||
|
:rtype: <a href="#Square">Square</a><br>
|
||
|
<br>
|
||
|
.. warning:: The square must be part of a grid</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Square-next_vert"><strong>next_vert</strong></a>(self)</dt><dd><tt>A method to get the next square vertically.<br>
|
||
|
<br>
|
||
|
:return: The next square, vertically.<br>
|
||
|
:rtype: <a href="#Square">Square</a><br>
|
||
|
<br>
|
||
|
.. warning:: The square must be part of a grid</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Square-opposite_state"><strong>opposite_state</strong></a>(self)</dt><dd><tt>Returns the opposite state of the current <a href="#Square">Square</a>.<br>
|
||
|
<br>
|
||
|
The opposite state of 'R' is 'B', and vice-versa.<br>
|
||
|
The opposite state of ' ' is ' '.<br>
|
||
|
<br>
|
||
|
:return: The opposite state of the current square.<br>
|
||
|
:rtype: str<br>
|
||
|
<br>
|
||
|
:Example:<br>
|
||
|
<br>
|
||
|
>>> <a href="#Square">Square</a>(None, 0, 0, 'R').<a href="#Square-opposite_state">opposite_state</a>()<br>
|
||
|
'B'<br>
|
||
|
>>> <a href="#Square">Square</a>(None, 0, 0, ' ').<a href="#Square-opposite_state">opposite_state</a>()<br>
|
||
|
' '</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Square-prev_horiz"><strong>prev_horiz</strong></a>(self)</dt><dd><tt>A method to get the previous square horizontally.<br>
|
||
|
<br>
|
||
|
:return: The previous square, horizontally.<br>
|
||
|
:rtype: <a href="#Square">Square</a><br>
|
||
|
<br>
|
||
|
.. warning:: The square must be part of a grid</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Square-prev_vert"><strong>prev_vert</strong></a>(self)</dt><dd><tt>A method to get the previous square vertically.<br>
|
||
|
<br>
|
||
|
:return: The previous square, vertically.<br>
|
||
|
:rtype: <a href="#Square">Square</a><br>
|
||
|
<br>
|
||
|
.. warning:: The square must be part of a grid</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Square-same_column"><strong>same_column</strong></a>(self)</dt><dd><tt>List of squares in the same column.<br>
|
||
|
Does not include the considered square.<br>
|
||
|
<br>
|
||
|
:return: The list of the squares in the same column.<br>
|
||
|
<br>
|
||
|
.. seealso:: <a href="#Square-all_prev_vert">all_prev_vert</a>(), <a href="#Square-all_next_vert">all_next_vert</a>()<br>
|
||
|
.. warning:: The square must be part of a grid.</tt></dd></dl>
|
||
|
|
||
|
<dl><dt><a name="Square-same_line"><strong>same_line</strong></a>(self)</dt><dd><tt>List of squares in the same line.<br>
|
||
|
Does not include the considered square.<br>
|
||
|
<br>
|
||
|
:return: The list of the squares in the same line.<br>
|
||
|
<br>
|
||
|
.. seealso:: <a href="#Square-all_prev_horiz">all_prev_horiz</a>(), <a href="#Square-all_next_horiz">all_next_horiz</a>()<br>
|
||
|
.. warning:: The square must be part of a grid.</tt></dd></dl>
|
||
|
|
||
|
<hr>
|
||
|
Data descriptors defined here:<br>
|
||
|
<dl><dt><strong>__dict__</strong></dt>
|
||
|
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
|
||
|
</dl>
|
||
|
<dl><dt><strong>__weakref__</strong></dt>
|
||
|
<dd><tt>list of weak references to the object (if defined)</tt></dd>
|
||
|
</dl>
|
||
|
<dl><dt><strong>state</strong></dt>
|
||
|
<dd><tt>Allow to get square state.<br>
|
||
|
<br>
|
||
|
:return: The square state. Either ' ', 'R' or 'B'</tt></dd>
|
||
|
</dl>
|
||
|
</td></tr></table></td></tr></table><p>
|
||
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
||
|
<tr bgcolor="#eeaa77">
|
||
|
<td colspan=3 valign=bottom> <br>
|
||
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
|
||
|
|
||
|
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
|
||
|
<td width="100%"><dl><dt><a name="-non_space_element"><strong>non_space_element</strong></a>(line)</dt><dd><tt>Returns the number of non space characters in a string.<br>
|
||
|
<br>
|
||
|
:param line: The line where to count characters.<br>
|
||
|
:type line: str<br>
|
||
|
:return: The number of non space characters.<br>
|
||
|
:rtype: str<br>
|
||
|
<br>
|
||
|
:Example:<br>
|
||
|
<br>
|
||
|
>>> <a href="#-non_space_element">non_space_element</a>('Ceci est un test')<br>
|
||
|
13</tt></dd></dl>
|
||
|
<dl><dt><a name="-solve_three_square"><strong>solve_three_square</strong></a>(square)</dt><dd><tt>Prevent 'three in a row'.<br>
|
||
|
<br>
|
||
|
Checks before and after the square if there are two squares of the<br>
|
||
|
same color in order to prevent 'three in a row'.<br>
|
||
|
<br>
|
||
|
:param square: The <a href="#Square">Square</a> to check<br>
|
||
|
:type square: <a href="#Square">Square</a><br>
|
||
|
:return: A boolean : True if something has been done, else False.<br>
|
||
|
:rtype: bool</tt></dd></dl>
|
||
|
<dl><dt><a name="-string_from_list"><strong>string_from_list</strong></a>(line)</dt><dd><tt>Makes a string from a line of squares.<br>
|
||
|
<br>
|
||
|
:param line: A line (list) of squares to make a string from.<br>
|
||
|
:type line: list<br>
|
||
|
:return: A string containing all the states of the squares in the list.<br>
|
||
|
:rtype: str<br>
|
||
|
<br>
|
||
|
.. warning:: The items of the list must be squares or have an attribute<br>
|
||
|
called 'state'.</tt></dd></dl>
|
||
|
</td></tr></table><p>
|
||
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
||
|
<tr bgcolor="#7799ee">
|
||
|
<td colspan=3 valign=bottom> <br>
|
||
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
|
||
|
|
||
|
<tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td>
|
||
|
<td width="100%">gaugendre</td></tr></table>
|
||
|
</body></html>
|