当前位置: 首页 > 编程笔记 >

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

钦德佑
2023-03-14
本文向大家介绍Python实现国外赌场热门游戏Craps(双骰子),包括了Python实现国外赌场热门游戏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有所帮助。

 类似资料:
  • 我对我正在写的一个介于两者之间的骰子游戏有一个问题。我之前有另一个问题被回答了,但我仍然有一个问题。(请记住,我对一般编程非常陌生) 甚至-史蒂文!高还是低[hl]?h 模具3:9 *你赢了!* 任何关于我需要改变什么/改变它的任何帮助都将非常感谢!提前谢了。

  • 有人能在这里给我指个正确的方向吗?我的游戏工作完美,但我想添加一些实际的互动/目标。谢谢

  • 本文向大家介绍Javafx实现国际象棋游戏,包括了Javafx实现国际象棋游戏的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了Javafx实现国际象棋游戏的具体代码,供大家参考,具体内容如下 基本规则 棋子马设计“日”的移动方式 兵设计只能向前直走,每次只能走一格。但走第一步时,可以走一格或两格的移动方式 请为后设计横、直、斜都可以走,步数不受限制,但不能越子的移动方式。 车只能横向

  • 本文向大家介绍Python实现的摇骰子猜大小功能小游戏示例,包括了Python实现的摇骰子猜大小功能小游戏示例的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了Python实现的摇骰子猜大小功能小游戏。分享给大家供大家参考,具体如下: 最近学习Python的随机数,逻辑判断,循环的用法,就想找一些练习题,比如小游戏猜大小,程序思路如下: 开发环境:python2.7 , 附上源代码如下: 摇

  • 我对C#和一般编码都是新手。为了提高我的技能,我试图创建一个基本的游戏,两个玩家掷骰子,并记录他们的得分。玩家达到20分即获胜。每个玩家轮流掷一个骰子,把他们的第一个骰子加到他们的第二个骰子上,以此类推,直到其中一个达到20。如果玩家掷出一个六,他们可以再次掷骰子。 任何帮助都将不胜感激。

  • 代码的目的是让两个玩家掷一对骰子。第一个掷出20分的玩家赢得比赛。我很难弄清楚如何正确地跟踪滚动的总和;它只给我当前回合的总和,然后当每个玩家滚动10次时游戏就结束了。 我如何正确地计算每个玩家游戏的总和,然后当其中一个玩家的总和等于20时停止循环?