Loading controller/binaryTreeToPlanarTree.py +2 −2 Changes for controller/binaryTreeToPlanarTree.py: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -41,8 +41,8 @@ class BinaryTreeToPlanarTree: def addNode(self, index: int, nodeType: str): if self.level.checkTree(index, nodeType): self.levelGui.planarTreeView.createTree() """if self.level.finished(): self.levelGui.finish()""" if self.level.finished(): self.levelGui.finish() else: self.levelGui.error(index, nodeType) Loading model/levelBinaryTreeToPlanarTree.py +5 −5 Changes for model/levelBinaryTreeToPlanarTree.py: 5 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ class LevelBinaryTreeToPlanarTree: self.index = index self.answer = getTree(index) self.planarAnswer = Tree(binaryTreeToPlanarTree(self.answer.root)) self.answer = self.planarAnswer self.tree = None self.score = None self.initialize() Loading @@ -29,15 +30,14 @@ class LevelBinaryTreeToPlanarTree: def checkTree(self, index: int, nodeType: str): copy = self.tree.copyTree() copy.completeNode(index, nodeType) print("checckkkk") """print("-----------------------") print(self.planarAnswer.root) print(copy.root) """if self.planarAnswer.root.checkNode(copy.root):""" if 1: print(copy.root)""" if self.planarAnswer.root.checkNode(copy.root): self.tree.completeNode(index, nodeType) return True else: return False def finished(self): return self.tree.root.isEqual(self.answer.root) return self.planarAnswer.root.isEqual(self.tree.root) model/node.py +72 −24 Changes for model/node.py: 72 added lines, 24 removed lines. Original line number Diff line number Diff line Loading @@ -345,6 +345,46 @@ class PlanarNode(Node): child.completeNode(index, nodeType, tree) def checkNode(self, node, nodeBrothers=None, brothers=None): print("node: ") print(node) print(self) if brothers is None: brothers = [] if nodeBrothers is None: nodeBrothers = [] if not isinstance(node, IncompleteNode): if len(self.children) != len(node.children): print("AAAAAAAAAAA") return False else: if len(self.children) < len(node.children): print("BBBBBBBBBB") return False if not self.children: if brothers: if not nodeBrothers: return True else: return brothers.pop(0).checkNode(nodeBrothers.pop(0), nodeBrothers, brothers) else: return True else: if not node.children: if brothers: if not nodeBrothers: return True else: return brothers.pop(0).checkNode(nodeBrothers.pop(0), nodeBrothers, brothers) else: return True else: newBrothers = self.children[1:] + brothers newNodeBrothers = node.children[1:] + nodeBrothers return self.children[0].checkNode(node.children[0], newNodeBrothers, newBrothers) def isEqual(self, node, nodeBrothers=None, brothers=None): if brothers is None: brothers = [] if nodeBrothers is None: Loading @@ -360,12 +400,12 @@ class PlanarNode(Node): if not nodeBrothers: return False else: return brothers.pop(0).checkNode(nodeBrothers.pop(0), nodeBrothers, brothers) return brothers.pop(0).isEqual(nodeBrothers.pop(0), nodeBrothers, brothers) else: if nodeBrothers: return True else: return False else: return True else: if len(self.children) == len(node.children): newBrothers = self.children[1:] + brothers Loading @@ -373,10 +413,23 @@ class PlanarNode(Node): if len(newNodeBrothers) != len(newBrothers): return False else: return self.children[0].numberNodes(node.children[0], newNodeBrothers, newBrothers) return self.children[0].isEqual(node.children[0], newNodeBrothers, newBrothers) else: return False """def isEqual(self, node): if isinstance(node, EmptyNode): return False elif len(self.children) != len(node.children): return False elif len(self.children) == 0: return True else: answer = True for i in range(len(self.children)): answer = answer and self.children[i].isEqual(node.children[i]) return answer""" def setup(self, depth=0, places=None, offsets=None): nb_children = len(self.children) if places is None: Loading Loading @@ -437,20 +490,7 @@ class PlanarNode(Node): else: return self.right.addNode(self.left.addNode(index, nodeType), nodeType) def isEqual(self, node): if isinstance(node, EmptyNode): return False elif len(self.children) != len(node.children): return False elif len(self.children) == 0: return True else: answer = True for i in range(len(self.children)): answer = answer and self.children[i].isEqual(node.children[i]) return answer def checkNode(self, answer): """def checkNode(self, answer): if isinstance(answer, EmptyNode): return True elif len(self.children) != len(answer.children): Loading @@ -465,7 +505,7 @@ class PlanarNode(Node): test = True for i in range(len(self.children)): test = test and self.children[i].isEqual(answer.children[i]) return test return test""" def getDepth(self): """ Loading Loading @@ -496,6 +536,14 @@ class IncompleteNode(PlanarNode): self.offset = 0 self.parent = None self.index = None for i in range(len(self.children)): self.children[i].setParent(self, i) def copyNode(self): copyChildren = [] for child in self.children: copyChildren.append(child.copyNode()) return IncompleteNode(copyChildren) def setParent(self, node, index): """ Loading @@ -515,8 +563,6 @@ class IncompleteNode(PlanarNode): brothers.pop(0).numberNodes(index + 1, brothers) else: newBrothers = self.children[1:] + brothers print("B") print(self.children[0]) self.children[0].numberNodes(index + 1, newBrothers) def completeNode(self, index: int, nodeType: str, tree): Loading @@ -524,6 +570,8 @@ class IncompleteNode(PlanarNode): if nodeType == "branch": self.addChild(IncompleteNode([])) else: print("parent: ") print(self.parent) if self.parent is not None: completedNode = PlanarNode(self.children) self.parent[0].changeChild(completedNode, self.parent[1]) Loading @@ -533,7 +581,7 @@ class IncompleteNode(PlanarNode): for child in self.children: child.completeNode(index, nodeType, tree) def checkNode(self, node, nodeBrothers=None, brothers=None): def isEqual(self, node, nodeBrothers=None, brothers=None): if brothers is None: brothers = [] if nodeBrothers is None: Loading @@ -552,9 +600,9 @@ class IncompleteNode(PlanarNode): return brothers.pop(0).checkNode(nodeBrothers.pop(0), nodeBrothers, brothers) else: if nodeBrothers: return True else: return False else: return True else: if len(self.children) == len(node.children): newBrothers = self.children[1:] + brothers Loading model/tree.py −3 Changes for model/tree.py: 0 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -20,10 +20,7 @@ class Tree: self.setup_root() def completeNode(self, index: int, nodeType: str): print("aaaaaaaaaaaaa") print(self.root) self.root.numberNodes() print(self.root) self.root.completeNode(index, nodeType, self) self.depth = self.root.getDepth() self.dyckWord = self.root.getDyckWord() Loading Loading
controller/binaryTreeToPlanarTree.py +2 −2 Changes for controller/binaryTreeToPlanarTree.py: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -41,8 +41,8 @@ class BinaryTreeToPlanarTree: def addNode(self, index: int, nodeType: str): if self.level.checkTree(index, nodeType): self.levelGui.planarTreeView.createTree() """if self.level.finished(): self.levelGui.finish()""" if self.level.finished(): self.levelGui.finish() else: self.levelGui.error(index, nodeType) Loading
model/levelBinaryTreeToPlanarTree.py +5 −5 Changes for model/levelBinaryTreeToPlanarTree.py: 5 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ class LevelBinaryTreeToPlanarTree: self.index = index self.answer = getTree(index) self.planarAnswer = Tree(binaryTreeToPlanarTree(self.answer.root)) self.answer = self.planarAnswer self.tree = None self.score = None self.initialize() Loading @@ -29,15 +30,14 @@ class LevelBinaryTreeToPlanarTree: def checkTree(self, index: int, nodeType: str): copy = self.tree.copyTree() copy.completeNode(index, nodeType) print("checckkkk") """print("-----------------------") print(self.planarAnswer.root) print(copy.root) """if self.planarAnswer.root.checkNode(copy.root):""" if 1: print(copy.root)""" if self.planarAnswer.root.checkNode(copy.root): self.tree.completeNode(index, nodeType) return True else: return False def finished(self): return self.tree.root.isEqual(self.answer.root) return self.planarAnswer.root.isEqual(self.tree.root)
model/node.py +72 −24 Changes for model/node.py: 72 added lines, 24 removed lines. Original line number Diff line number Diff line Loading @@ -345,6 +345,46 @@ class PlanarNode(Node): child.completeNode(index, nodeType, tree) def checkNode(self, node, nodeBrothers=None, brothers=None): print("node: ") print(node) print(self) if brothers is None: brothers = [] if nodeBrothers is None: nodeBrothers = [] if not isinstance(node, IncompleteNode): if len(self.children) != len(node.children): print("AAAAAAAAAAA") return False else: if len(self.children) < len(node.children): print("BBBBBBBBBB") return False if not self.children: if brothers: if not nodeBrothers: return True else: return brothers.pop(0).checkNode(nodeBrothers.pop(0), nodeBrothers, brothers) else: return True else: if not node.children: if brothers: if not nodeBrothers: return True else: return brothers.pop(0).checkNode(nodeBrothers.pop(0), nodeBrothers, brothers) else: return True else: newBrothers = self.children[1:] + brothers newNodeBrothers = node.children[1:] + nodeBrothers return self.children[0].checkNode(node.children[0], newNodeBrothers, newBrothers) def isEqual(self, node, nodeBrothers=None, brothers=None): if brothers is None: brothers = [] if nodeBrothers is None: Loading @@ -360,12 +400,12 @@ class PlanarNode(Node): if not nodeBrothers: return False else: return brothers.pop(0).checkNode(nodeBrothers.pop(0), nodeBrothers, brothers) return brothers.pop(0).isEqual(nodeBrothers.pop(0), nodeBrothers, brothers) else: if nodeBrothers: return True else: return False else: return True else: if len(self.children) == len(node.children): newBrothers = self.children[1:] + brothers Loading @@ -373,10 +413,23 @@ class PlanarNode(Node): if len(newNodeBrothers) != len(newBrothers): return False else: return self.children[0].numberNodes(node.children[0], newNodeBrothers, newBrothers) return self.children[0].isEqual(node.children[0], newNodeBrothers, newBrothers) else: return False """def isEqual(self, node): if isinstance(node, EmptyNode): return False elif len(self.children) != len(node.children): return False elif len(self.children) == 0: return True else: answer = True for i in range(len(self.children)): answer = answer and self.children[i].isEqual(node.children[i]) return answer""" def setup(self, depth=0, places=None, offsets=None): nb_children = len(self.children) if places is None: Loading Loading @@ -437,20 +490,7 @@ class PlanarNode(Node): else: return self.right.addNode(self.left.addNode(index, nodeType), nodeType) def isEqual(self, node): if isinstance(node, EmptyNode): return False elif len(self.children) != len(node.children): return False elif len(self.children) == 0: return True else: answer = True for i in range(len(self.children)): answer = answer and self.children[i].isEqual(node.children[i]) return answer def checkNode(self, answer): """def checkNode(self, answer): if isinstance(answer, EmptyNode): return True elif len(self.children) != len(answer.children): Loading @@ -465,7 +505,7 @@ class PlanarNode(Node): test = True for i in range(len(self.children)): test = test and self.children[i].isEqual(answer.children[i]) return test return test""" def getDepth(self): """ Loading Loading @@ -496,6 +536,14 @@ class IncompleteNode(PlanarNode): self.offset = 0 self.parent = None self.index = None for i in range(len(self.children)): self.children[i].setParent(self, i) def copyNode(self): copyChildren = [] for child in self.children: copyChildren.append(child.copyNode()) return IncompleteNode(copyChildren) def setParent(self, node, index): """ Loading @@ -515,8 +563,6 @@ class IncompleteNode(PlanarNode): brothers.pop(0).numberNodes(index + 1, brothers) else: newBrothers = self.children[1:] + brothers print("B") print(self.children[0]) self.children[0].numberNodes(index + 1, newBrothers) def completeNode(self, index: int, nodeType: str, tree): Loading @@ -524,6 +570,8 @@ class IncompleteNode(PlanarNode): if nodeType == "branch": self.addChild(IncompleteNode([])) else: print("parent: ") print(self.parent) if self.parent is not None: completedNode = PlanarNode(self.children) self.parent[0].changeChild(completedNode, self.parent[1]) Loading @@ -533,7 +581,7 @@ class IncompleteNode(PlanarNode): for child in self.children: child.completeNode(index, nodeType, tree) def checkNode(self, node, nodeBrothers=None, brothers=None): def isEqual(self, node, nodeBrothers=None, brothers=None): if brothers is None: brothers = [] if nodeBrothers is None: Loading @@ -552,9 +600,9 @@ class IncompleteNode(PlanarNode): return brothers.pop(0).checkNode(nodeBrothers.pop(0), nodeBrothers, brothers) else: if nodeBrothers: return True else: return False else: return True else: if len(self.children) == len(node.children): newBrothers = self.children[1:] + brothers Loading
model/tree.py −3 Changes for model/tree.py: 0 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -20,10 +20,7 @@ class Tree: self.setup_root() def completeNode(self, index: int, nodeType: str): print("aaaaaaaaaaaaa") print(self.root) self.root.numberNodes() print(self.root) self.root.completeNode(index, nodeType, self) self.depth = self.root.getDepth() self.dyckWord = self.root.getDyckWord() Loading