Python游戏代写 | Python AI Dice Game


In this assignment you’ll be writing an AI that can play a simple dice game. You will be given code
which implements the game mechanics. This code is demonstrated in the Jupyter notebook, which
can be accessed using the link at the bottom of this page.

You must follow the instructions within and then submit this specific notebook (.ipynb file). Failure
to do this will result in zero marks.

In the following text, you will be shown the dice game you will be solving.

“In this assignment, you will be working with a simple game. All you need is three dice. The aim is
to get the best score when you add up the values showing on the dice, but there is a twist. If we
decide to stop rolling when two or more of the values are showing the same number, then those
dice get turned upside down before the final scoring. The opposite sides of a die add up to seven.
So, 1 becomes 6, 2 becomes 5, and so on. The best possible roll is three 1s. They will all get
flipped upside down and you will get three 6s, a score of 18. But, if you don’t roll any duplicates,
the best possible roll is 4 or 5, 6: the score of 15. You want to get high singles, but low doubles.

After rolling, you can decide to stick and get your final score or you can re-roll, optionally
choosing to hold some of the values and just roll the other dice. So here, I might just hold the 1 or
I could just roll 3. However, each time you decide to re-roll, you lose one point from your final
score. So, if you think the score shown on the dice is higher than what you are likely to get by re-
rolling, you should stick. So this game isn’t going to take over the world. But it is complicated
enough that it isn’t immediately obvious what your best action is on any given role. It meets the
criteria for modeling as a Markov decision process. And, since we can easily calculate the
probabilities for any given dice roll, we can actually solve this game using value iteration and
answer definitively what the best move is for any dice roll. Maybe take a second to think about
what you do if you rolled these numbers. There is more information inside the Jupyter notebook
and a simulation of the game you can play yourself. So move on to that when you are ready.”

Your task is to write an agent that can play the dice game described above and get the best score
possible. The choice of technique to write your agent is up to you, but since the game can be
modelled as a Markov decision process (MDP), and has known mechanics, it is well-suited to
techniques such as those from this section of the unit (value iteration, policy iteration, and so on).

Your code will be subject to automated testing in random iterations of the dice game. Full details
can be found in the Jupyter Notebook file.

Download the file, extract the files, and then open dicegame.ipynb to begin. Ensure
you read the guidelines carefully.

You must submit a single completed Jupyter notebook (.ipynb) file.

• You should restart the kernel and run all cells before submission.

• You must not delete or modify any of the blank test cells.

• You do not have to write your code in the Jupyter environment. You are welcome to write your
solution in another IDE, but you must copy it across and test it within the Jupyter notebook
before submission.