Browse Source

first commit

VollYoung 6 years ago
parent
commit
6b56783dda
1 changed files with 114 additions and 0 deletions
  1. 114 0
      TaiSai.py

+ 114 - 0
TaiSai.py

@@ -0,0 +1,114 @@
+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<amount
+        
+
+    def lose(self):
+        print("lose...剩余本金:%d" %(self.principal))
+
+        
+    def isWin(self):
+        """ 每次买小 , 小于等于10当赢"""
+        random.seed(random.randint(1, 100000))
+        one = random.randint(1,6) 
+        two = random.randint(1,6) 
+        three = random.randint(1,6) 
+
+        result = one + two + three
+
+        self.logGameResult(one,two,three,result,result<=10)
+
+        return result <=10
+
+    def logStart(self,i,money):
+        print("第%d轮,本金%d ,初次下注金额:%d" %(i,self.principal,money))
+
+    def logGameStart(self,money):
+        print("下注金额:%d  剩余本金:%d" %(money,self.principal))
+
+    def logWin(self,money):
+        print("赢了,结束本轮,收入:%d 剩余本金:%d" %(money,self.principal))
+        print("")
+
+    def logGameResult(self,one,two,three,result,isWin):
+        print("本轮结果:%d %d %d = %d  %s" %(one ,two ,three ,result ,"赢" if isWin else "输"))
+
+    def logResult(self,i):
+        print("游戏%d轮结束 , 剩余本金:%d" %(i ,self.principal))
+
+
+if __name__ == '__main__':
+
+    count = 100
+    principal = 1000000
+    
+    bet = betSize(count,principal)
+    bet.gambling()
+
+