Commit 520cd3de authored by Aurélien's avatar Aurélien
Browse files

ajout de branches et confirmation de noeud fonctionnels pour le jeu binary -> planar tree

parent 0780c056
Loading
Loading
Loading
Loading
+36 −5
Changes for model/node.py: 36 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -330,6 +330,29 @@ class PlanarNode(Node):
    def changeChild(self, node, index: int):
        self.children[index] = node

    def numberNodes(self, index=0, brothers=None):
        if brothers is None:
            brothers = []
        if not self.children:
            if brothers:
                brother = brothers.pop(0)
                print("A")
                print(brother)
                brother.numberNodes(index, brothers)
        else:
            newBrothers = self.children[1:] + brothers
            print("B")
            print(self.children[0])
            self.children[0].numberNodes(index, newBrothers)

    def completeNode(self, index: int, nodeType: str, tree):
        print("---------------------")
        print(index)
        print(self)
        print("---------------------")
        for child in self.children:
            child.completeNode(index, nodeType, tree)

    def setup(self, depth=0, places=None, offsets=None):
        nb_children = len(self.children)
        if places is None:
@@ -468,15 +491,21 @@ class IncompleteNode(PlanarNode):
        self.parent = (node, index)

    def numberNodes(self, index=0, brothers=None):
        print("bro:")
        print(brothers)
        if brothers is None:
            brothers = []
        self.index = index
        if not self.children:
            if brothers:
                brothers[0].numberNodes(index + 1, brothers.pop(0))
                brother = brothers.pop(0)
                print("A")
                print(brother)
                brother.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):
@@ -822,16 +851,18 @@ if __name__ == '__main__':

    ptroot = binaryTreeToPlanarTree(btroot)"""

    ptroot = IncompleteNode([IncompleteNode([IncompleteNode([])]),
    """ptroot = IncompleteNode([IncompleteNode([IncompleteNode([])]),
                             IncompleteNode([IncompleteNode([]), IncompleteNode([])]),
                             IncompleteNode([IncompleteNode([]), IncompleteNode([]), IncompleteNode([])])])
    print(ptroot)
    ptroot.numberNodes()
    print(ptroot)
    print(ptroot)"""
    """l1 = ["a","b"]
    c = "c"
    print(l1 + [c])"""
    c = l1[1:]
    print(c)"""

    """print(ptroot)

    btroot2 = planarTreeToBinaryTree(ptroot)"""