예제 #1
0
def execute(buffer_size, save_images, interval_seconds):
    start_time = time.time()

    while True:
        image = grab_screen(ignore_foreground_check=False,
                            save_image=save_images)
        if image is not None:
            print('screen grabbed. Processing...')
            matrix, required_sequences, offset_matrix_x, offset_matrix_y = ocr_core(
                image)
            print('Screen processed.')

            # check if we found a valid matrix of codes
            if matrix is not None and len(
                    matrix) >= 5 and required_sequences is not None and len(
                        required_sequences) > 0:
                end_paths = []

                # reformat the required sequences
                for sequence in required_sequences:
                    end_paths.append(''.join([s.code for s in sequence]))

                print('Finding path')
                path = find_path(np.array(matrix), end_paths, buffer_size)
                print('Finding path complete')
                execute_clicks(matrix, path, offset_matrix_x, offset_matrix_y)
                print(path)
        time.sleep(interval_seconds -
                   ((time.time() - start_time) % interval_seconds))
 def test_path_finder_ignores_already_used_nodes(self):
     array = create_object_matrix_from_str_matrix([['1C', '7A'],
                                                   ['1C', 'E9']])
     actual_path = find_path(np.array(array), ['1C1CE97A1C'], 999)
     self.assertLess(
         len(actual_path), 5,
         'There should not be a valid path for the required sequence')
 def test_path_finder_finds_easy_path(self):
     matrix = create_object_matrix_from_str_matrix([['1C', '7A'],
                                                    ['55', 'BD']])
     required_sequences = ['1C55BD']
     actual_path = find_path(np.array(matrix), required_sequences, 999)
     self.assertTrue(
         self.path_completes_required(matrix, required_sequences,
                                      actual_path))
 def test_path_finder_finds_multiple_sequences(self):
     matrix = create_object_matrix_from_str_matrix([['55', '55', '55'],
                                                    ['55', 'BD', '55'],
                                                    ['55', 'BD', '55']])
     required_sequences = ['BDBD', 'BD55']
     actual_path = find_path(np.array(matrix), required_sequences, 5)
     self.assertTrue(
         self.path_completes_required(matrix, required_sequences,
                                      actual_path))
 def test_path_finder_finds_path_in_complex_image(self):
     matrix = create_object_matrix_from_str_matrix(
         [['1C', '7A', '1C', 'E9', '55', '1C'],
          ['1C', 'E9', '7A', '1C', '1C', '55'],
          ['55', '1C', '55', '1C', 'E9', '55'],
          ['7A', '55', 'E9', 'BD', '7A', '1C'],
          ['7A', '1C', '7A', '55', 'E9', '55'],
          ['1C', 'BD', '55', '55', 'BD', '7A']])
     required_sequences = ['1C7A1C', 'BD557A1C', '7A5555BD']
     actual_path = find_path(np.array(matrix), required_sequences, 10)
     self.assertTrue(
         self.path_completes_required(matrix, required_sequences,
                                      actual_path))