Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Needs to be in C. not C++. having great issues with this it would be helpful to just get the create player, distribute, deck and
Needs to be in C. not C++. having great issues with this it would be helpful to just get the create player, distribute, deck and who wins functions if anything.
Game Description: You are going to make a multi-player menu-driven card game in C. Once you (which will be referred as player or user hereafter) run your program, you should see the following options menu: 1. Enter player's information 2. Play 3. Exit The player can register for the game before playing it. He/she can do so by choosing option 1. If the player chooses option (1), then the player can enter his/her information (first_name, last_name and country). Only those players who choose to enter their information will be eligible to enter their names on the scoreboard. More about scoreboard will be discussed later. The player can directly start playing the game as a guest. However, if the player chooses option (2), without choosing option 1, then the player needs to be informed that his/her score will not be recorded (in the file scoreboard.txt) or eligible to be displayed on the score board. The player then needs to be given an option to either continue playing as a guest or allow him/her to register to the game. If the player chooses to enter his/her information then after entering his/her information, he/she will directly start the game i.e. no menu should be displayed again. If the player chooses to continue the game (i.e. without registration), then he/she can start the game. If the player chooses option 3, then he/she can exit from the program. Brief overview of card games rules: You will be using a standard deck of 52 cards for the game, where each card has a face value and the suit. The face value of the card can be one of the following: Brief overview of card games rules: You will be using a standard deck of 52 cards for the game, where each card has a face value and the suit. The face value of the card can be one of the following: Face Value Face value represented as 2 through 9 The number itself T 10 Jack Queen King Ace J Q A Similarly, the suit of each card can be one of the following: Spade, Heart, Diamond or Club Suit represented as S Suit Spade Heart Diamond Club H D If you want to represent Ace of Spade, then it will be represented as AS. Similarly, four of club will be represented as "4C". To compare two cards, you need to follow the following rules: 1. "Ace" beats King, which in turn beats "Queen", which in turn beats "Jack". 2. A card with higher number beats a card with lower number. E.g.: 10 beats 4 and so on. 3. When two cards have the same face value, then the suit would be used to break the tie. In this case, "Spade" beats "Heart", which in turn beats "Diamond", which in turn beats "Club". So, following these above rules, if the first card is "35" and the second card is "60", then the second card wins. Similarly, if the first card is "As" and the second card is "AC", then the first card wins. How to play the game? The game is played among N players. Once option 2 is chosen and the player information is decided, the player will be prompted to enter the value of N. For example, if the user chooses the value of N as 10, then there will be a total of 10 players in the game, out of which 9 players would be computer and one player will be you (which would be named as either the name you have entered during the registration in the format first_name followed by last_name or the Guest, if the user decided to play as a guest). These nine players will be named as Computeri, Computer2, Computers,... and Computer, respectively. A game consists of M rounds, where the value of M is to be entered from the user. Once the number pf players (N) is decided, each round will consist the same number of players. Each round starts with a new shuffled deck of cards and each player gets equal number of cards. For example, if N is selected as 10 and A game consists of M rounds, where the value of M is to be entered from the user. Once the number of players (N) is decided, each round will consist the same number of players. Each round starts with a new shuffled deck of cards and each player gets equal number of cards. For example, if N is selected as 10 and Mis selected as 4, then in all the 4 rounds, each player will get 5 cards and the remaining 2 cards will be unused. In each round, each player turns up one card at a time and the player with the highest card takes 1 point. This is called a "hand. So, the number of hands in each round depends on the number of cards each player has (make sure all the players have an equal number of cards). For the above example (n = 10 and M = 4), we have 4 rounds, and each round will have 5 hands. There is a rule that needs to be followed in deciding which player will start each hand: For the first hand in each each round, the program needs to randomly decide which player is going to start the hand. It can be either you or any other players. From second hand onwards, the winner of the previous hand will start that round. For example, for 2nd hand, the winner of 1* hand will start, for 3 hand, the winner of 2nd hand will start and so on. At the end of each round, the sum of the points each player received from each hand is counted and the result is stored in a file, name it temp.txt. So, the number of write operation equals the number of rounds played. Once the all the round is completed, you need to read the file (i.e. temp.txt), sum the total of each player's score from each round and declare the winner. A player with the highest number of points is the winner. If there is more than one player with the same highest score, then it is a tie, and you declare both as the winner. Note: temp.text file will be used irrespective of whether the player has registered in the game or not. The winner of the game is stored in the file scoreboard.txt. The file scoreboard.txt only contains the registered user information (first_name, last_name, country), the winning score, number of rounds played, number of players. Once the winner is decided, the user will be given an option to see the score board. The scoreboard.txt can contains hundreds of winners' information, but it is not fair to compare the score of one winner who have played 100 rounds among 2 players with another winner who have player 4 rounds among 5 players. So, you would only want to know the top 5 winners who have selected the same values for N and M, as you have just now played. Once the scoreboard option is chosen, the program should accept an Enter as input, before displaying the option menu again. This is a particularly important part for the input redirection to work properly (refer to How will the TA run your program? to know more about input file redirection.) Programming requirements: Your program needs to strictly follow the description given below on how the game needs to be implemented. Important note: Please keep in mind, that your program needs to display all the outputs (like the ones shown in red). This will help TA to verify that each step is working correctly. Also, note that I have just shown the output once the game has started and did not show menu option and player information. Your program needs to include them as well. Implementation Requirement: The program should have at least the following functions: main(...) CreatePlayers(...) createDeck(---) shuffle (..-) distribute(...) whoWins(...) writeTempFile (...) readTempFile(...) declare Winner() writeScoreFile (...) readScoreBoard (...) exit....) The description of each of these functions are given below: 1. main: The main function will be calling all other functions. All the inputs and outputs will be performed in the main function. 2. createPlayers: The createPlayers function creates players using dynamic memory allocation. This function also prompts the user to enter the number of rounds in the game. How many players?:5 How many rounds to play before declaring winner?: 4 . You need to use structure (given by construct struct in C) array to present all the players in the game: The size of the structure array needs to be dynamically allocated based on the number of players, N specified by the user. The fields in the structure should contain following information: first_name, represented as string last_name, represented as string country, represented as string scores, represented as array which needs to be dynamically allocated based on the number of rounds selected. o cards, represented as array which needs to be dynamically allocated based on the players selected. . 0 3. createDeck: The createDeck function is used to create a deck of cards. The sample cards created by this function is shown below: The created deck of card is as follows: ['2', '3', '4', '5', '6', '7', '8', '9', 'Ts', 's', 'as', 'ks', 'As', '2h', '3h', '4h', '5h', '6h', '7h', 'sh', '9h', 'Th', 'h', 'Qh', 'Kh', 'Ah', "2d', '3d', '4d', '5d", '6d', '7d', 'd', 'd', 'Td', 'd', 'Qd', 'Kd', 'Ad', '22', '32', '4c', '52', '62', '7', '8c', '92', 'T', 'lc', 'Qc', 'Kc', 'Ac'] A deck of card should be created using a dynamic array. 4. shuffle: : The shuffle function is used to shuffle the newly created deck of cards as well as the cards after the completion of each round. The shuffled card for each round is shown below for your illustration. Even though I have shown all rounds here, your program should display 2nd round shuffled cards only once the 1st round is completed. For 1st round The shuffled deck of card is as follows: ['5c', 'As', '9', 'Qc', 'Oh', '2', '55', 'Th', 'Qd', 'Os', '5 d', '3', 's', 'Td', 'T', 'Id', '7', '9', '45', '9h', '9d', '30', '6s', '2', '8', '3d", "6d', 'Kd', '2d', 'Kh', '6h', 'Ks', '6c', 'd', 'd', '8c', '2h', '7', 'sh', 'Ad', 'Kc', 'Ad', '7d', '42', '7c', '4h', 'sh', '4d', 'Ts', 'Jh', 'Ah', '3h'] For 2nd round The shuffled deck of card is as follows: ['38', 'Jh', 'd', 'Ad', '7d', 's', '25', 'Os', 'Kc', '9s', 'As', '6d', '4h', '7c', 'Id', '8c', '3', '6h', 'T', 'Ah', '5d", '6', 'Id', 'Td', 'Qc', 'Th', '2', '9h', '55', '60', '4', '5', '3h', '4', '2d', '3d', 'Ks', 'Qh', '4d", '9d', 'Ac', 'Kh', '2h', 'Ts', 'sh', '9c', 's', 'Qd', '7h', 'sh', '7s', 'Kd'] For 3rd round The shuffled deck of card is as follows: ['Th', 'h', '5d", '22', 'Qs', 'Id', '4c', 'TC', 's', '5c', '4d', '6d", '3s', "Kh', 'Ks', 'Qh', '9c', 'Qc', 'As', '6h', '3c', 'Ac', '3d", "9d", 'Id', '7', 'Qd", "6s', 'sh', 'Kd', 'Ah', '2h', 'sh', 'Ts', 'Kc', 'Ad', '2d', '9s', '8', "6c', '7s', '7d", '45', '25', 'd', '5', '7h', '9h', '3h', '8', 'Id', '4h'] For 4th round The shuffled deck of card is as follows: ['2', '5d", '6d', 'Th', 'Ts', 'sh', '7d", 'Qd', '3d", '4d', 'Ac', 'Qs', '2h', 'sh', 'Kc', '4h', 'Ah', 'c', 'Th', '7', '8', '2', 'Kd', 'ks', '7', '9c', '9d', '3h', 'Ad', 'd', '3', 'Tc', '55', '32', 's', '5c', '7h', '6h', 'Id", 'Id', 'Kh', '6s', '9h', 'Qh', 'Qc', '45', '2d', '8c', 'As', '62', '4c', '9s'] Please make sure your deck of cards is well shuffled. Your shuffling should not be restricted to only few cards. Observe how well the cards have been shuffled (especially between the newly created deck of card and the deck used during the first round). 5. distribute: The distribute function is used to distribute cards to each player. The card at each player is as follows: At round 1: Computer1: ['5c', '2', '5d", 'c', '9d", "3d", "6h', 'c', 'Kc', '4h'] Computer2: ['As', '55', '3', '7h', '3', '6d", "Ks', '2h', 'Ac', 'sh'] Luis Moreno: ['9c", 'Th', 's', '9', '6', 'Kd', '6c', '7', '7d", "4d'] Computer3: ['Qc', 'Qd', 'Id', '45', '2', '2d', 'd', 'sh', '4c', 'Ts'] Computer4: ['Qh', 'Os', 'TC', '9h', '8s', 'Kh', 'Id', 'Ad', '72', 'Th'] Round 2: Computer1: ['35', '8s', 'As', '8c', '5d', 'Th', '42', '3d", "Ac', '9c'] Computer2: ['h', '25', '6d', '3', '6', '22', '5c', 'Ks', 'Kh', 's'] Luis Moreno: [8d', 'Qs', '4h', '6h', 'Id', 'sh', '3h', 'Oh', '2h', 'Qd'] Computer3: ['Ad', 'Kc', '7c', 'Tc', 'Td', '55', '43', '4d', 'Ts', '7h'] Computer4: ['7d", '9s', 'd', 'Ah', 'Q', '6c', '2d', '9d', 'sh', '8h'] Round 3: Computer1: ['Th', 'Id', '4d', 'Oh', '32', '72', 'Ah', 'Ad', '7', '5s'] Computer2: ['Jh', '4', '6d', '9', 'Ac', 'Qd', '2h', '2d', '7d', '7h'] Luis Moreno: ['d', 'T', '38', 'Qc', '3d', '6s', 'sh', '9s', '45', '9h'] Computer3: ['2c', 's', 'Kh', 'As', 'd', 'sh', 'Ts', '8c', '25', '3h'] Computer4: ['Qs', '5c', 'Ks', '6h', 'c', 'Kd', 'Kc', '6c', 'd', '8s'] Round 4: Computer1: ['25', '5h', 'Ac', '4h', '8', '9c', '33', '5c', 'Kh', '45'] Computer2: ['5d', '7d', 'Os', 'Ah', '2', 'd', 'T', '7h', '63', '2d'] Luis Moreno: ['6d', 'Qd', '2h', 'c', 'Kd', '3h', '5', '6h', '9h', '8c'] Computer3: ['Th', '3d', 'sh', 'Jh', 'Ks', 'Ad', '30', 'd', 'Ch', 'As'] Computer4: ['Ts', '4d', 'Kc', '7s', '7', '8d', 'Is', 'Id', 'Qc', '6c'] There are some points to note in this function: Each player has equal number of cards. Notice, you have 52 cards and 5 players. Each player has 10 cards. That leaves 2 cards unused. if you observe the shuffled deck of cards (at the end of shuffled function) and how the cards have been distributed to each player (above), you will notice that cards have been distributed in the round-robin fashion i.e. first card is assigned to the 1* player, second card to the 2nd player, third card to the 3" player and so on. It should not be like first ten cards to the 1 player, second ten cards to the 2nd player and so on. 6. who Wins: The who Wins function computes which player has won each hand and each round. For each round the sample output from this function is given below: At round 1: The total score of each player is: [2, 3, 1, 0, 4] At round 2: The total score of each player is: [3, 2, 1, 2, 2] At round 3: The total score of each player is: [2, 1, 1, 2, 4] At round 4: The total score of each player is: [2, 1, 1, 4, 2] Each player has a score at the end of each round. 7. write TempFile: The writeFile function writes the output of each round to the file (i.e. temp.txt), after each round. Please make sure, you write to the file after each round is over. The file content looks like this: Computer 3 temp but 1 Computerl 2 2 3 3 4 2 5 2 Computer2 3 2 1 NOWN Luis Moreno 1 1 1 Computer4 4 2 NO 2 2 4 Make sure when you write to the file, the contents are formatted properly. The first line should specify players by writing 1* player, 2nd player, 3rd player and so on. Also, there should be uniform spacing between each player. The score after the end of each round should be placed in separate line under their proper heading. The score should also be right aligned as shown above. 8. readTempFile: The readTempFile function reads the file (.e. temp.txt) at the completion of all the rounds for calculation of final total. 9. declareWinner: The declare Winner function first declare the final score of all the players and then declares the winner. There can be two or more players with the same final score. In that case, it is a tie. If there is a tie, then all the players' names must be clearly specified. The final score at the end of all round is: (9,7, 4, 8, 12] The winner is: Computer4 10. writeScoreFile: The writeScoreFile function writes the winner information in another file, scoreboard.txt. For the given example, since the winner is Computer, you do not need to include that in the Scoreboard.txt. The sample scoreboard.txt might look something like this: scoreboard.txt First_name last_name country Score Number of palyers 2 Mariah Finley USA 13 5 3 Leonel Soga Germany 5 4 Skyler Ali China 15 6 5 Esther Sellers Russia 24 6 Desiree Alexander India 13 6 7 Eva Smith Russia 23 Derick Black Russia 13 9 Amiya Flores India 18 10 Lorenzo Forbes USA 18 6 11 Harold Bernett Lithuania 19 6 12 Zain Levy Iran 23 7 13 Zander Santos China 25 7 Number of rounds 4 4 4 3 5 OOOO 3 6 4 ULONG 11. readScoreBoard: The readScoreboard function first gives an option to the user if he/she wants to see the score board. If the user chooses the see the score board, then it will display the list of top 5 winners. For the above sample scoreboard.txt and for given example above, the output may look something like this: The Scoreboard is: Number of players Number of rounds first_name last_name country Score Mariah Finley USA 13 Leonel Sosa Germany 9 4 5 5 4 12. exit: The exit function first displays the final goodbye message before existing the program. Additional requirements: Each of the above function should be in separate C file. All the parameters must be passed from one function to another function using pointers. All the array operations (for example, iterating over each element in an array, accessing an element in the array) needs to be performed using pointer arithmetic: How will the TA run your program? 1. To check the proper working of each round, the TA will run your program as: ./a.out 2. To check the proper working of the scoreboard, the TA will run your program as: ./a.outStep 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