Python實現(xiàn)國外賭場熱門游戲Craps(雙骰子)
運行方法:
1. 打開python2 IDLE;
2. 輸入 from craps import *
3. 按提示輸入運行命令。例如,玩游戲就輸入play();查看余額就輸入check_bankroll();
自動玩看勝率就輸入auto()
craps.py
import random point_set = False bet = 10 bankroll = 1000 sim_win = 0 sim_lose = 0 print """ Welcome to the 'Seven Star' casino! You are playing craps now, your started bankroll is '$1000', the started bet is '$10', command: play(): "Rolling the dices" check_bankroll(): "Checking your current balance" all_in(): Showing "hand" set_bet(): "Setting a new bet" game(): "Check your game status" auto(): "It can be played automatically for you until reach a specific bankroll" """ def roll(): d1 = random.randrange(1,7) d2 = random.randrange(1,7) print "You rolled", d1, "+", d2, "=", d1+d2 return d1 + d2 def play(): global point_set, bankroll, point global sim_win, sim_lose if bankroll < bet: print "Sorry, you can't play since you don't have enough money!" print """Do you wanna get more money? 1: Yes 2: No """ choice = raw_input(">>") if choice == str(1): money = raw_input("How much do you wanna get?") bankroll += int(money) print "Your current bankroll is: ", bankroll if choice == str(2): print "Thanks for playing! See you next time!" else: if not point_set: print print "New game. Your bet is: ", bet # for the first roll r = roll() if not point_set: if r in (7, 11): bankroll += bet sim_win += 1 print "Congratz! You Won! Your bankroll is: ", bankroll elif r in (2, 3, 12): bankroll -= bet sim_lose += 1 print "Oops! You lost! Your bankroll is: ", bankroll else: point = r point_set = True print "Your point is", "[", point, "]" # for subsequence rolls elif r == 7: bankroll -= bet sim_lose += 1 point_set = False print "You crapped out! Your bankroll is: ", bankroll elif r == point: bankroll += bet sim_win += 1 point_set = False print "You made your point! Your bankroll is: ", bankroll def set_bet(inp): global bet, bankroll, point_set print if point_set: print "WARNING!" print "The game has started, you will lose half of your bet if resetting your bet!" prompt = raw_input(""" 1: Yes, I am wanna reset my bet! 2: No, I don't wanna reset my bet! """) if prompt == "1": point_set = False bankroll -= bet/2 print "Forfeiting current bet. Your bankroll is: ", bankroll else: pass bet = int(inp) print "New bet size is: ", bet def all_in(): set_bet(bankroll) def check_bankroll(): global bet print "Your current balance is: ", bankroll def game(): total = sim_win + sim_lose percent = float(sim_win)/total * 100 print "So far, the games that you have been playing are: ", total print "Won ", sim_win print "Lost ", sim_lose print "Overall, you have %d%% to win!" %percent def auto(): game_status = True purpose = raw_input("How much are you gonna reach? ") while game_status: play() if bankroll == int(purpose) or bankroll == 0: game_status = False game()
以上所述就是本文的全部內容了,希望能夠對大家學習Python有所幫助。
相關文章
Python實現(xiàn)的ftp服務器功能詳解【附源碼下載】
這篇文章主要介紹了Python實現(xiàn)的ftp服務器功能,結合實例形式分析了Python構建ftp服務器功能的相關設置、實現(xiàn)技巧與操作注意事項,并附帶源碼供讀者下載參考,需要的朋友可以參考下2019-06-06python pands實現(xiàn)execl轉csv 并修改csv指定列的方法
今天小編就為大家分享一篇python pands實現(xiàn)execl轉csv 并修改csv指定列的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12Flask框架通過Flask_login實現(xiàn)用戶登錄功能示例
這篇文章主要介紹了Flask框架通過Flask_login實現(xiàn)用戶登錄功能,結合實例形式較為詳細的分析了flask框架使用Flask_login實現(xiàn)用戶登陸功能的具體操作步驟、相關實現(xiàn)技巧與操作注意事項,需要的朋友可以參考下2018-07-07Python使用asyncio.Queue進行任務調度的實現(xiàn)
本文主要介紹了Python使用asyncio.Queue進行任務調度的實現(xiàn),它可以用于任務調度和數(shù)據(jù)交換,文中通過示例代碼介紹的非常詳細,感興趣的可以了解一下2024-02-02python numpy矩陣信息說明,shape,size,dtype
這篇文章主要介紹了python numpy矩陣信息說明,shape,size,dtype,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-05-05Python實現(xiàn)刪除當前目錄下除當前腳本以外的文件和文件夾實例
這篇文章主要介紹了Python實現(xiàn)刪除當前目錄下除當前腳本以外的文件和文件夾的方法,涉及Python針對目錄及文件的刪除技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07Python 對象序列化與反序列化之pickle json詳細解析
我們知道在Python中,一切皆為對象,實例是對象,類是對象,元類也是對象。本文正是要聊聊如何將這些對象有效地保存起來,以供后續(xù)使用2021-09-09