shenzhen-solitaire.py
def read_orders(self, img=None, old_move=None, old_b=None):
        """Update orders from screenshot or image."""
        if (old_b and old_move and
                self.num_goals_started() == old_b.num_goals_started()):
            self.goals_order = old_b.goals_order
            self.spaces_order = old_b.spaces_order[:]

            _, move_type, details, _ = old_move

            if move_type == UP_SPACES:
                idx = details
                card = old_b.piles[idx][-1]
                for dst_idx, s in enumerate(old_b.spaces_order):
                    if not s:
                        break
                self.spaces_order[dst_idx] = card

            elif move_type in [DOWN_SPACES, GOAL_S]:
                c_str, _ = details
                card = Card.from_str(c_str)
                src_idx = old_b.spaces_order.index(card)
                self.spaces_order[src_idx] = None

            if move_type != CLEAR_D:
                return

        # print "Reading spaces and goals"

        if not img:
            img = grab_screenshot()

        # Goals
        self.goals_order = [None for _ in range(3)]
        for xl in range(3):
            for y_off in range(10):
                card_img = img.crop((XTOP0 + xl * XTOPD, YTOP0 - y_off,
                                     XTOP1 + xl * XTOPD, YTOP1 - y_off))
                res = Card.from_img(card_img)
                if res:
                    self.goals_order[xl] = res.color
                    break

        # Spaces
        self.spaces_order = [None for _ in range(3)]
        for xl in range(3):
            card_img = img.crop((XSPACE0 + xl * XTOPD, YTOP0,
                                 XSPACE1 + xl * XTOPD, YTOP1))
            res = Card.from_img(card_img)
            if res:
                self.spaces_order[xl] = res
Update orders from screenshot or image.
Update orders from screenshot or image.
Update orders from screenshot or image .
def read_orders(self, img=None, old_move=None, old_b=None):
        if (old_b and old_move and
                self.num_goals_started() == old_b.num_goals_started()):
            self.goals_order = old_b.goals_order
            self.spaces_order = old_b.spaces_order[:]
            _, move_type, details, _ = old_move
            if move_type == UP_SPACES:
                idx = details
                card = old_b.piles[idx][-1]
                for dst_idx, s in enumerate(old_b.spaces_order):
                    if not s:
                        break
                self.spaces_order[dst_idx] = card
            elif move_type in [DOWN_SPACES, GOAL_S]:
                c_str, _ = details
                card = Card.from_str(c_str)
                src_idx = old_b.spaces_order.index(card)
                self.spaces_order[src_idx] = None
            if move_type != CLEAR_D:
                return
        if not img:
            img = grab_screenshot()
        self.goals_order = [None for _ in range(3)]
        for xl in range(3):
            for y_off in range(10):
                card_img = img.crop((XTOP0 + xl * XTOPD, YTOP0 - y_off,
                                     XTOP1 + xl * XTOPD, YTOP1 - y_off))
                res = Card.from_img(card_img)
                if res:
                    self.goals_order[xl] = res.color
                    break
        self.spaces_order = [None for _ in range(3)]
        for xl in range(3):
            card_img = img.crop((XSPACE0 + xl * XTOPD, YTOP0,
                                 XSPACE1 + xl * XTOPD, YTOP1))
            res = Card.from_img(card_img)
            if res:
                self.spaces_order[xl] = res
def read_orders ( self , img = None , old_move = None , old_b = None ) : if ( old_b and old_move and self . num_goals_started ( ) == old_b . num_goals_started ( ) ) : self . goals_order = old_b . goals_order self . spaces_order = old_b . spaces_order [ : ] _ , move_type , details , _ = old_move if move_type == UP_SPACES : idx = details card = old_b . piles [ idx ] [ - 1 ] for dst_idx , s in enumerate ( old_b . spaces_order ) : if not s : break self . spaces_order [ dst_idx ] = card elif move_type in [ DOWN_SPACES , GOAL_S ] : c_str , _ = details card = Card . from_str ( c_str ) src_idx = old_b . spaces_order . index ( card ) self . spaces_order [ src_idx ] = None if move_type != CLEAR_D : return if not img : img = grab_screenshot ( ) self . goals_order = [ None for _ in range ( 3 ) ] for xl in range ( 3 ) : for y_off in range ( 10 ) : card_img = img . crop ( ( XTOP0 + xl * XTOPD , YTOP0 - y_off , XTOP1 + xl * XTOPD , YTOP1 - y_off ) ) res = Card . from_img ( card_img ) if res : self . goals_order [ xl ] = res . color break self . spaces_order = [ None for _ in range ( 3 ) ] for xl in range ( 3 ) : card_img = img . crop ( ( XSPACE0 + xl * XTOPD , YTOP0 , XSPACE1 + xl * XTOPD , YTOP1 ) ) res = Card . from_img ( card_img ) if res : self . spaces_order [ xl ] = res
Update orders from screenshot or image.
Update orders from screenshot or image .
"""Update orders from screenshot or image.""" # print "Reading spaces and goals" # Goals # Spaces
self
img
old_move
old_b