python写的掷骰子小游戏,python掷骰子小游戏,规则来自于此:http:
python写的掷骰子小游戏,python掷骰子小游戏,规则来自于此:http:
规则来自于此:http://tieba.baidu.com/p/2747388562
粗略写了一个,还没写完,为了调试暂时把电脑掷点明文显示,跟电脑玩明的。
下一步打算优化两个方面。
一个是规则,目前双方是一次性下注,即使下注不一样也会一次性下注而开,1点1点的下注必然吃死电脑。下一步打算必须双方下注一样才会开,或者直到一方梭哈。
另一个是电脑的AI,目前电脑完全基于random算法的随机性,下注和放弃下注的概率各为50%,下注多少完全随机,即使7点也会放弃跟注。下一步打算优化下跟注概率,7点100%跟注,1点放弃跟注,2-6跟注几率依次升高。点数越高,下注越狠。
#!/usr/bin/python#coding:utf8import randomimport timedef get_dice(): return random.randint(1,7)def the_open(player_dice,computer_dice): print '双方开:' time.sleep(1) print '玩家:' + str(player_dice) time.sleep(1) print '电脑:' + str(computer_dice) time.sleep(1)def every_game(player_money,computer_money): print 'Get Ready~~~' time.sleep(1) print 'Go!' time.sleep(2) print "双方筹码:" print '玩家:' + str(player_money) print '电脑:' + str(computer_money) time.sleep(2) print '玩家掷点:', time.sleep(1) player_dice = get_dice() print '您得到的点数为' + str(player_dice) time.sleep(2) print '电脑掷点:', time.sleep(1) computer_dice = get_dice() print '电脑掷点完毕!' time.sleep(1) result = raw_input('玩家方先下注,是否下注?[y/N]') if result.lower() == 'y': while True: player_bets = input('选择下注范围:[1-{0}]'.format(player_money)) if player_bets >= 1 and player_bets <= player_money: break print '玩家下注{0}'.format(player_bets) time.sleep(1) print '电脑思考中...', time.sleep(2) if random.choice('yn') == str('y'): computer_bets = random.randint(1,computer_money) print '电脑下注{0}'.format(computer_bets) time.sleep(1) the_open(player_dice,computer_dice) if player_dice > computer_dice: print '玩家胜!玩家赢得筹码{0}'.format(computer_bets) player_money += computer_bets computer_money -= computer_bets elif player_dice == computer_dice: print '平局!双方收回各自筹码!' else: print '电脑胜!玩家输掉筹码{0}'.format(player_bets) player_money -= player_bets computer_money += player_bets else: print '电脑放弃下注!玩家收回自己的筹码!' time.sleep(1) the_open(player_dice,computer_dice) else: print '玩家放弃下注,本局放弃!' time.sleep(1) the_open(player_dice,computer_dice) return [player_money,computer_money]def play_game(): print '游戏开始!' player_money = 100 computer_money = 100 time.sleep(1) while player_money != 0 and computer_money != 0: money_list = every_game(player_money,computer_money) player_money = money_list[0] computer_money = money_list[1] if player_money == 0: print 'You Lose!' else: print 'You Win!'if __name__ == '__main__': play_game()#该片段来自于http://byrx.net
相关内容
- 查找包含多个字符的文件,包含多个字符,查找指定目录
- Mac下Goagent打开部分https链接无法访问,goagenthttps,调试后
- cutescan.py,,cutescan.py
- Python一句话生成N个随机数并挑出某个范围内的,pytho
- 比“目前最快的素数生产“快7倍,目前素数生产7倍,用
- python爬虫,抓豆瓣勾搭组妹纸照片,,import urlli
- 通过logging与ctypes打印不同颜色的日志,loggingctypes日志
- 爬取中图分类法,爬取图分类法,# -*- coding
- 发邮件(全功能),发邮件全功能,#coding=utf-
- python发微博升级版,python发微博,上次发了一个利用新浪
评论关闭