Commit 6aca2014 authored by Aurelien Dufour's avatar Aurelien Dufour
Browse files

correction de bugs sur l'algo de placement de points + utilisation dans le dessin des arbres

parent dffd123d
Loading
Loading
Loading
Loading
+80 B (13.7 KiB)

File changed.

No diff preview for this file type.

+2
Changes for main.py: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@ from PyQt5.QtWidgets import QApplication

from controller.menuController import MenuController
from model.game import Game
from model.node import BinaryNode, Leaf
from model.tree import BinaryTree
from view.menu import Menu


+5 −4
Changes for model/levelDyckWordToBinaryTree.py: 5 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -3,11 +3,13 @@ from enum import Enum

from model.node import BinaryNode, EmptyNode, Leaf, randomTree
from model.tree import BinaryTree

Levels = Enum("Levels", [
    ("Lvl1", BinaryTree(BinaryNode(Leaf(), BinaryNode(Leaf(), Leaf())))),
    ("Lvl2", BinaryTree(BinaryNode(BinaryNode(Leaf(), Leaf()), BinaryNode(Leaf(), Leaf())))),
    ("Lvl3", BinaryTree(BinaryNode(BinaryNode(Leaf(), BinaryNode(Leaf(), Leaf())), BinaryNode(Leaf(), Leaf()))))])


def getTree(level):
    if level == 1:
        return Levels.Lvl1.value
@@ -18,11 +20,13 @@ def getTree(level):
    else:
        return BinaryTree(randomTree(int(math.log(level) * 3)))


class LevelDyckWordToBinaryTree:
    def __init__(self, index):
        self.index = index
        self.answer = getTree(index)
        self.tree = BinaryTree(BinaryNode(EmptyNode(), EmptyNode()))
        self.tree = self.answer
        """BinaryTree(BinaryNode(EmptyNode(), EmptyNode()))"""
        self.score = 100

    def nextLevel(self):
@@ -47,8 +51,5 @@ class LevelDyckWordToBinaryTree:
        else:
            return False


    def finished(self):
        return self.tree.root.isEqual(self.answer.root)

+19 −3
Changes for model/node.py: 19 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -20,11 +20,11 @@ def setup(node, depth=0, places=None, offsets=None):

    if isinstance(node, BinaryNode):
        if not isinstance(node, Leaf) and not isinstance(node, EmptyNode):
            setup(node.left, depth, places, offsets)
            setup(node.right, depth, places, offsets)
            setup(node.left, depth + 1, places, offsets)
            setup(node.right, depth + 1, places, offsets)
    else:
        for child in node.children:
            setup(child, depth, places, offsets)
            setup(child, depth + 1, places, offsets)

    if nb_children == 0:
        place = places[depth]
@@ -51,10 +51,16 @@ def add_offsets(node, offset_sum=0):
    if isinstance(node, BinaryNode):
        if not isinstance(node, Leaf) and not isinstance(node, EmptyNode):
            add_offsets(node.left, offset_sum)
            node.height = max(node.left.height, node.height)
            node.width = max(node.right.width, node.width)
            add_offsets(node.right, offset_sum)
            node.height = max(node.right.height, node.height)
            node.width = max(node.right.width, node.width)
    else:
        for child in node.children:
            add_offsets(child, offset_sum)
            node.height = max(node.height, child.height)
            node.width = max(node.width, child.width)


def putHole(word, start, end):
@@ -380,6 +386,11 @@ class Leaf(BinaryNode):

    def __init__(self):
        super(BinaryNode, self).__init__()
        self.x = 0
        self.y = 0
        self.height = 0
        self.width = 0
        self.offset = 0

    def getDyckWord(self):
        return ""
@@ -395,6 +406,11 @@ class EmptyNode(BinaryNode):

    def __init__(self):
        super(BinaryNode, self).__init__()
        self.x = 0
        self.y = 0
        self.height = 0
        self.width = 0
        self.offset = 0

    def getDyckWord(self):
        return ""
+5
Changes for model/tree.py: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ class BinaryTree:
        self.depth = root.getDepth()
        self.dyckWord = root.getDyckWord()
        self.index = 0
        self.setup_root()

    def copyBinaryTree(self):
        return BinaryTree(self.root.copyBinaryNode())
@@ -18,7 +19,11 @@ class BinaryTree:
        self.root.addNode(index, nodeType)
        self.depth = self.root.getDepth()
        self.dyckWord = self.root.getDyckWord()
        self.setup_root()

    def setup_root(self):
        setup(self.root)
        add_offsets(self.root)

class PlanarTree:
    def __init__(self, root: PlanarNode):
Loading