summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Anderson <jandew+dev@gmail.com>2016-02-10 17:34:28 -0800
committerJoe Anderson <jandew+dev@gmail.com>2016-02-10 17:34:28 -0800
commitb54325a48b1afb8d5f7a25e32afc062aa82aaf17 (patch)
tree33553fec3bc6df922208a0b473c6906d2be648d7
parent23371ad2a17c099d0eec2d7ed962f8d2e2257ffc (diff)
downloadoo-b54325a48b1afb8d5f7a25e32afc062aa82aaf17.tar.gz
oo-b54325a48b1afb8d5f7a25e32afc062aa82aaf17.zip
started ooPuzzle.is_solved
-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.