您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Python实现国外赌场热门游戏Craps(双骰子)

2024/4/11 15:38:19发布22次查看
运行方法:
1. 打开python2 idle;
    2. 输入 from craps import *
    3. 按提示输入运行命令。例如,玩游戏就输入play();查看余额就输入check_bankroll();
        自动玩看胜率就输入auto()
craps.py
import random point_set = falsebet = 10bankroll = 1000sim_win = 0sim_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 >) 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有所帮助。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product