Problem 11 (200pts)
战略也可以利用Swine Swap规则。
实现swine_strategy,如果掷0个骰子在本回合给玩家至少threshold分,则返回0。
在其他情况下,该战略掷num_rolls个骰子。
在编写任何代码之前,请解锁测试以验证您对问题的理解。
python ok -q 11 -u
解锁完成后,开始实现您的解决方案。您可以使用以下命令检查正确性:
python ok -q 11
一旦您实现了此战略,请更新run_experiments以将您的新战略与基线进行评估。
Solutions
def swine_strategy(score, opponent_score, threshold=8, num_rolls=6):
"""This strategy returns 0 dice when this would gives the player at least
THRESHOLD points in this turn. Otherwise, it returns NUM_ROLLS.
"""
# BEGIN PROBLEM 11
pig = picky_piggy(opponent_score)
if swine_swap(score + pig):
if opponent_score - score >= threshold:
return 0
else:
if pig >= threshold:
return 0
return num_rolls
# END PROBLEM 11
one-liner:
def swine_strategy(score, opponent_score, threshold=8, num_rolls=6):
return ((0 if opponent_score - score >= threshold else num_rolls) if swine_swap(score + picky_piggy(opponent_score)) else (0 if picky_piggy(opponent_score) >= threshold else num_rolls))