Problem 9 (200pts)
Implement the max_scoring_num_rolls
function, which runs an experiment to determine the number of rolls (from 1 to 10) that gives the maximum average score for a turn. Your implementation should use make_averaged
and roll_dice
.
If two numbers of rolls are tied for the maximum average score, return the lower number. For example, if both 3 and 6 achieve a maximum average score, return 3.
You might find it useful to read the doctest and the example shown in the doctest for this problem before doing the unlocking test.
Important: In order to pass all of our tests, please make sure that you are testing dice rolls starting from 1 going up to 10, rather than starting from 10 to 1.
Before writing any code, unlock the tests to verify your understanding of the question.
$ python ok -q 09 -u
Once you are done unlocking, begin implementing your solution. You can check your correctness with:
$ python ok -q 09
助教忘记修改
run_experiments
相关的功能了,但是这不影响大家在OJ得分。你需要对代码做出如下修改,才可以正常运行
run_experiments
(不改也没事)。
- 按如下所示的方法修改文件结尾的
def run(*args):
这一行(这种格式叫做diff,你要做的是删除红色的内容,添加绿色的内容,也就是把定义函数的def
语句换成一个if
):# NOTE: Functions in this section do not need to be changed. They use features # of Python not yet covered in the course. -def run(*args): +if __name__ == '__main__': """Read in the command-line argument and calls corresponding functions.""" import argparse parser = argparse.ArgumentParser(description="Play Hog")
- 自己修改
run_experiments
的内容(函数的调用参数写错了,这就留给大家自己随意修改了)
Running experiments:
To run this experiment on randomized dice, call run_experiments
using the -r
option:
$ python hog.py -r
For the remainder of this project, you can change the implementation of run_experiments
as you wish. The function includes calls to average_win_rate
for evaluating various Hog strategies, but most of the calls are currently commented out. You can un-comment the calls to try out strategies, like to compare the win rate for always_roll(8)
to the win rate for always_roll(6)
.
Some of the experiments may take up to a minute to run. You can always reduce the number of trials in your call to make_averaged
to speed up experiments.
Running experiments won't affect your score on the project.