import random class betSize(object): """ 假设有足够多的钱 ,庄家愿意一直玩就不会输 1.初次下注基本金额足够少,本金1/100 2.之后每次下注为上一次金额的翻倍 3.直到第一次赢了后,回到步骤1 """ def __init__(self,count,principal): self.count = count self.principal = principal def gambling(self): """""" c =0 for i in range(self.count): c =i+1 #初次下注金额 money = self.principal/100 self.logStart(c, money) if not self.game(money): break self.logResult(c) def game(self,amount): """ 游戏开始, amount=下注金额 """ #下注 self.bet(amount) self.logGameStart(amount) if (not self.isWin()): #下轮下注金额 nextAmount =amount * 2 if(self.isLose(nextAmount)): self.lose() return False else: return self.game(nextAmount) else: self.win(amount) return True def bet(self,money): """下注 , money = 下注金额""" self.principal -= money return money def win(self,money): self.principal += money * 2 self.logWin(money*2) def isLose(self,amount): return self.principal<=0 or self.principal