這是一個豬骰子游戲,我使用2個策略,目標是達到63分。骰子游戲與字典
所以我得到了一個功能play_games(n_games, strategy_a, strategy_b)
。(看代碼的底部) 該功能可以發揮n_games,在此玩家A具有使用strategy_a和球員B必須使用strategy_b(兩個參數都是字符串)。並且該函數必須返回一個字典,其中鍵爲'A','B'和'D',其中值表示A和B多久獲勝以及多少次抽籤。
我已經試了兩天了,不能拿出任何東西,真的很想學這個。
這是我走到這一步:
from random import randint
def one_round(total, strategy):
round = 0
while True:
value = randint(1,6)
round = round + value
if Value == 1:
round = 0
break
if round + total >= 63:
break
if strategy == 'Sum13':
if round >= 13:
break
if strategy == 'Sum6':
if round >= 6:
break
return round
def one_game(strategy_a, strategy_b):
total_a = 0
total_b = 0
while True:
round_a = one_round(total_a, strategy_a)
round_b = one_round(total_b, strategy_b)
total_a += round_a
total_b += round_b
while total_a >= 63 or total_b >=63:
break
if total_a >= 63:
return 'A'
elif total_b >= 63:
return 'B'
elif total_a == total_b:
return 'D'
def play_games(n_games, strategy_a, strategy_b):
n_games = 100
for i in range(n_games):
你應該說明問題與代碼是什麼。出了什麼問題。可以問一下家庭作業(請標記爲「家庭作業」),但如果他們不知道該怎麼幫忙,他們就無法提供幫助。你也應該描述遊戲的規則。 – ninjagecko 2012-04-26 22:00:59
我以爲我在文本中解釋過,但無論如何,所以規則如同在一個豬骰子游戲中,2個玩家擲骰子,她使用2個策略。一名球員在達到總和6時持有,其他球員在達到總和13時持有,當你達到63分時贏得。至於這個問題,我不知道如何進行,說他們玩100場比賽,我如何玩遊戲並返回字典? – sharky8899 2012-04-26 22:09:22