Beispiel #1
0
    def undraw(self):
        tmp_liquids = Stack()
        while not self.liquids.isEmpty():
            liquid: Liquid = self.liquids.pop()
            liquid.undraw()
            tmp_liquids.push(liquid)

        self.liquids = tmp_liquids.reverse()
Beispiel #2
0
    def __str__(self) -> str:
        tmp = Stack()
        result = ""
        while not self.liquids.isEmpty():
            liquid = self.liquids.pop()
            result += liquid.getColor() + " -> "
            tmp.push(liquid)

        self.liquids = tmp.reverse()
        return result
Beispiel #3
0
    def getNumAlternating(self):
        alt = 0
        tmp = Stack()
        prev_color = None
        while not self.liquids.isEmpty():
            liquid = self.liquids.pop()
            color = liquid.getColor()
            if not color == prev_color and prev_color is not None:
                alt += 1
            prev_color = color
            tmp.push(liquid)

        self.liquids = tmp.reverse()
        return alt
Beispiel #4
0
    def getNumGroups(self):
        groups = [0]
        g_idx = 0
        tmp = Stack()
        prev_color = None
        while not self.liquids.isEmpty():
            liquid = self.liquids.pop()
            color = liquid.getColor()
            if not color == prev_color and prev_color is not None:
                groups.append(0)
                g_idx += 1

            groups[g_idx] += 1
            prev_color = color
            tmp.push(liquid)

        self.liquids = tmp.reverse()
        return len([x for x in groups if x > 0])
Beispiel #5
0
    def draw(self, win: GraphWin):

        Text(Point(self.sx + (self.width // 2), self.sy + (self.width // 2)),
             self.name).draw(win)

        Line(Point(self.sx, self.sy), Point(self.sx,
                                            self.sy - self.height)).draw(win)
        Line(Point(self.sx + self.width, self.sy),
             Point(self.sx + self.width, self.sy - self.height)).draw(win)
        Line(Point(self.sx, self.sy - self.height),
             Point(self.sx + self.width, self.sy - self.height)).draw(win)

        tmp_liquids = Stack()
        while not self.liquids.isEmpty():
            liquid: Liquid = self.liquids.pop()
            liquid.draw(win)
            tmp_liquids.push(liquid)

        self.liquids = tmp_liquids.reverse()