Answered step by step
Verified Expert Solution
Question
1 Approved Answer
code the following problem using python: Consider a 2-player game where the objective is to be the first to collect 5 tokens, one each of
code the following problem using python:
Consider a 2-player game where the objective is to be the first to collect 5 tokens, one each of the five colors: blue, red, green, yellow, purple When the game starts, neither player has any tokens. At no time can a player have more than 1 token of any particular color. The players alternate in randomly selecting one of 9 outcomes for their turn (think of an arrow spinner found in many board games) 1-5. Draw a specific color (1 for blue, 2 for red, etc.) If the player already has a token of this color, nothing happens. Otherwise, they add a token of the given color to their collection. Choose a color The player is prompted to select a color (that they don't already have) that they would like to add to their collection. Steal. The player is prompted to select a token from the other player's pile Lose a turn. Play passes to the other player Lose a token. The player loses a random token (assuming they have any) and their turn ends. Play ends when one player has 5 tokens corresponding to the five colors Specific guidelines: Your program should use the input() function to prompt players to either draw or exit on their turn. Draw should generate a random number from 1-9, corresponding to the outcomes above. Exit should terminate the game If the outcome of a draw requires it (e.g., option 6), the player should be prompted with input() again to provide their selection. After every turn, your program should neatly output a summary of what tokens each player * . . When the game ends, output a line declaring the winner. Make sure your program is neatly commented so it is easy for you and others to decipher your work. Hints & Suggestions: Near the beginning of your program, define the following objects colors p1_tokens p2_tokens blue' , ' red' ,' green' , . yellow. , ' purple' ] [False, False, False, False, False] [False, False, False, False, False] Wrap the whole game into a while loop. What must be true to break out of the loop? 5: , to handle cases 1-5 You should be able to have one block inside the while loop, if draw above (without copy/pasting a block of code 5 times!)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started