def test_synthetic_fail(): stages = [ Stage(1, 3, [3, 1, 2, 4]), Stage(2, 1, [1, 2, 4, 3]), Stage(3, 2, [2, 3, 4, 1]), Stage(4, 4, [4, 3, 1, 2]), Stage(5, 2, [3, 2, 4, 1]) ] solutions = [ Instruction(Instruction.Type.POSITION, 3), Instruction(Instruction.Type.LABEL, 4), Instruction(Instruction.Type.LABEL, 2), Instruction(Instruction.Type.POSITION, 3), Instruction(Instruction.Type.LABEL, 2) ] with pytest.raises(AssertionError): run_test("test_synthetic_fail", stages, solutions) assertWasThrown = False try: run_test("test_synthetic_fail", stages, solutions) except AssertionError as e: assertWasThrown = True finally: assert assertWasThrown
def test_field_4(): stages = [ Stage(1, 2, [3, 1, 2, 4]), Stage(2, 4, [3, 2, 4, 1]), Stage(3, 4, [2, 4, 1, 3]), Stage(4, 4, [1, 4, 3, 2]), Stage(5, 4, [4, 1, 2, 3]) ] solutions = [ Instruction(Instruction.Type.POSITION, 2), Instruction(Instruction.Type.POSITION, 2), Instruction(Instruction.Type.LABEL, 4), Instruction(Instruction.Type.POSITION, 2), Instruction(Instruction.Type.LABEL, 4) ] run_test("test_field_4", stages, solutions)
def test_field_3(): stages = [ Stage(1, 4, [4, 3, 1, 2]), Stage(2, 2, [4, 1, 2, 3]), Stage(3, 3, [4, 3, 1, 2]), Stage(4, 4, [2, 4, 1, 3]), Stage(5, 3, [2, 3, 4, 1]) ] solutions = [ Instruction(Instruction.Type.POSITION, 4), Instruction(Instruction.Type.POSITION, 4), Instruction(Instruction.Type.POSITION, 3), Instruction(Instruction.Type.POSITION, 4), Instruction(Instruction.Type.LABEL, 3) ] run_test("test_field_3", stages, solutions)
def test_synthetic_2(capsys): stages = [ Stage(1, 3, [3, 1, 2, 4]), Stage(2, 3, [1, 2, 4, 3]), Stage(3, 2, [2, 3, 4, 1]), Stage(4, 2, [4, 3, 1, 2]), Stage(5, 2, [3, 2, 4, 1]) ] solutions = [ Instruction(Instruction.Type.POSITION, 3), Instruction(Instruction.Type.POSITION, 1), Instruction(Instruction.Type.LABEL, 2), Instruction(Instruction.Type.POSITION, 1), Instruction(Instruction.Type.LABEL, 1) ] run_test("test_synthetic_2", stages, solutions)
def solveMemoryModule(bomb, moduleIdx): print("Solving memory module") solver = Memory() for level in range(1, 6): time.sleep(3) # wait for buttons to be setup screen = takeScreenshot(bomb) memory_module = screen[217:382, 332:492] button_y = 0.57833 button_x = [0.44875, 0.47875, 0.5075, 0.54375] # button_image_list = [button1, button2, button3, button4] display, buttons = extract_text(memory_module) buttons = buttons.replace('8', '3') buttons = buttons.replace('$', '3') if len(buttons) > 4: for button in buttons: strip = False try: int_button = int(button) strip = int_button not in range(1, 5) except ValueError: strip = True if strip: print("removing anciliary character:", button) buttons = buttons.replace(button, '') # print("level: " + str(level)) # print("display: " + str(display)) # print("buttons: " + str(buttons)) print(display) print(buttons) stage = Stage(level, int(display), [int(num) for num in buttons]) solution = solver.stageSolution(stage) if solution.type == Instruction.Type.POSITION: # print("Solution Type = Position") buttonIndex = solution.value else: # print("Solution Type = Label") buttonIndex = buttons.index(str(solution.value)) + 1 print("Button position to press: " + str(buttonIndex)) clickAtLocation(( getPixelFromPercentage(bomb, x=button_x[buttonIndex - 1]), getPixelFromPercentage(bomb, y=button_y), ))