shenzhen-solitaire.py
def autoclear(self):
        """If an automatic (game-made) move is available, return that board."""
        # Piles to goals
        for idx, pile in enumerate(self.piles):
            if not pile:
                continue

            card = pile[-1]
            if card.ctype != NUMBER:
                continue

            goal_stack_num = COLORS.index(card.color)
            goal_stack = self.goals[goal_stack_num]
            if (not goal_stack and card.number == 1) or (
                    goal_stack and goal_stack[-1].number == card.number - 1):
                n = card.number - 1
                count = 0

                for goal_stack in self.goals:
                    if len(goal_stack) >= n:
                        count += 1

                if count == 3 or card.number == 2:
                    new_b = deepcopy(self)
                    new_b.goals[goal_stack_num].append(new_b.piles[idx].pop())
                    return new_b

        # Now, from spaces to goals
        for idx, card in enumerate(self.spaces):
            if card.ctype != NUMBER:
                continue

            goal_stack_num = COLORS.index(card.color)
            goal_stack = self.goals[goal_stack_num]
            if (not goal_stack and card.number == 1) or (
                    goal_stack and goal_stack[-1].number == card.number - 1):
                n = card.number - 1
                count = 0

                for goal_stack in self.goals:
                    if len(goal_stack) >= n:
                        count += 1

                if count == 3 or card.number == 2:
                    new_b = deepcopy(self)
                    new_b.goals[goal_stack_num].append(new_b.spaces.pop(idx))
                    return new_b

        # Clear rose
        for idx, pile in enumerate(self.piles):
            if not pile:
                continue

            card = pile[-1]
            if card.ctype != ROSE:
                continue

            new_b = deepcopy(self)
            new_b.piles[idx].pop()
            new_b.rose_cleared = True
            return new_b

        return None
If an automatic (game-made) move is available, return that board.
If an automatic (game-made) move is available, return that board.
If an automatic ( game - made ) move is available return that board .
def autoclear(self):
        for idx, pile in enumerate(self.piles):
            if not pile:
                continue
            card = pile[-1]
            if card.ctype != NUMBER:
                continue
            goal_stack_num = COLORS.index(card.color)
            goal_stack = self.goals[goal_stack_num]
            if (not goal_stack and card.number == 1) or (
                    goal_stack and goal_stack[-1].number == card.number - 1):
                n = card.number - 1
                count = 0
                for goal_stack in self.goals:
                    if len(goal_stack) >= n:
                        count += 1
                if count == 3 or card.number == 2:
                    new_b = deepcopy(self)
                    new_b.goals[goal_stack_num].append(new_b.piles[idx].pop())
                    return new_b
        for idx, card in enumerate(self.spaces):
            if card.ctype != NUMBER:
                continue
            goal_stack_num = COLORS.index(card.color)
            goal_stack = self.goals[goal_stack_num]
            if (not goal_stack and card.number == 1) or (
                    goal_stack and goal_stack[-1].number == card.number - 1):
                n = card.number - 1
                count = 0
                for goal_stack in self.goals:
                    if len(goal_stack) >= n:
                        count += 1
                if count == 3 or card.number == 2:
                    new_b = deepcopy(self)
                    new_b.goals[goal_stack_num].append(new_b.spaces.pop(idx))
                    return new_b
        for idx, pile in enumerate(self.piles):
            if not pile:
                continue
            card = pile[-1]
            if card.ctype != ROSE:
                continue
            new_b = deepcopy(self)
            new_b.piles[idx].pop()
            new_b.rose_cleared = True
            return new_b
        return None
def autoclear ( self ) : for idx , pile in enumerate ( self . piles ) : if not pile : continue card = pile [ - 1 ] if card . ctype != NUMBER : continue goal_stack_num = COLORS . index ( card . color ) goal_stack = self . goals [ goal_stack_num ] if ( not goal_stack and card . number == 1 ) or ( goal_stack and goal_stack [ - 1 ] . number == card . number - 1 ) : n = card . number - 1 count = 0 for goal_stack in self . goals : if len ( goal_stack ) >= n : count += 1 if count == 3 or card . number == 2 : new_b = deepcopy ( self ) new_b . goals [ goal_stack_num ] . append ( new_b . piles [ idx ] . pop ( ) ) return new_b for idx , card in enumerate ( self . spaces ) : if card . ctype != NUMBER : continue goal_stack_num = COLORS . index ( card . color ) goal_stack = self . goals [ goal_stack_num ] if ( not goal_stack and card . number == 1 ) or ( goal_stack and goal_stack [ - 1 ] . number == card . number - 1 ) : n = card . number - 1 count = 0 for goal_stack in self . goals : if len ( goal_stack ) >= n : count += 1 if count == 3 or card . number == 2 : new_b = deepcopy ( self ) new_b . goals [ goal_stack_num ] . append ( new_b . spaces . pop ( idx ) ) return new_b for idx , pile in enumerate ( self . piles ) : if not pile : continue card = pile [ - 1 ] if card . ctype != ROSE : continue new_b = deepcopy ( self ) new_b . piles [ idx ] . pop ( ) new_b . rose_cleared = True return new_b return None
If an automatic (game-made) move is available, return that board.
If an automatic ( game - made ) move is available return that board .
"""If an automatic (game-made) move is available, return that board.""" # Piles to goals # Now, from spaces to goals # Clear rose
self