Commit fca66f43 authored by Aurélien's avatar Aurélien
Browse files

gestion conflits

parents d94f9770 29c7e0a0
Loading
Loading
Loading
Loading
+1
Changes for diagrammes/.~lock.algoDePlacement.odt#: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
,21915980,C304L-406C10.campus.unicaen.fr,13.05.2022 15:47,file:///home/21915980/.config/libreoffice/4;
 No newline at end of file
+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)

+83
Changes for model/node.py: 83 added lines, 0 removed lines.
Original line number Diff line number Diff line
from collections import defaultdict
from random import randint



def setup(node, depth=0, places=None, offsets=None):
    if isinstance(node, BinaryNode):
        if not isinstance(node, Leaf) and not isinstance(node, EmptyNode):
            nb_children = 2
        else:
            nb_children = 0
    else:
        nb_children = len(node.children)

    if places is None:
        places = defaultdict(lambda: 0)
    if offsets is None:
        offsets = defaultdict(lambda: 0)
    node.y = depth

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

    if nb_children == 0:
        place = places[depth]
        node.x = place
    else:
        if isinstance(node, BinaryNode):
            place = (node.left.x + node.right.x) / 2
        else:
            place = (node.children[0].x + node.children[nb_children - 1].x) / 2

    offsets[depth] = max(offsets[depth], places[depth] - place)

    if nb_children != 0:
        node.x = place + offsets[depth]

    places[depth] = node.x + 1
    node.offset = offsets[depth]

def add_offsets(node, offset_sum=0):
    node.x += offset_sum
    offset_sum += node.offset
    node.height = node.y
    node.width = node.x
    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):
    """
    this method permeates to create a hole in a dyck word, a part of the word is removed and replaced by some '?'
@@ -84,6 +146,12 @@ class BinaryNode:
        self.right = right
        self.right.setParent(self, 'r')
        self.parent = None
        self.x = 0
        self.y = 0
        self.height = 0
        self.width = 0
        self.offset = 0


    def setParent(self, node, side):
        """
@@ -231,6 +299,11 @@ class PlanarNode:

    def __init__(self, children: list):
        self.children = children
        self.x = 0
        self.y = 0
        self.height = 0
        self.width = 0
        self.offset = 0

    def addChild(self, planarNode):
        self.children.append(planarNode)
@@ -313,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 ""
@@ -328,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 ""
+9 −2
Changes for model/tree.py: 9 added lines, 2 removed lines.
Original line number Diff line number Diff line
from model.node import BinaryNode, PlanarNode

from collections import defaultdict

from model.node import BinaryNode, PlanarNode, Leaf, setup, add_offsets


class BinaryTree:
@@ -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,9 +19,15 @@ 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):
        self.root = root
        self.depth = root.getDepth()

Loading