The Deal:
Python code used
for Monte Carlo simulations:# -*- coding: utf-8 -*-
"""
Created on Mon Sep 17 13:06:22 2018
@author: R. Lucas Thomas III
"""
import collections
import matplotlib.pyplot as plt
import numpy
import random
from scipy import stats
def deal(deck, players, cardsperplayer):
hands = []
for i in xrange(0,players):
newhand = deck[i*cardsperplayer:(i*(cardsperplayer)+cardsperplayer)]
hands.append(newhand)
return hands
def finddealer(hands,levels):
ordinal = 1
for c in xrange(0,20):
for p in xrange(0,5):
if hands[p][c][0] == levels[p]:
if len(hands[p][c]) != 1:
return [p,c,ordinal]
else:
ordinal += 1
return "No dealer"
def haspoints(hand):
for c in hand:
if c[0] == '5':
return True
elif c[0] == 'K':
return True
for c in hand:
if len(c) == 3:
return True
return False
def countpairs(hand):
return len(hand)-len(set(hand))
def trumpcount(hand, level):
trump = 0
rank = level[:1]
suit = level[-1:]
for c in hand:
if c == "J":
trump += 1
elif c == "j":
trump += 1
elif c[-1:] == suit:
trump += 1
elif c[:1] == rank:
trump += 1
return trump
twodecks = []
suits = ['s','h','c','d']
ranks = ['A','K','Q','J','10','9','8','7','6','5','4','3','2']
#form cards by appending suits to ranks and adding the result to the deck
for r in ranks:
for s in suits:
twodecks.append(r+s)
twodecks.append(r+s)
twodecks.append('J')
twodecks.append('J')
twodecks.append('j')
twodecks.append('j')
testdeals = 100000
handcount = 0
paircountlist = []
for a in xrange(0,testdeals):
random.shuffle(twodecks)
hands = deal(twodecks, 5, 20)
for h in hands:
handcount += 1
paircountlist.append(countpairs(h))
print paircountlist.count(4)/float(handcount)
trumpcounts = []
for a in xrange(0,testdeals):
random.shuffle(twodecks)
hands = deal(twodecks, 5, 20)
for h in hands:
handcount += 1
trumpcounts.append(trumpcount(h,"2s"))
results = ""
for cnt in xrange(0,16):
results += str(cnt) + " "
results += str(100*trumpcounts.count(cnt)/float(handcount)) + "% "
print results
#First Card Flipped Probability
firstflipped = []
for a in xrange(0,testdeals):
random.shuffle(twodecks)
bottomeight = twodecks[-8:]
hands = deal(twodecks, 5, 20)
levels = ['2','2','2','2','2']
firstflipped.append(finddealer(hands,levels)[2])
ff = numpy.array(firstflipped)
plt.hist(ff)
plt.show()
print "Average card flipped: " + str(numpy.mean(ff))
print "Median card flipped: " + str(numpy.median(ff))
print "Mode card flipped: " + str(stats.mode(ff)[0])
print "Probability of draw flip: " + str(100*collections.Counter(firstflipped)[10]/float(testdeals)) + "%"
#Pointless Hand Probability
redeal = 0
pointlesscount = 0
handcount = 0
for a in xrange(0,testdeals):
random.shuffle(twodecks)
bottomeight = twodecks[-8:]
hands = deal(twodecks, 5, 20)
haspointless = 0
for h in hands:
handcount += 1
if haspoints(h) == False:
pointlesscount += 1
haspointless = 1
if haspointless == 1:
redeal += 1
print "Redealt hands: " + str(redeal)
print pointlesscount
print handcount
print redeal/float(testdeals)