1 ECE 209 Program 2: farkle Fall 2021 Due Friday, Oct 22 @ 11:59pm This programming assignment must be completed individually. Do not share your code with or receive code from any other student....

This is a Farkle program that must be written in C. P2.pdf is the assignment description with rules that must be followed. The clion file is the shell program to fill in the 7 or so missing functions. Thank you


1 ECE 209 Program 2: farkle Fall 2021 Due Friday, Oct 22 @ 11:59pm This programming assignment must be completed individually. Do not share your code with or receive code from any other student. Evidence of copying or other unauthorized collaboration will be investigated as a potential academic integrity violation. The minimum penalty for cheating on a programming assignment is a grade of 0 on the assignment. If you are tempted to copy because you're running late, or don’t know what you’re doing, you will be better off missing the assignment and taking a zero. Providing your code to someone is cheating, just as much as copying someone else's work. DO NOT copy code from the Internet, or use programs found online or in textbooks as a "starting point" for your code. Your job is to design and write this program from scratch, on your own. Evidence of using external code from any source will be investigated as a potential academic integrity violation. This program implements a dice-rolling game known as Farkle. Based on a dice roll, a score is calculated, and the player decides whether to keep rolling. With multiple players, the goal is to be the first player to reach a total score of 10,000. The learning objectives of the program are: • Implement a program using multiple functions. • Access and manipulate elements of an array. • Implement a function that takes an array as a parameter. • Use loops, conditionals, and function calls to implement complex behavior. • Write code to test whether a function is implemented correctly. Background Farkle is a multi-player dice game, developed in the 1980s. It is also known by other names, such as Pocket Farkel, 10000, Zilch, Squelch, Cosmic Wimpout, or Hot Dice. Each player rolls a group of dice to accumulate points, until they voluntarily end the turn, or a roll wipes out their points and ends the turn. The winner is the player who first reaches 10,000 points. There are variations in the scoring rules, so be sure to read the rules for this version carefully. More information about Farkle can be found on Wikipedia: https://en.wikipedia.org/wiki/Farkle Problem Description Remember: There are many variations to the game. For this program, you must follow the rules exactly as specified. 2 Farkle is played with two or more players. Each player takes a turn rolling dice to earn points. After any roll, the player may choose to end the turn and keep the accumulated points. If, however, the roll scores zero points, the player loses all of the points from that turn and play goes to the next person. This is called a “Farkle.” Here is a more detailed description of one player’s turn: • The player rolls six dice to start. • Based on the scoring table below, the player determines which dice may contribute points to the score: these are known as scoring dice. • If there are no scoring dice, that’s a Farkle. The turn ends with zero points. Otherwise, the player must remove at least one scoring die from the rolled dice. The score from the removed dice are added to the score for this turn. • The player is then given the option to re-roll using the remaining dice: the ones that were not removed. If the player does not want to move, then the score from this turn are added to their total score, and play passes to the next player. • On each subsequent roll, only scores from those dice can be considered. (The removed dice are out of play.) Again, the player removes any set of scoring dice and can keep rolling or end the turn. At any point, a roll with no scoring dice ends the turn and sets the score for the turn to zero. • This pattern of rolling, removing, and re-rolling continues until the player ends the turn or a Farkle is rolled. • If the player scores using all six dice (using any number of rolls), this is known as “Hot Dice.” If the user chooses to keep rolling, the next roll begins again with six dice. The same rules apply as above: points are accumulated until the player ends the turn or rolls a Farkle. • At the end of a turn, the score from that turn is added to the player’s total. The first player to reach 10,000 points or more wins the game. The scoring options are shown in the following table. Dice Points 1 100 for each 5 50 for each Three 1’s 1000 Three 2’s 200 Three 3’s 300 Three 4’s 400 Three 5’s 500 Three 6’s 600 Straight (1-2-3-4-5-6) 1500 3 Multiple scores can be combined from a single roll. For example, a roll of 1-1-3-3-3-4 can score 200 (two 1’s) + 300 (three 3’s) = 500. The player decides which dice to count toward the score by removing those dice from the group. For example, after this roll, the player could remove one 1, both 1’s, the 3’s and the two 1’s, or just the 3’s, etc. Here are is an example of one player’s turn. We are showing the dice sorted in ascending order, to make it easier to find scoring opportunities, but of course in a real game the order of the dice is irrelevant. • Roll = 1-2-2-3-5-6 The player removes 1-5, with a score of 150. The player chooses to roll again with the four remaining dice. • Roll = 1-1-1-2 The player removes 1-1-1, with a score of 1000. Turn score now is 1150. The player chooses to end the turn, rather than roll the one remaining die, and 1150 is added to the game score for that player. Here’s another example. • Roll = 1-2-3-4-4-6 The player removes 1, score = 100. The player chooses to roll the remaining five dice. • Roll = 1-1-3-3-3 The player removes 1-1-3-3-3, scoring 500. Turn score is 600. Note that the two 1’s from this roll cannot be combined with the 1 from the previous roll. This is “Hot Dice,” since all six dice have been used to score. The player chooses to keep rolling, using all six dice. • Roll = 1-2-3-4-5-6 The player removes 1-2-3-4-5-6, score 1200 for a straight. Turn score is 1800. Hot Dice again! The player chooses to keep rolling. • Roll = 2-2-3-3-4-6 FARKLE! The player’s score is reset to zero and the turn is over. Program Specification The main function, which is provided for you, is the top-level user interface (UI) for the game. The assignment specifies several other functions that you must implement. You may also implement additional functions of your own, if you choose to. We will only directly test the functions that are explicitly listed below. First, the program asks how many players. Usually, Farkle requires two or more players. For this program, the maximum is 4. We also allow 1 player for testing purposes – when 1 player is specified, one turn is played for that player, and then the program ends. (This is how we will test your takeTurn function, described below.) Next, the program asks for a random number. You can enter a number using decimal or hexadecimal (0x...) notation. This is used as a seed for the random number generator, described below. For a given number, the same set of random numbers will be generated. This allows you to test your code by trying the same combination over and over, and it allows us to test/grade the code – when a certain seed is specified, your code will generate the same sequence of random numbers as the test program, and so the results should match exactly. 4 At the beginning of each turn, the scores for all players is printed. Then the first roll (of six dice) is performed for the proper player. From there, the main function will call a function that you must write, named takeTurn. This function will interact with the user to complete the turn: removing dice, rolling again, accumulating the score, etc. The takeTurn function returns the score for that player’s turn. When more than one player is specified, the program will continue until some player exceeds 10,000 points, and then it will announce the winner. As described above, if only one player is specified, then only one turn is played, and the score for that turn is printed. Data Structure Because we need to deal with rolling a group of dice, we need a data structure to represent a group of dice. During game play, we can roll any number of dice between 1 and 6. We could use an array of six integers, where each integer represents the value shown by a die. (We could use a value of zero for “empty” slots when fewer than six dice are rolled.) However, we will use a different representation of a group of dice that is more flexible and makes the scoring process for this game easier. We use an array of seven integer. The first integer (element 0) is the number of dice in the group. Elements 1 through 6 contain the number of dice showing that value. In other words, element 1 contains the number of ones, element 2 contains the number of twos, and so forth. See the example in the figure below. The flexibility of this representation is that we can represent any number of six-side dice. Also the dice are already sorted and collated, making
Oct 23, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here