Closed T0nyX1ang closed 6 months ago
We "simulated" the inheritance. As a result, there is a higher level function run()
to call:
def run(puzzle_type: str, puzzle_content: str) -> str:
"""Run the solver."""
module = modules[puzzle_type]
if not hasattr(module, "encode"):
module.encode = encode
if not hasattr(module, "solve"):
raise NotImplementedError("Solver not implemented.")
if not hasattr(module, "decode"):
module.decode = decode
puzzle_encoded: Encoding = module.encode(puzzle_content)
solutions_encoded: List[Dict[str, str]] = module.solve(puzzle_encoded)
solutions_decoded: str = module.decode(solutions_encoded)
return solutions_decoded
This feature aims to make solvers behave like plugins.
The following code might be used: