Exemplo n.º 1
0
def get_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--input",
        "-i",
        help=
        "set input path in txt, must be rectangular n x m board, first line is 'n m' separated by space, then followed by n lines: fill the number separated by space or 0 if empty cell (must have exactly 1 empty cell)"
    )
    return parser.parse_args()


def get_config():
    args = get_args()
    filename = args.input if args.input else input("Input filename: ")
    with open(filename, "r") as f:
        config = f.readlines()
    return config


if __name__ == "__main__":
    config = get_config()
    B = Board(config)
    print("==== Initial matrix ====")
    B.nodes[0].print()
    print()

    if B.solvable(output=True):
        B.solve()
    else:
        print("Puzzle is unsolvable!")
Exemplo n.º 2
0
            board[i][j] = info['shape'][0]
            if info['end_points']:
                board[i][j] = board[i][j].upper()
        else:
            board[i][j] = str(info['visits'])
    return board, (x_levels[0], x_interval), (y_levels[0], y_interval)


if __name__ == '__main__':
    import subprocess
    import pyscreenshot as ImageGrab

    from solver import Board

    print("Please click on the window of the game LYNE.")
    res = subprocess.getoutput('xwininfo')
    num = [int(s) for s in res.split() if s.isdigit()]

    while True:
        input("Press enter for starting.")
        img = ImageGrab.grab(bbox=(num[0], num[1], num[0] + num[4],
                                   num[1] + num[5]))
        img = cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR)
        board = get_board(img)[0]
        from IPython import embed
        embed()
        board = Board(board)
        paths = board.solve()
        for path in paths:
            board._print_path(path)