前言
哈哈哈有点标题党内味儿了。
接着昨天那个欢乐斗牛的小程序,我又模拟了一种极为简单的情形:
- 四人游戏,1号玩家为庄家,其他玩家为闲家;
- 庄家自由注入起始金额(模型中简化为30、50、100);
- 当奖池金额高于某一特定数值时,庄家可以选择终止游戏;
- 奖池金额为负数时庄家立即停止游戏;
- 闲家自由下注(模型中简化为:每次闲家下注金额为 (奖池金额/闲家人数) 的四分之一或二分之一,并且每位玩家下注不会超过30元)
代码
import numpy as np
import pandas as pd
from singleniuniu import Poker
class Gambling(object):
"""docstring for Gambling"""
def __init__(self, n, pool):
super(Gambling, self).__init__()
self.pool = pool
self.n = n
def settle(self):
self.stakes = 0
for i in range(self.n):
multi = np.random.randint(1,3)
stake = (self.pool / (self.n - 1)) * (multi / 4)
if stake > 30:
stake = 30
self.stakes += stake
def play(self):
self.settle()
self.nn = Poker(self.n)
self.nn.play()
self.pool = self.pool + (self.stakes * self.nn.total)
li = []
for limit in [x*100 for x in range(1,11)]:
for start in [30, 50, 100]:
for i in range(1000):
B = Gambling(4, start)
B.play()
r = 1
while 1:
if (B.pool > 0) and (B.pool < limit):
B = Gambling(3, B.pool)
B.play()
r = r+1
else:
break
piece = {
'起始金额': start,
'结束限额': limit,
'坚持的轮数': r,
'最终金额': B.pool
}
li.append(piece)
结果
从代码里面可以看出,我每种情况都模拟了一千次。下面是程序运行的结果。
Comments | NOTHING