This assignment deals with the following topics: · Loops · Control Statements · Functions General Idea of the Assignment Dice is a simple game that involves two players taking turns; on each turn, a...

1 answer below »
Attached


This assignment deals with the following topics: · Loops · Control Statements · Functions General Idea of the Assignment Dice is a simple game that involves two players taking turns; on each turn, a player rolls a six- sided die ("die" is the singular of "dice") as many times as they wish, or until they rolls a 6. Each number they rolls, except a 6, is added to their score this turn; but if they rolls a 6, their score for this turn is zero, and they turn ends. At the end of each turn, the score for that turn is added to the player's total score. The first player to reach or exceed 50 wins. For example: · Juma rolls 3, 5, 3, 1, and stops. His score is now 12. · Janet rolls 5, 4, 1, 1, 2, and stops. Her score is now 13. · Juma rolls 5, 3, 3, 5, 4, and stops. Her score is now 32 (12 + 20). · Janet rolls 4, 6. She has to stop, and her score is still 13 (13 + 0). etc. As defined above, the first player has an advantage. To make the game more fair, we will say that if the first player reaches or exceeds 50, the second player gets one additional turn. (If the second player is the first to reach 50, the first player does not get an additional turn.) Your assignment is to implement the game of Dice. You will play against the computer. The computer always goes first, so you get one more turn if the computer is the first to reach 50. If both players are tied with 50 or more, each gets another turn until the tie is broken. 1 | P a g e Each player must roll the die at least once per turn. Additionally, the program should ask if the user wants to play again. Any response that begins with 'y' (capital or lowercase) should play again. Any response that begins with 'n' (capital or lowercase) means the user wants to exit. Any response that begins with any other character should ask the user again. Your task is to create the program by writing the necessary code using functions. Docstring-style comments must be included to tell what has be done in each function. Implement the following functions: def print_instructions(): · Tell the user the rules of the game. What words you use is up to you. def computer_move(computer_score, human_score): · The computer rolls some number of times, displays the result of each roll, and the function returns the result (either 0 or the total of the rolls). · The function can (but doesn't have to) use its parameters in order to play more intelligently (for example, it may wish to gamble more aggressively if it is behind). def human_move(computer_score, human_score): · Repeatedly asks whether the user wants to roll again and displays the result of each roll. · If the user chooses to roll again, and DOES NOT roll a 6, this function adds the roll to the total of the rolls made during this move. · If the user chooses to roll again, and DOES roll a 6, the function returns 0. · If the user chooses not to roll again, the function returns the total of the rolls made during this move. · Like the computer_move function, this function can (but doesn't have to) use its parameters. def is_game_over(computer_score, human_score): · Returns True if either player has 50 or more, and the players are not tied, otherwise it returns False. (Hint: Call this only after the human's move.) def roll(): · Returns a random number in the range 1 to 6, inclusive. (Hint: Find the random module on https://docs.python.org/3/library/index.html and follow the link to find the randint method.) def ask_yes_or_no(prompt): · Prints the given prompt as a question to the user, for example, "Roll again? " or "Want to play again? (y/n) ", then prompts the user for input. · If the user responds with a string whose first character is 'y' or 'Y', the function returns True. If the user responds with a string whose first character is 'n' or 'N', the function returns False. · For example: "Y", "yes", and "yyyyy" should all be considered affirmative "None", "no", and "nnnnn" should all be considered negative · Any other response will cause the question to be repeated until the user provides an acceptable response. def show_current_status(computer_score, human_score): · Prints the user's current score and the computer's current score, how far behind (or ahead) the user is, or if there is a tie. (Hint: Call this before and after the human's move.) def show_final_results(computer_score, human_score): · Tells whether the human won or lost, and by how much. (Hint: Call this when the game has ended.) def main(): This is where your program will start execution. Add starter code to the bottom of your script to run the main function. if name == ' main ': main() Note, do not use Python's time.sleep() function to "slow down" (or suspend execution of) your program. This will make playing the game and grading difficult. Program Output Printoutwhattheprogramisdoingasitgoesalong.Storetheoutputina template_behavior_{user_name}.txt file which shows runs of the program. Submission Your submission should include: · dice.py - the source code for your game Bonus Points/Advanced 1. Allow multiple players to play the game 2. Modify the game such that if the player roles the last number rolled by the previous player their turn ends 3. Include a bonus turn for a player who roles the exact same number 3 times expect for a 6 4. Implement a function to help choose which player starts. Each player will roll the dice the times and the total score from each player determines the order in which they play. Evaluation Style - 20 pts Style includes things like variable names, comments, function names, and general readability of your code. Are variables named based on the information they store? Are your user-defined functions named based on what they do? Comments – 5 pts Does every function have a docstring defined? Does it appropriately describe what the function does? Bonus – 10 pts This assignment deals with the following topics: · Loops · Control Statements · Functions General Idea of the Assignment Dice is a simple game that involves two players taking turns; on each turn, a player rolls a six- sided die ("die" is the singular of "dice") as many times as they wish, or until they rolls a 6. Each number they rolls, except a 6, is added to their score this turn; but if they rolls a 6, their score for this turn is zero, and they turn ends. At the end of each turn, the score for that turn is added to the player's total score. The first player to reach or exceed 50 wins. For example: · Juma rolls 3, 5, 3, 1, and stops. His score is now 12. · Janet rolls 5, 4, 1, 1, 2, and stops. Her score is now 13. · Juma rolls 5, 3, 3, 5, 4, and stops. Her score is now 32 (12 + 20). · Janet rolls 4, 6. She has to stop, and her score is still 13 (13 + 0). etc. As defined above, the first player has an advantage. To make the game more fair, we will say that if the first player reaches or exceeds 50, the second player gets one additional turn. (If the second player is the first to reach 50, the first player does not get an additional turn.) Your assignment is to implement the game of Dice. You will play against the computer. The computer always goes first, so you get one more turn if the computer is the first to reach 50. If both players are tied with 50 or more, each gets another turn until the tie is broken. 1 | P a g e Each player must roll the die at least once per turn. Additionally, the program should ask if the user wants to play again. Any response that begins with 'y' (capital or lowercase) should play again. Any response that begins with 'n' (capital or lowercase) means the user wants to exit. Any response that begins with any other character should ask the user again. Your task is to create the program by writing the necessary code using functions. Docstring-style comments must be included to tell what has be done in each function. Implement the following functions: def print_instructions(): · Tell the user the rules of the game. What words you use is up to you. def computer_move(computer_score, human_score): · The computer rolls some number of times, displays the result of each roll, and the function returns the result (either 0 or the total of the rolls). · The function can (but doesn't have to) use its parameters in order to play more intelligently (for example, it may wish to gamble more aggressively if it is behind). def human_move(computer_score, human_score): · Repeatedly asks whether the user wants to roll again and displays the result of each roll. · If the user chooses to roll again, and DOES NOT roll a 6, this function adds the roll to the total of the rolls made during this move. · If the user chooses to roll again, and DOES roll a 6, the function returns 0. · If the user chooses not to roll again, the function returns the total of the rolls made during this move. · Like the computer_move function, this function can (but doesn't have to) use its parameters. def is_game_over(computer_score, human_score): · Returns True if either player has 50 or more, and the players are not tied, otherwise it returns False. (Hint: Call this only after the human's move.) def roll(): · Returns a random number in the range 1 to 6, inclusive. (Hint: Find the random module on https://docs.python.org/3/library/index.html and follow the link to find the randint method.) def ask_yes_or_no(prompt): · Prints the given prompt as a question to the user, for example, "Roll again? " or "Want to play again? (y/n) ", then prompts the user for input. · If the user responds with a string whose first character is 'y' or 'Y', the function returns True. If the user responds with a string whose first character is 'n' or 'N', the function returns False. · For example: "Y", "yes", and "yyyyy" should all be considered affirmative "None", "no", and "nnnnn" should all be considered negative · Any other response will cause the question to be repeated until the user provides
Answered 10 days AfterJul 16, 2022

Answer To: This assignment deals with the following topics: · Loops · Control Statements · Functions General...

Samiya answered on Jul 27 2022
79 Votes
********Turn 1 *********
Computer's turn
Computer rolled a 5
Your turn
You rolled a 3
Do you want to roll again?yes
You rolled a 1
Do you want to roll again?yyy
You rolled a 6
******Current status******
Human Player: 0
Computer Player: 5
**************************
********Turn 2 *********
Computer's turn
Co
mputer rolled a 6
Your turn
You rolled a 1
Do you want to roll again?Y
You rolled a 5
Do you want to roll again?y
You rolled a 4
Do you want to roll again?y
You rolled a 2
Do you want to roll again?n
******Current status******
Human Player: 12
Computer Player: 5
**************************
********Turn 3 *********
Computer's turn
Computer rolled a 6
Your turn
You rolled a 3
Do you want to roll again?y
You rolled a 3
Do you want to roll again?y
You rolled a 4
Do you want to roll again?y
You rolled a 3
Do you want to roll again?n
******Current status******
Human Player: 25
Computer Player: 5
**************************
********Turn 4 *********
Computer's turn
Computer rolled a 3
Your turn
You rolled a 5
Do you want to roll again?y
You rolled a 6
******Current status******
Human Player: 25
Computer Player: 8
**************************
********Turn 5 *********
Computer's turn
Computer rolled a 1
Computer rolled a 2
Computer rolled a 1
Your turn
You rolled a 5
Do you want to roll again?y
You rolled a 5
Do you want to roll again?y
You rolled a 2
Do you want to roll again?y
You rolled a 2
Do you want to roll again?n
******Current status******
Human Player: 39
Computer Player: 12
**************************
********Turn 6 *********
Computer's turn
Computer rolled a 2
Computer rolled a 4
Computer rolled a 4
Your turn
You rolled a 4
Do you want to roll again?y
You rolled a 3
Do you want to roll again?y
You rolled a 3
Do you want to roll again?y
You rolled a 5
Do you want to roll again?n
******Current status******
Human Player: 54
Computer Player: 22
**************************
******Final Results******
Human Player wins!!!
Human: 54
Computer: 22
*************************
Do you want to play again? y
********Turn 1 *********
Computer's turn
Computer rolled a 2
Computer rolled a 3
Computer rolled a 5
Computer rolled a 2
Computer rolled a 4
Your turn
You rolled a 3
Do you want to roll again?y
You rolled a 5
Do you want to roll again?y
You rolled a 6
******Current status******
Human Player: 0
Computer Player: 16
**************************
********Turn 2 *********
Computer's turn
Computer rolled a 3
Computer rolled a 2
Computer rolled a 3
Computer rolled a 4
Computer rolled a 1
Your turn
You rolled a 1
Do you want to roll again?y
You rolled a 4
Do you want to roll again?y
You rolled a 3
Do you want to roll again?y
You rolled a 6
******Current status******
Human Player: 0
Computer Player: 29
**************************
********Turn 3 *********
Computer's turn
Computer rolled a 1
Your turn
You rolled a 5
Do you want to roll again?y
You rolled a 1
Do you want to roll again?y
You rolled a 6
******Current status******
Human Player: 0
Computer Player: 30
**************************
********Turn 4 *********
Computer's turn
Computer rolled a 1
Your...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here