Skip to content

Instantly share code, notes, and snippets.

@DIYer22
Created June 12, 2017 14:55
Show Gist options
  • Save DIYer22/183bb8d19be4b9cd7e5b44ce23b29679 to your computer and use it in GitHub Desktop.
Save DIYer22/183bb8d19be4b9cd7e5b44ce23b29679 to your computer and use it in GitHub Desktop.
用于验证百分百胜利的赌博博弈模型 缺点是需要准备大量资金 由于不会化简一个含有迭代的公式 数学模型 还没能成功后建立
# -*- coding: utf-8 -*-
from pylab import *
'''
用于验证百分百胜利的赌博博弈模型
缺点是需要准备大量资金
数学模型由于不会化简一个基于迭代的公式
还没能成功后建立
'''
totalround = 100 # 赌博次数
alll = 0 # 初始本金(可以欠钱)
batch = 10 # 显示几次中间结果
goalinit = 10 # 每次目标挣多少
winrate = 0.7 # 胜率
lossrate = 0.95 # 费用率
'''
赢的回报率为
(赌注/胜率)*费用率
即 (pay/winrate)*lossrate
蓝线:总资产
红线:那一局的胜负
绿线:连续为输的情况下 对应的赔款(赢一局即清空为0)
'''
#totalround=batch=200
getRate = lossrate/winrate
payWinRate = lambda x:x*getRate
winPayRate = lambda y:y/(getRate-1)
gen = np.random.random(totalround)
shuffle(gen)
wins = gen < winrate
#wins = gen < winrate*0
#wins[-1] = True
goal = goalinit
pay = winPayRate(goalinit)
loss = 0
alls,losss = [],[]
for ind,win in enumerate(wins):
alll -= pay
loss += pay
oldgoal = goal
if win:
get = payWinRate(pay)
alll += get
goal = goalinit
pay = winPayRate(goalinit)
loss = 0
else:
goal = loss+goalinit
pay = winPayRate(goal)
alls += [alll]
losss+= [loss]
# continue
# print ind,oldgoal,pay,win,loss,goal,alll
if ind%(totalround//batch)==0:
print 'ind:%d, oldgoal:%.2f, pay:%.2f, win:%s, loss:%.2f, goal:%.2f, all:%d'%(
ind,oldgoal,pay,win,loss,goal,alll)
plot(alls)
plot(losss)
plot(goalinit*2/batch*totalround*winrate*wins[:ind+1])
show()
losss = np.array(losss)
alls = np.array(alls)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment