In [12]:
from cribbage.cards import *
from cribbage.cribbage_score import *
In [13]:
%matplotlib inline
import numpy as np
from matplotlib import pyplot as plt
from collections import Counter
import itertools
def generate_5scores():
while True:
h, d = make_random_hand_and_draw()
yield score_hand(h, d)
samples5 = np.array(list(itertools.islice(generate_5scores(), 500000)))
plt.hist(samples5, 29, (0,29))
plt.title('Histograms of scores of random 4-card hands plus a draw')
plt.xlabel('Score')
plt.ylabel('Count')
Counter(samples5)
Out[13]:
In [14]:
plt.hist(samples5, 15, (0,30))
plt.title('Histograms of scores of random 4-card hands plus a draw (even-odd averaged)')
plt.xlabel('Score')
plt.ylabel('Count')
Out[14]:
In [15]:
%timeit h,d = make_random_hand_and_draw() ; score_hand(h,d)
In [19]:
from cribbage import _cribbage_score as c_cribbage_score
%timeit h,d = make_random_hand_and_draw() ; c_cribbage_score.score_hand(h,d)
In [21]:
h,d = make_random_hand_and_draw()
%timeit score_hand(h,d)
In [22]:
%timeit c_cribbage_score.score_hand(h,d)
In [23]:
%timeit h,d = make_random_hand_and_draw()