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()
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
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
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])
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()