def weave_shuffle(deck, p=16): """Return the deck slightly shuffled, like a human might do it. First cut the deck, then weave it together again in p partitions.""" n = len(deck) for i in range(p/2-1): deck = deck[:n/p+2*i*n/p] + deck[n/2+i*n/p:n/2+(i+1)*n/p] + deck[n/p+2*i*n/p:n/2+i*n/p] + deck[n/2+(i+1)*n/p:] return deck def cut(deck): n = len(deck) deck = deck[n/2:] + deck[:n/2] return deck def human_deal(numhands, n=5, deck=[r+s for r in '23456789TJQKA' for s in 'SHDC']): "Don't shuffle, and deal the cards one by one." return zip(*[deck[i*numhands:(i+1)*numhands] for i in range(n)]) # usage example: deck=[r+s for r in '23456789TJQKA' for s in 'SHDC'] deck = weave_shuffle(deck) deck = weave_shuffle(deck) deck = weave_shuffle(deck) deck = cut(deck) hands = human_deal(4, 5, deck) for hand in hands: print hand # At this point you might sort and evaluate the hands, then return them to # the bottom of the deck. Shuffle, cut, and deal again. # Repeat this some hundred thousand times and watch how probabilities differ # compared to 'computer shuffled' hands.
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question