From b54325a48b1afb8d5f7a25e32afc062aa82aaf17 Mon Sep 17 00:00:00 2001 From: Joe Anderson Date: Wed, 10 Feb 2016 17:34:28 -0800 Subject: started ooPuzzle.is_solved --- oo.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) 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. -- cgit v1.2.3-70-g09d2