Commit 7e95f011 authored by Aurelien Dufour's avatar Aurelien Dufour
Browse files

jeu planar tree -> mot de dyck fonctionnel

parent b34db6f1
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -2,8 +2,8 @@ from random import randint

from model.level import Level
from model.levelEnum import getTreePlanarTreeToDyckWord
from model.node import putHole

from model.node import putHole, binaryTreeToPlanarTree
from model.tree import Tree


def getIncompleteWord(dyckWord):
@@ -24,7 +24,8 @@ def getIncompleteWord(dyckWord):
class LevelPlanarTreeToDyckWord(Level):
    def __init__(self, index):
        super().__init__(index)
        self.tree = getTreePlanarTreeToDyckWord(index)
        binaryTree = getTreePlanarTreeToDyckWord(index)
        self.tree = Tree(binaryTreeToPlanarTree(binaryTree.root))
        self.dyckWord = self.tree.dyckWord
        self.incompleteWord = getIncompleteWord(self.dyckWord)
        self.answer = ""
+1 −27
Original line number Diff line number Diff line
@@ -230,7 +230,7 @@ class BinaryNode(Node):
        :param node: the node we compare with
        :return: True if the nodes are the sames, False otherwise
        """
        if isinstance(node, EmptyNode) or isinstance(node, IncompleteBinaryNode):
        if isinstance(node, EmptyNode):
            return False
        elif isinstance(self, Leaf):
            if isinstance(node, Leaf):
@@ -508,29 +508,6 @@ class PlanarNode(Node):
        return self.toStr()


class IncompleteBinaryNode(BinaryNode):
    def __init__(self, left, right):
        super(BinaryNode, self).__init__()
        self.left = left
        self.right = right
        # in a few funtions, we need that each node knows its parent
        self.left.setParent(self, 0)
        self.right.setParent(self, 1)
        self.parent = None
        # we need the position of the node compared with the others nodes of the tree to draw a tree
        self.x = 0
        self.y = 0
        self.height = 0
        self.width = 0
        self.offset = 0

    def toStr(self, tab=0):
        return ' ' * tab + 'INCOMPLETE BINODE' + '\n' + "".join(self.left.toStr(tab + 2)) + "".join(self.right.toStr(tab + 2))

    def __str__(self):
        return self.toStr()


class IncompleteNode(PlanarNode):
    def __init__(self, children):
        super(PlanarNode, self).__init__()
@@ -950,9 +927,6 @@ def planarToBinaryRec(planarTree, brothers):
        right = planarToBinaryRec(brothers[0], brothers[1:])
    else:
        right = Leaf()
    if isinstance(planarTree, IncompleteNode):
        return IncompleteBinaryNode(left, right)
    else:
    return BinaryNode(left, right)


+5 −1
Original line number Diff line number Diff line
@@ -11,8 +11,12 @@ def title(game: GameEnum):
        return "Jeu: Arbre binaire - > Arbre planaire"
    elif game == GameEnum.BINARY_TREE_TO_DYCK_WORD:
        return "Jeu: Arbre binaire - > Mot de Dyck"
    else:
    elif game == GameEnum.PLANAR_TREE_TO_BINARY_TREE:
        return "Jeu: Arbre planaire - > Arbre binaire"
    elif game == GameEnum.BINARY_TREE_TO_DYCK_WORD:
        return "Jeu: Arbre planaire - > Mot de Dyck"
    else:
        return "Jeu: Mot de Dyck - > Arbre planaire"


def explaination(game: GameEnum):