Skip to content

Instantly share code, notes, and snippets.

@brine
Last active December 22, 2015 06:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brine/6428912 to your computer and use it in GitHub Desktop.
Save brine/6428912 to your computer and use it in GitHub Desktop.
mechanical shuffles
def riffleShuffle(group, x = 0, y = 0):
mute()
deck = []
for c in group:
deck.append(c) ##loads the deck contents into a list
topChunk = deck[:len(deck)/2] ##Grabs the top half of the deck
bottomChunk = deck[len(deck)/2:] ##Grabs the bottom half of the deck
deck = [] #This'll be the new deck stack
while len(bottomChunk) > 0: ##keep looping as long as there's still cards
deck.insert(0, bottomChunk.pop()) ##The bottom of the chunk gets added to the top of the deck
if len(topChunk) > 0: ##The bottom chunk will always have 1 more card if the deck was odd-numbered, due to rounding
deck.insert(0, topChunk.pop())
for c in deck:
c.moveToBottom(me.Library) ##Moves to bottom to maintain the same deck order
notify("{} riffle-shuffles their Library.".format(me))
def pileShuffle(group, x = 0, y = 0):
mute()
deck = []
for c in group:
deck.append(c) ##loads the deck contents into a list
piles = []
pileCount = askInteger('How many piles?', 5) ##default is 5 piles
for num in xrange(0, pileCount): ##loops from 0 to 4, each one being the starting index of the list
piles.append(deck[num::pileCount]) ## Distributes the cards into the specified number of piles
for pile in piles:
for c in pile:
c.moveToBottom(group)
notify("{} pile-shuffles their Library.".format(me))
@kellyelton
Copy link

This is dirty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment