利用Python分析快三骰子游戏

# -*- coding: utf-8 -*-
"""
Created on Tue Jan 24 13:07:01 2017

@author: Wayne
"""
   
import random 
import pandas as pd
import matplotlib.pylab as pl

list1 = []
list2 = []
m4,m5,m6,m7,m8,m9,m10,m11,m12,m13,m14,m15,m16,m17 = 0,0,0,0,0,0,0,0,0,0,0,0,0,0  # 和值遗漏
same1,same2,same3,same4,same5,same6,same = 0,0,0,0,0,0,0  # 豹子遗漏

i = 0
while(i<5000):
    a = random.randint(1,6)
    b = random.randint(1,6)
    c = random.randint(1,6)
    
    list1.append(a)
    list1.append(b)
    list1.append(c)
    list1.append(a+b+c)
    
    if a+b+c == 4:
        m4 = 0
    else:
        m4 += 1
    list1.append(m4)
    
    if a+b+c == 5:
        m5 = 0
    else:
        m5 += 1
    list1.append(m5)
    
    if a+b+c == 6:
        m6 = 0
    else:
        m6 += 1
    list1.append(m6)
    
    if a+b+c == 7:
        m7 = 0
    else:
        m7 += 1
    list1.append(m7)
    
    if a+b+c == 8:
        m8 = 0
    else:
        m8 += 1
    list1.append(m8)
    
    if a+b+c == 9:
        m9 = 0
    else:
        m9 += 1
    list1.append(m9)
    
    if a+b+c == 10:
        m10 = 0
    else:
        m10 += 1
    list1.append(m10)
    
    if a+b+c == 11:
        m11 = 0
    else:
        m11 += 1
    list1.append(m11)
    
    if a+b+c == 12:
        m12 = 0
    else:
        m12 += 1
    list1.append(m12)
    
    if a+b+c == 13:
        m13 = 0
    else:
        m13 += 1
    list1.append(m13)
    
    if a+b+c == 14:
        m14 = 0
    else:
        m14 += 1
    list1.append(m14)
    
    if a+b+c == 15:
        m15 = 0
    else:
        m15 += 1
    list1.append(m15)
    
    if a+b+c == 16:
        m16 = 0
    else:
        m16 += 1
    list1.append(m16)
    
    if a+b+c == 17:
        m17 = 0
    else:
        m17 += 1
    list1.append(m17)
 
    if a==b==c==1:
        same1 = 0
    else:
        same1 += 1
    list1.append(same1)
    
    if a==b==c==2:
        same2 = 0
    else:
        same2 += 1
    list1.append(same2)
 
    if a==b==c==3:
        same3 = 0
    else:
        same3 += 1
    list1.append(same3)
    
    if a==b==c==4:
        same4 = 0
    else:
        same4 += 1
    list1.append(same4)
 
    if a==b==c==5:
        same5 = 0
    else:
        same5 += 1
    list1.append(same5)
    
    if a==b==c==6:
        same6 = 0
    else:
        same6 += 1
    list1.append(same6)   
    
    if a==b==c:
        same = 0
    else:
        same += 1
    list1.append(same)
           
    list2.append(list1)
    list1 = []

    i+=1
    
fields = ['a','b','c','sum3','m4','m5','m6','m7','m8','m9','m10','m11','m12','m13','m14','m15','m16','m17','same1','same2','same3','same4','same5','same6','same']
dicedf = pd.DataFrame(list2,columns=fields)

pm1 = pl.subplot(221)
pm2 = pl.subplot(222)
pm3 = pl.subplot(223)
pm4 = pl.subplot(224)

pm1.plot(dicedf.index,dicedf.m4,label='m4')
pm2.plot(dicedf.index,dicedf.m5,label='m5')
pm3.plot(dicedf.index,dicedf.m16,label='m16')
pm4.plot(dicedf.index,dicedf.m17,label='m17')

pm1.legend(loc='upper left')
pm2.legend(loc='upper left')
pm3.legend(loc='upper left')
pm4.legend(loc='upper left')

'''
p1 = pl.subplot(331)
p2 = pl.subplot(332)
p3 = pl.subplot(333)
p4 = pl.subplot(334)
p5 = pl.subplot(335)
p6 = pl.subplot(336)
p7 = pl.subplot(337)

p1.plot(dicedf.index,dicedf.same1,label='same1')
p2.plot(dicedf.index,dicedf.same2,label='same2')
p3.plot(dicedf.index,dicedf.same3,label='same3')
p4.plot(dicedf.index,dicedf.same4,label='same4')
p5.plot(dicedf.index,dicedf.same5,label='same5')
p6.plot(dicedf.index,dicedf.same6,label='same6')
p7.plot(dicedf.index,dicedf.same,label='same')

p1.legend(loc='upper left')
p2.legend(loc='upper left')
p3.legend(loc='upper left')
p4.legend(loc='upper left')
p5.legend(loc='upper left')
p6.legend(loc='upper left')
p7.legend(loc='upper left')
'''


        

主要模拟三个骰子投掷情况

和值遗漏曲线:

 

豹子遗漏曲线:

 

posted on 2017-02-05 22:59  你的踏板车要滑向哪里  阅读(1457)  评论(0编辑  收藏  举报

导航