其他分享
首页 > 其他分享> > CS61A 2021 Spring, Project 1: The Game of Hog (Phase 1)

CS61A 2021 Spring, Project 1: The Game of Hog (Phase 1)

作者:互联网

规则及示例

Phase 1: Simulator

Problem 0

dice.py 文件,定义了骰子类型

Problem 1

roll_dice 函数,传入骰子数量 num_rolls 和骰子类型 dice,返回此次投骰子结果(考虑 Sow Sad 规则)。

Problem 2

piggy_points 函数,传入对手分数 score,返回投0次骰子的得分(piggy points 规则)。

Problem 3

take_turn 函数,传入骰子数量 num_rolls, 对手得分 opponent_score, 骰子类型 dice=six_sided, 目标得分 goal=GOAL_SCORE,返回该轮得分。
take_turn 函数,在骰子数量为0时,调用 piggy_points 函数;在骰子数量不为0时,调用 roll_dice 函数。

Problem 4

more_boar 函数,传入选手得分player_score, 对手得分opponent_score,返回布尔值,判断该选手是否再来一轮(more_boar 规则)。

Problem 5

play 函数,传入选手0的骰子策略 strategy0, 选手1的骰子策略s trategy1, 初始得分 score0=0, 初始得分 score1=0, 骰子类型 dice=six_sided, 目标得分 goal=GOAL_SCORE, 注释函数 say=silence,返回游戏结束时的两位选手得分。
分析:
strategy是决定选手的骰子数量的函数,传入选手得分和对手得分;
选手得分score = 初始得分 + 本轮得分,本轮得分由 take_turn 函数返回;
选手得分score达到目标值goal时,本轮结束,游戏结束,返回两选手得分;
选手得分score未达到目标值,more_boar 函数判断是否再来一局;
next_player 函数,判断下一位选手是谁,注意赋值给who。

image

Phase 1 完成:

python hog_gui.py
image

标签:Hog,骰子,dice,得分,Spring,CS61A,选手,score,函数
来源: https://www.cnblogs.com/ikventure/p/14815119.html