shenzhen-solitaire.py
def moves_to_goals(self):
        """Generate all moves to the goal places, if any legal."""
        # Moves from 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):
                new_b = deepcopy(self)
                new_b.goals[goal_stack_num].append(new_b.piles[idx].pop())
                yield new_b, ("Move %s up" % card, GOAL_P, (str(card), idx))

        # 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):
                new_b = deepcopy(self)
                new_b.goals[goal_stack_num].append(new_b.spaces.pop(idx))
                yield new_b, ("Move %s up" % card, GOAL_S, (str(card), idx))
Generate all moves to the goal places, if any legal.
Generate all moves to the goal places, if any legal.
Generate all moves to the goal places if any legal .
def moves_to_goals(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):
                new_b = deepcopy(self)
                new_b.goals[goal_stack_num].append(new_b.piles[idx].pop())
                yield new_b, ("Move %s up" % card, GOAL_P, (str(card), idx))
        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):
                new_b = deepcopy(self)
                new_b.goals[goal_stack_num].append(new_b.spaces.pop(idx))
                yield new_b, ("Move %s up" % card, GOAL_S, (str(card), idx))
def moves_to_goals ( 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 ) : new_b = deepcopy ( self ) new_b . goals [ goal_stack_num ] . append ( new_b . piles [ idx ] . pop ( ) ) yield new_b , ( "Move %s up" % card , GOAL_P , ( str ( card ) , idx ) ) 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 ) : new_b = deepcopy ( self ) new_b . goals [ goal_stack_num ] . append ( new_b . spaces . pop ( idx ) ) yield new_b , ( "Move %s up" % card , GOAL_S , ( str ( card ) , idx ) )
Generate all moves to the goal places, if any legal.
Generate all moves to the goal places if any legal .
"""Generate all moves to the goal places, if any legal.""" # Moves from piles to goals # Now, from spaces to goals
self