def solve_problem(self, problem: Problem): solver = StrategyTypes.GENETIC secret_type = problem.secret_type() secret_size = problem.secret_size() if secret_size == 1 or secret_size == 3: solver = StrategyTypes.SWASZEK elif secret_type == SecretTypes.NUMERIC: if secret_size == 2: solver = StrategyTypes.KNUTH elif secret_size > 3: solver = StrategyTypes.GENETIC elif secret_size == SecretTypes.LSTRING: if secret_size == 2: solver = StrategyTypes.KNUTH elif secret_size < 5: solver = StrategyTypes.SWASZEK else: solver = StrategyTypes.GENETIC elif secret_type == SecretTypes.STRING: if secret_size < 5: solver = StrategyTypes.SWASZEK else: solver = StrategyTypes.GENETIC return self.__strategies[solver].solve_problem(problem)
def convert(secret: str, strategy, problem: Problem) -> Dict: """ Convert the resultant test information into a simplified representation :param secret: secret to uncover :param strategy: strategy used to solve the problem :param problem: resultant problem :return: dict of the captured information """ return { "secret": secret, "algorithm": strategy, "size": problem.secret_size(), "rounds": problem.turns_to_solve(), "solved": problem.solved(), "type": problem.secret_type(), "time": problem.time_to_solve(), }