solver-0h-h1/sources/Square.py

63 lines
1.8 KiB
Python
Raw Normal View History

2014-12-30 14:49:38 +01:00
# 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/>.
2014-12-30 14:47:47 +01:00
__author__ = 'gaugendre'
class Square:
"""
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 ' ').
"""
def __init__(self, horiz, vert):
self.horiz = horiz
self.vert = vert
def get_next_horiz(self):
return Square(self.horiz + 1, self.vert)
def get_prev_horiz(self):
return Square(self.horiz - 1, self.vert)
def get_next_vert(self):
return Square(self.horiz, self.vert + 1)
def get_prev_vert(self):
return Square(self.horiz, self.vert - 1)
def __eq__(self, other):
if other is None or not isinstance(other, Square):
return False
else:
return self.vert == other.vert and self.horiz == other.horiz
def __hash__(self):
return hash((self.horiz, self.vert))
def solve(grid):
for char in grid:
pass
grid = [['R', ' ', ' ', 'R'],
['R', ' ', 'B', ' '],
[' ', 'R', ' ', ' '],
[' ', ' ', ' ', ' ']]