summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--oo.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/oo.py b/oo.py
index 158e404..67bf51b 100644
--- a/oo.py
+++ b/oo.py
@@ -176,7 +176,37 @@ class ooPuzzle:
def is_solved(self):
"""Checks whether the puzzle is in a solved state."""
- pass
+
+ # check internal edge pairs
+
+ for x in range(self.X - 1):
+ for y in range(self.Y - 1):
+
+ # check horizontal edge pair right of (x, y)
+
+ l_piece = self.pieces [x, y]
+ l_orient = self.orients[x, y]
+ r_piece = self.pieces [x+1, y]
+ r_orient = self.orients[x+1, y]
+ l_edge = self.PIECE_ORIENT_TO_EDGES[l_piece, l_orient][2]
+ r_edge = self.PIECE_ORIENT_TO_EDGES[r_piece, r_orient][0]
+ if l_edge != r_edge: return False
+
+ # check vertical edge pair below (x, y)
+
+ u_piece = self.pieces [x, y]
+ u_orient = self.orients[x, y]
+ d_piece = self.pieces [x, y+1]
+ d_orient = self.orients[x, y+1]
+ u_edge = self.PIECE_ORIENT_TO_EDGES[u_piece, u_orient][3]
+ d_edge = self.PIECE_ORIENT_TO_EDGES[d_piece, d_orient][1]
+ if u_edge != d_edge: return False
+
+ # check boundary edge pairs
+
+ #TODO: check boundary edges dependent on toroidal
+
+ return True
class ooPlay:
"""Encapsulates an oo game instance.