Beispiel #1
0
                            board.put_piece(i, j, board.puzzle_def.all[id], 0)
                            break
        board.fix_orientation()
        # board.save(args.load+".2")

    else:
        board.randomize()
        board.heuristic_orientation()

    # mark the pieces
    for i in range(height):
        for j in range(width):
            if board.board[i][j]:
                board.marks[i][j] = board.board[i][j].piece_def.id

    ui = ui.BoardUi(board)
    ui.init()
    pygame.display.set_caption(f'Puzzle (score {board.evaluate()})')

    selected_from = None
    selected_to = None

    LEFT_BUTTON = 1
    RIGHT_BUTTON = 2

    while True:

        for event in pygame.event.get():
            if event.type == pygame.locals.QUIT:
                pygame.quit()
                sys.exit()
Beispiel #2
0
    parser = argparse.ArgumentParser()
    parser.add_argument('-conf',
                        type=str,
                        required=True,
                        help='Definition file')
    parser.add_argument('-dir',
                        type=str,
                        default=".",
                        help='Folder to monitor')
    args = parser.parse_args()

    puzzle_def = PuzzleDefinition()
    puzzle_def.load(args.conf)

    board_inst = board.Board(puzzle_def)
    ui = ui.BoardUi(board_inst)
    ui.init()

    prev_csv_files = set()
    max_score = 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