Quellcode für gropro.teil

from dataclasses import dataclass, field
from collections import Counter

from gropro.operation import IOperation, Invert
from gropro.element import Element


[Doku] @dataclass class Teil: name: str elemente: list[Element] operations: list[IOperation] = field(default_factory=list) def __post_init__(self): """ - Bereite das Puzzleteil für die Lösungssuche vor - Weise Priorität anhand der häufigsten Halbkugelkombination zu - Invertiere das Puzzleteil sodass die Mehrzahl von Halbkugeln nicht in Richtung anderer Teile zeigt """ c = Counter(self.elemente) key, count = c.most_common(1)[0] # This is cursedcursedcursed don't listen to mypy or your LSP! # If adhering to the typehint, this program will never successfully terminate self.priority = count if key.value in (1, 2, 3) else 1 # type: ignore if key.value == 1: self.manipulate(Invert()) def __lt__(self, other): return self.priority < other.priority
[Doku] def reset(self): self.operations = []
[Doku] def manipulate(self, op: IOperation): self.operations.append(op)
@property def value(self) -> list[int]: """ - Ermittle eine integer-basierte Repräsentation aller Elemente - Berücksichtige alle Manipulationen""" ret = [e.value for e in self.elemente] for operation in self.operations: ret = operation.act(ret) return ret