def save_still_image():
    frame = video_capture.read()[1]
    cv2.imwrite("tmp_image.png", frame)
    b, g, r = cv2.split(frame)
    frame = cv2.merge((r, g, b))
    ui.set_image(PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(frame)))
    ui.set_msg("Uploading and Fetching data from Web.. Please wait")
    ui.hide_buttons()
    ThreadHelper().start()
    while ui.for_online_search:
        ui.update()
        ui.set_name(info_string, 'info')
    ui.show_buttons()
Exemple #2
0
    def update(filename):
        try:

            board_inst = board.Board(puzzle_def)
            board_inst.load(filename)
            score = board_inst.evaluate()
            global max_score
            if score >= max_score:
                print(f"Loading new file {filename}")
                max_score = score
                ui.board = board_inst
                ui.update()
                caption = f'S {board_inst.evaluate()}/{board_inst.max_score()}'
                pygame.display.set_caption(caption)
        except:
            pass
Exemple #3
0
    def check_best():
        curr = board.evaluate()

        global best
        global shuffle_counter
        global shuffle_backup
        #
        # if shuffle_counter <= 0 and curr == best:
        #     # trying to find sequence of ANY 2 swaps that potentially increase the overall score ...
        #     #swapper.do_double_swap()
        #     shuffle_backup = copy.deepcopy(board)
        #     swapper.shuffle()
        #     shuffle_counter = 3

        #if True: # DEBUG TEST ONLY
        #if double_swap_counter <= 0 and curr == best:
        # if False: # double swapping disabled for now - until not optimized
        #     print("DOUBLE SWAP! Start...")
        #     # trying to find sequence of ANY 2 swaps that potentially increase the overall score ...
        #     #swapper.do_double_swap()
        #     swapper.do_double_swap()
        #     print("DOUBLE SWAP! End...")
        #     double_swap_counter = 3

        ui.update()
        if best < curr:
            print(f"[UI] Best score improved to {curr}")
            best = curr

            if best >= board.max_score() - 30:
                board.save("save " + str(uuid.uuid4()) + "_" + str(best) +
                           ".csv")
            # we fill in remaining pieces to have a slightly better score

            if best == board.max_score():
                pygame.display.set_caption(f'Puzzle SOLVED!')
                print("SOLVED!")
        # elif best == curr:
        #     double_swap_counter -= 1

        pygame.display.set_caption(
            f'SBest {best}/{board.max_score()} SCurr {curr}/{board.max_score()}'
        )
Exemple #4
0
                                board.is_edge(*selected_from) and board.is_edge(*selected_to) or \
                                board.is_inner(*selected_from) and board.is_inner(*selected_to):
                            board.exchange(*selected_from, *selected_to)
                            from_i = selected_from[0]
                            from_j = selected_from[1]
                            to_i = selected_to[0]
                            to_j = selected_to[1]

                            board.marks[from_i][from_j], board.marks[to_i][to_j] = \
                                board.marks[to_i][to_j], board.marks[from_i][from_j]
                            board.fix_orientation()
                            # experimental feature
                            board.heuristic_orientation()
                            pygame.display.set_caption(
                                f'Puzzle (score {board.evaluate()})')
                            ui.update()

                        selected_from = selected_to = None

                else:
                    # rotate
                    if (i > 0) and (i < height - 1) and (j > 0) and (
                            j < width - 1):
                        board.board[i][j].dir += 1
                        board.board[i][j].dir %= 4
                        pygame.display.set_caption(
                            f'Puzzle (score {board.evaluate()})')
                        ui.update()

            elif event.type == pygame.MOUSEBUTTONDOWN:
                x, y = pygame.mouse.get_pos()