博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
利用Python分析快三骰子游戏
阅读量:5095 次
发布时间:2019-06-13

本文共 3647 字,大约阅读时间需要 12 分钟。

# -*- coding: utf-8 -*-"""Created on Tue Jan 24 13:07:01 2017@author: Wayne"""   import random import pandas as pdimport matplotlib.pylab as pllist1 = []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 = 0while(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')'''

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

和值遗漏曲线:

 

豹子遗漏曲线:

 

转载于:https://www.cnblogs.com/wnzhong/p/6368811.html

你可能感兴趣的文章
Linux常用命令
查看>>
Master选举原理
查看>>
Objective-C在ARC下结合GCD的单例模式和宏模版
查看>>
zuul入门(5)zuul 处理异常
查看>>
SpringBoot+Angular2 开发环境搭建
查看>>
C++编程--类与继承(3)
查看>>
nvl()函数和nvl2()函数
查看>>
蓝桥杯入门(一)
查看>>
[BZOJ 3995] [SDOI2015] 道路修建 【线段树维护连通性】
查看>>
nodejs中安装webpack的简单使用
查看>>
array_combine php一个比较偏门的数组函数
查看>>
js数字转换为float,取N个小数
查看>>
lr参数化取值规则总结
查看>>
RN的第一个API-----注册组件Appregistry
查看>>
DevExpress Gridcontrol 显示序号列
查看>>
Delphi实现大写字母键打开提示
查看>>
SqlServer2008 数据库同步的两种方式 (发布、订阅)
查看>>
VS2010中,无法嵌入互操作类型“……”,请改用适用的接口的解决方法
查看>>
SpringBoot之springfox(Swagger) (ApiDoc接口文档)
查看>>
上手React Native--常用属性介绍
查看>>