In [80]:
import numpy as np
import scipy
from scipy.stats import randint, cumfreq
np.random.seed(1)

In [81]:
NUM_PLAYERS = 4
NUM_CARDS = 24

freq = np.zeros(NUM_CARDS)
player_pos = np.zeros(NUM_PLAYERS, dtype=np.int)
print(randint.rvs(1, 7, size=NUM_PLAYERS))

for turn in range(50):
    player_pos += randint.rvs(1, 7, size=NUM_PLAYERS)
    player_pos += randint.rvs(1, 7, size=NUM_PLAYERS)
    player_pos %= NUM_CARDS
    for x in player_pos:
        freq[x] += 1
print("BOARD GAME DISTRIBUTION")
print(freq)
board_game_freq = freq

freq = np.zeros(NUM_CARDS)
DECKS=1
cards = np.arange(NUM_CARDS*DECKS) % NUM_CARDS
on_card = NUM_CARDS*DECKS
for turn in range(50):
    for x in range(NUM_PLAYERS):
        if on_card >= (NUM_CARDS//2)*DECKS:
            on_card = 0
            np.random.shuffle(cards)
        freq[cards[on_card]] += 1
        on_card += 1
print("CARD GAME FIXED STOP DISTRIBUTION")
print(freq)
print(np.mean(freq),np.var(freq))
card_game_freq = freq

print("Divergence:",scipy.stats.ks_2samp(board_game_freq, freq))

NUM_SHUFFLE_CARDS = 2
freq = np.zeros(NUM_CARDS)
cards = np.arange(NUM_CARDS + NUM_SHUFFLE_CARDS)
on_card = 0
np.random.shuffle(cards)
cards_until_shuffle = np.zeros(NUM_CARDS+NUM_SHUFFLE_CARDS)

for turn in range(50000):
    for x in range(NUM_PLAYERS):
        while cards[on_card] >= NUM_CARDS:
            # Got a shufle card
            cards_until_shuffle[on_card]+=1
            on_card = 0
            np.random.shuffle(cards)
        freq[cards[on_card]] += 1
        on_card += 1
print("CARD GAME SHUFFLE CARD DISTRIBUTION")
print(freq)
print(cards_until_shuffle)
print(np.cumsum(cards_until_shuffle) / np.sum(cards_until_shuffle))
print(np.mean(freq),np.var(freq))
print("Divergence:",scipy.stats.ks_2samp(board_game_freq, freq))
print("Divergence:",scipy.stats.ks_2samp(card_game_freq, freq))


[6 4 5 1]
BOARD GAME DISTRIBUTION
[  6.   4.   9.  13.   7.   6.  12.   9.   7.  11.   9.   6.  11.  10.   6.
   8.  11.   4.   6.  14.   5.   8.  11.   7.]
CARD GAME FIXED STOP DISTRIBUTION
[  8.  12.   6.   9.   9.   8.   8.   8.   7.   8.   6.  11.  10.   8.  11.
   7.   7.   5.   7.  15.   8.   5.  11.   6.]
8.33333333333 5.38888888889
Divergence: Ks_2sampResult(statistic=0.125, pvalue=0.9867794517653834)
CARD GAME SHUFFLE CARD DISTRIBUTION
[ 8330.  8357.  8312.  8327.  8161.  8293.  8350.  8310.  8425.  8410.
  8407.  8379.  8386.  8321.  8344.  8304.  8305.  8254.  8318.  8207.
  8424.  8363.  8397.  8316.]
[ 1960.  1830.  1702.  1686.  1622.  1547.  1526.  1399.  1283.  1278.
  1150.  1109.   977.   877.   799.   786.   707.   588.   528.   431.
   410.   338.   240.   156.    75.     0.]
[ 0.07838746  0.15157575  0.21964486  0.28707407  0.35194369  0.41381379
  0.47484402  0.53079507  0.58210686  0.63321869  0.67921133  0.72356423
  0.76263798  0.79771237  0.82966725  0.86110222  0.8893777   0.91289394
  0.93401056  0.9512478   0.96764518  0.98116301  0.99076148  0.99700048
  1.          1.        ]
8333.33333333 3985.55555556
Divergence: Ks_2sampResult(statistic=1.0, pvalue=8.8051854836893306e-12)
Divergence: Ks_2sampResult(statistic=1.0, pvalue=8.8051854836893306e-12)

In [ ]:


In [ ]: