shenzhen-solitaire.py
def autosolve_game(timeout=None):
    """Take screenshot, solve the current game, and execute the solution."""
    board = Board(img=grab_screenshot())
    if VERBOSE:
        print(board)

    # Solve the board
    finished = solve(board, traceback=False, print_tb_boards=False,
                     timeout=timeout)

    if not finished:
        return

    # Process the trace
    curr_b = finished
    trace = [curr_b]
    while curr_b.previous:
        curr_b, _ = curr_b.previous
        trace.append(curr_b)

    trace.reverse()
    trace = trace[1:]

    # Playback the solution
    click_window()

    old_board = None
    old_move = None
    for board in trace:
        # print '-' * 20
        # Read board and unpack move
        board, move = board.previous
        board.read_orders(old_move=old_move, old_b=old_board)
        # print map(str, board.spaces_order), board.goals_order
        old_board = board
        old_move = move
        _, move_type, details, num_automove = move

        # Send command
        if move_type == PILE:
            idx, idy, dst_idx = details
            dst_idy = max(len(board.piles[dst_idx]) - 1, 0)
            move_piles(idx, idy, dst_idx, dst_idy)

        elif move_type == UP_SPACES:
            idx = details
            idy = len(board.piles[idx]) - 1

            for dst_idx, s in enumerate(board.spaces_order):
                if not s:
                    break

            move_to_spaces(idx, idy, dst_idx)

        elif move_type == DOWN_SPACES:
            c_str, dst_idx = details
            dst_idy = max(len(board.piles[dst_idx]) - 1, 0)

            card = Card.from_str(c_str)
            src_idx = board.spaces_order.index(card)

            move_from_spaces(src_idx, dst_idx, dst_idy)

        elif move_type == GOAL_P:
            c_str, src_idx = details
            src_idy = len(board.piles[src_idx]) - 1

            card = Card.from_str(c_str)
            dst_idx = board.goals_order.index(card.color)

            move_goal_piles(src_idx, src_idy, dst_idx)

        elif move_type == GOAL_S:
            c_str, src_idx = details
            card = Card.from_str(c_str)
            dst_idx = board.goals_order.index(card.color)
            move_goal_spaces(src_idx, dst_idx)

        elif move_type == CLEAR_D:
            color = details
            clear_dragon(color)

        # Sleep for automoves
        if num_automove:
            if VERBOSE:
                print("Sleeping %s automoves" % num_automove)
            time.sleep(AUTOMOVE_DELAY * num_automove)
Take screenshot, solve the current game, and execute the solution.
Take screenshot, solve the current game, and execute the solution.
Take screenshot solve the current game and execute the solution .
def autosolve_game(timeout=None):
    board = Board(img=grab_screenshot())
    if VERBOSE:
        print(board)
    finished = solve(board, traceback=False, print_tb_boards=False,
                     timeout=timeout)
    if not finished:
        return
    curr_b = finished
    trace = [curr_b]
    while curr_b.previous:
        curr_b, _ = curr_b.previous
        trace.append(curr_b)
    trace.reverse()
    trace = trace[1:]
    click_window()
    old_board = None
    old_move = None
    for board in trace:
        board, move = board.previous
        board.read_orders(old_move=old_move, old_b=old_board)
        old_board = board
        old_move = move
        _, move_type, details, num_automove = move
        if move_type == PILE:
            idx, idy, dst_idx = details
            dst_idy = max(len(board.piles[dst_idx]) - 1, 0)
            move_piles(idx, idy, dst_idx, dst_idy)
        elif move_type == UP_SPACES:
            idx = details
            idy = len(board.piles[idx]) - 1
            for dst_idx, s in enumerate(board.spaces_order):
                if not s:
                    break
            move_to_spaces(idx, idy, dst_idx)
        elif move_type == DOWN_SPACES:
            c_str, dst_idx = details
            dst_idy = max(len(board.piles[dst_idx]) - 1, 0)
            card = Card.from_str(c_str)
            src_idx = board.spaces_order.index(card)
            move_from_spaces(src_idx, dst_idx, dst_idy)
        elif move_type == GOAL_P:
            c_str, src_idx = details
            src_idy = len(board.piles[src_idx]) - 1
            card = Card.from_str(c_str)
            dst_idx = board.goals_order.index(card.color)
            move_goal_piles(src_idx, src_idy, dst_idx)
        elif move_type == GOAL_S:
            c_str, src_idx = details
            card = Card.from_str(c_str)
            dst_idx = board.goals_order.index(card.color)
            move_goal_spaces(src_idx, dst_idx)
        elif move_type == CLEAR_D:
            color = details
            clear_dragon(color)
        if num_automove:
            if VERBOSE:
                print("Sleeping %s automoves" % num_automove)
            time.sleep(AUTOMOVE_DELAY * num_automove)
def autosolve_game ( timeout = None ) : board = Board ( img = grab_screenshot ( ) ) if VERBOSE : print ( board ) finished = solve ( board , traceback = False , print_tb_boards = False , timeout = timeout ) if not finished : return curr_b = finished trace = [ curr_b ] while curr_b . previous : curr_b , _ = curr_b . previous trace . append ( curr_b ) trace . reverse ( ) trace = trace [ 1 : ] click_window ( ) old_board = None old_move = None for board in trace : board , move = board . previous board . read_orders ( old_move = old_move , old_b = old_board ) old_board = board old_move = move _ , move_type , details , num_automove = move if move_type == PILE : idx , idy , dst_idx = details dst_idy = max ( len ( board . piles [ dst_idx ] ) - 1 , 0 ) move_piles ( idx , idy , dst_idx , dst_idy ) elif move_type == UP_SPACES : idx = details idy = len ( board . piles [ idx ] ) - 1 for dst_idx , s in enumerate ( board . spaces_order ) : if not s : break move_to_spaces ( idx , idy , dst_idx ) elif move_type == DOWN_SPACES : c_str , dst_idx = details dst_idy = max ( len ( board . piles [ dst_idx ] ) - 1 , 0 ) card = Card . from_str ( c_str ) src_idx = board . spaces_order . index ( card ) move_from_spaces ( src_idx , dst_idx , dst_idy ) elif move_type == GOAL_P : c_str , src_idx = details src_idy = len ( board . piles [ src_idx ] ) - 1 card = Card . from_str ( c_str ) dst_idx = board . goals_order . index ( card . color ) move_goal_piles ( src_idx , src_idy , dst_idx ) elif move_type == GOAL_S : c_str , src_idx = details card = Card . from_str ( c_str ) dst_idx = board . goals_order . index ( card . color ) move_goal_spaces ( src_idx , dst_idx ) elif move_type == CLEAR_D : color = details clear_dragon ( color ) if num_automove : if VERBOSE : print ( "Sleeping %s automoves" % num_automove ) time . sleep ( AUTOMOVE_DELAY * num_automove )
Take screenshot, solve the current game, and execute the solution.
Take screenshot solve the current game and execute the solution .
"""Take screenshot, solve the current game, and execute the solution.""" # Solve the board # Process the trace # Playback the solution # print '-' * 20 # Read board and unpack move # print map(str, board.spaces_order), board.goals_order # Send command # Sleep for automoves
timeout