Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. The card game Each of n players starts with c cards arranged in a pile. These cards have value 1 ... C, with the
1. The card game Each of n players starts with c cards arranged in a pile. These cards have value 1 ... C, with the 1 card on the top. The weight of the pile is the sum of d*v, where d is the depth of each card (starting at 1) and v is its value. So the starting weight of each pile is 1*1 +2*2 + ... + c*c=c(c+1)(2c+1)/6. Higher-weight piles are worse; the goal is to have 0 weight, that is, no cards at all. At each turn, someone tosses an n-sided die, which indicates which player p will have the advantage on this turn. Player p tosses a 2-sided die, indicating whether to discard a card from the top (if the die shows 1) or the bottom of its pile (if the die shows 2), and an n-sided die, indicating which player accepts the discarded card. It is possible for p to get its own card back. The recipient puts the accepted card at the top of its pile. The winner is the first player to have an empty pile. If after t turns, no player has won, then the player whose pile has the smallest weight wins. If there is a tie, the lowest-numbered player with the smallest weight wins. 2. What to do Write a program called cards that simulates this card game. This program must take n. c, and t as command-line parameters. Make sure your program fails gently if any of these parameters is ridiculous, such as n=0. The program also takes a stream of random numbers from standard input. The program must play the game until some player wins or t turns have completed. After each turn, it prints which player sends a card (top or bottom) to which recipient and the weight of each player's pile after the turn. When the game is over (either because a player has no remaining cards or the number of turns has reached its limit), the program prints which player wins. Your program must use a doubly-linked list to implement the piles You must not use a library routine (such as C++ std::list or Java java.util.LinkedList) for linked lists; you must write your own routines. Do not use code you find on the Internet; you will get 0 points and be charged with academic misconduct if we detect any such code. Try to make your program modular, with separate routines for the main loop. for reading the next random number, for evaluating the weight of a pile, and for discarding and accepting a card. 1. The card game Each of n players starts with c cards arranged in a pile. These cards have value 1 ... C, with the 1 card on the top. The weight of the pile is the sum of d*v, where d is the depth of each card (starting at 1) and v is its value. So the starting weight of each pile is 1*1 +2*2 + ... + c*c=c(c+1)(2c+1)/6. Higher-weight piles are worse; the goal is to have 0 weight, that is, no cards at all. At each turn, someone tosses an n-sided die, which indicates which player p will have the advantage on this turn. Player p tosses a 2-sided die, indicating whether to discard a card from the top (if the die shows 1) or the bottom of its pile (if the die shows 2), and an n-sided die, indicating which player accepts the discarded card. It is possible for p to get its own card back. The recipient puts the accepted card at the top of its pile. The winner is the first player to have an empty pile. If after t turns, no player has won, then the player whose pile has the smallest weight wins. If there is a tie, the lowest-numbered player with the smallest weight wins. 2. What to do Write a program called cards that simulates this card game. This program must take n. c, and t as command-line parameters. Make sure your program fails gently if any of these parameters is ridiculous, such as n=0. The program also takes a stream of random numbers from standard input. The program must play the game until some player wins or t turns have completed. After each turn, it prints which player sends a card (top or bottom) to which recipient and the weight of each player's pile after the turn. When the game is over (either because a player has no remaining cards or the number of turns has reached its limit), the program prints which player wins. Your program must use a doubly-linked list to implement the piles You must not use a library routine (such as C++ std::list or Java java.util.LinkedList) for linked lists; you must write your own routines. Do not use code you find on the Internet; you will get 0 points and be charged with academic misconduct if we detect any such code. Try to make your program modular, with separate routines for the main loop. for reading the next random number, for evaluating the weight of a pile, and for discarding and accepting a card
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