shenzhen-solitaire.py
def move_piles(self):
        """Generate all moves between piles."""
        for idx, pile in enumerate(self.piles):
            if not pile:
                continue

            prev = None
            for idy, card in reversed(list(enumerate(pile))):
                if prev is not None and not prev.goes_on(card):
                    break
                prev = card

                for dst_idx, dst_pile in enumerate(self.piles):
                    if dst_idx == idx:
                        continue

                    if not dst_pile or card.goes_on(dst_pile[-1]):
                        new_b = deepcopy(self)
                        new_b.piles[dst_idx].extend(new_b.piles[idx][idy:])
                        new_b.piles[idx] = new_b.piles[idx][:idy]
                        yield new_b, ("Move %s (%s) to %s" %
                                      (card, idx + 1, dst_idx + 1),
                                      PILE, (idx, idy, dst_idx))
Generate all moves between piles.
Generate all moves between piles.
Generate all moves between piles .
def move_piles(self):
        for idx, pile in enumerate(self.piles):
            if not pile:
                continue
            prev = None
            for idy, card in reversed(list(enumerate(pile))):
                if prev is not None and not prev.goes_on(card):
                    break
                prev = card
                for dst_idx, dst_pile in enumerate(self.piles):
                    if dst_idx == idx:
                        continue
                    if not dst_pile or card.goes_on(dst_pile[-1]):
                        new_b = deepcopy(self)
                        new_b.piles[dst_idx].extend(new_b.piles[idx][idy:])
                        new_b.piles[idx] = new_b.piles[idx][:idy]
                        yield new_b, ("Move %s (%s) to %s" %
                                      (card, idx + 1, dst_idx + 1),
                                      PILE, (idx, idy, dst_idx))
def move_piles ( self ) : for idx , pile in enumerate ( self . piles ) : if not pile : continue prev = None for idy , card in reversed ( list ( enumerate ( pile ) ) ) : if prev is not None and not prev . goes_on ( card ) : break prev = card for dst_idx , dst_pile in enumerate ( self . piles ) : if dst_idx == idx : continue if not dst_pile or card . goes_on ( dst_pile [ - 1 ] ) : new_b = deepcopy ( self ) new_b . piles [ dst_idx ] . extend ( new_b . piles [ idx ] [ idy : ] ) new_b . piles [ idx ] = new_b . piles [ idx ] [ : idy ] yield new_b , ( "Move %s (%s) to %s" % ( card , idx + 1 , dst_idx + 1 ) , PILE , ( idx , idy , dst_idx ) )
Generate all moves between piles.
Generate all moves between piles .
"""Generate all moves between piles."""
self