attached file
1 ECE 175: Computer Programming for Engineering Applications Final Project: Two pairs or Better Due Date: Monday December 6, 2021 at 4.00 pm, via D2L dropbox All due date: Group sign up - Tuesday November 23, 2021 by 11.59 pm Mid-project - Tuesday November 23, 2021 at 11.59 pm Final project - Monday December 6, 2021 at 4.00 pm Administrative details: 1.1 Group: You can work on this final project by yourself, or you can work in a group of (maximum) 2 students. If you choose to work as a group, use collaborative tools to facilitate the project development, such as replit.com, google doc, etc. Sign up your team for the final project here: https://forms.gle/UyhcAqDBJZuvTnNo9 The team/group must be signed-up by 11.59 pm on November 23, 2021. No group can be formed after this date (unless approved by an instructor). Sign up even if you will work by yourself. You can check that your group signed up properly at https://docs.google.com/spreadsheets/d/1rQzXrz1E80tkL1S4US2d7z9t6AGU3D-P-owpYmNjnBE/edit?usp=sharing 1.2 Intermediate Code and Design Submission To keep track of your progress, an intermediate code submission is required. The deadline for the intermediate code submission on D2L is Tuesday November 23, 2021 at 11.59 pm. Late submission policy: 20% deduction per day. Submit: 1. A high-level design of your code. You are free to use any format that makes sense to your team (e.g., a flowchart with all functions and how the game proceeds, pseudo-code, etc.). 2. An initial code implementation, with - a deck of cards being implemented as a linked list - a shuffling function that shuffles the deck. - a player hand implemented as a linked list - a print function that can be used to print the deck or the 5-card player’s hand. 3. A skeleton of the remaining code containing all the function prototypes and comments on the input/output of the functions and their intent. 1.3 Final Code Submission: The project is due on Monday December 6, 2021 at 4.00 pm. Both team members must submit the code in the designated Dropbox on D2L. Late submission policy: 20% deduction per day. The last day of final project submission is by 4.00 PM on Wednesday December 8, 2021. After this date/time, the final project will NOT be accepted/graded. 1.4 Academic Integrity Policy: Each team is expected to submit its own code. You may ask others for advice and/or discuss the project in general. However, you/your group MUST WRITE YOUR OWN CODE. If any part of the code submitted by different students or groups of students is identical, ALL involved parties will receive zero credit on the entire project and one letter reduction in their final grade. This policy will be very aggressively enforced. ALL submitted code will be checked with a plagiarism detection tool (http://theory.stanford.edu/~aiken/moss/). 1.5 Suggestions a) Spend time designing your code and use modular programming. Create all function prototypes and describe what they do before developing your code. Create pseudocode of your program. b) Determine test cases for your functions and your overall code to ensure proper functionality. c) Write well-documented code. https://forms.gle/UyhcAqDBJZuvTnNo9 https://docs.google.com/spreadsheets/d/1rQzXrz1E80tkL1S4US2d7z9t6AGU3D-P-owpYmNjnBE/edit?usp=sharing http://theory.stanford.edu/%7Eaiken/moss/ 2 Project description – Two pairs or Better Two pairs or Better is a modified poker game in which the goal is to have a 5-card hand that wins the highest payout. The player first places the bet before being dealt a 5-card hand. The player then decides the cards in his/her hand to keep/discard. The discarded cards are then replaced by new cards drawn from the deck. The 5-card hand is then used to decide whether the player wins the payout. For a deck of 52 cards, 13 faces/ranks are 1(Ace), 2 – 10, Jack (J), Queen (Q), and King (K). Each face has 4 suits: clubs (♣), spades (♠), hearts (♥), diamonds (♦), the followings are the 5-card poker hands from highest to lowest ranking: 1. Royal Flush: the 5-card hand has face values of 10, J, Q, K, A and all cards have the same suit such as 10♠ J♠ Q♠ K♠ A♠ 2. Straight Flush: the 5-card hand has face values that are in a sequence and all cards have the same suit such as J♥ 10♥ 8♥ 9♥ 7♥ 3. Four of a Kind: the 5-card hand has 4 cards of the same face/rank value such as 10♣ 2♦ 10♥ 10♦ 10♠ 4. Full House: the hand has 3 cards of the same face value and 2 cards of another face value such as 2♣ 2♦ 10♥ 10♦ 10♠ 5. Flush: all 5 cards have the same suit with any face value (face values are not in a sequence) such as 5♣ 10♣ 4♣ J♣ 8♣ 6. Straight: the 5-card hand has face values that are in a sequence but not of the same suit such as A♦ 2♦ 3♠ 4♥ 5♣ 7. Three of a Kind: the 5-card hand has 3 cards of the same face value such as 2♣ 6♦ 10♥ 10♦ 10♠ 8. Two Pairs: the 5-card hand has 2 pairs (a pair of one face and the second pair of another face) such as 2♣ 2♦ 10♠ 10♦ 5♦ Payout: The player wins the bet if he/she gets at least two pairs or better with the following payout: If a user places X coins for the bet, Pay Royal Flush 250*X Straight Flush 100*X Four of a Kind 50*X Full House 25*X Flush 10*X Straight 5*X Three of a Kind 4*X Two Pair 2*X 3 Project requirements: Write an interactive C program for the card game – Two pairs or Better using linked lists for the card deck, as well as the player’s hand. Not using linked lists in your final project code results in 0 point for this final project. 2.1) Deck of 52 cards and player and dealer hands 2.1a) To represent cards, use the following struct type: typedef struct card_s { char suit; int face; struct card_s *next; } card; Each card consists of a suit [clubs (♣), spades (♠), hearts (♥), or diamonds (♦)) a face (1(Ace), 2 – 10, Jacks (J), Queens (Q), and Kings (K)) Note: you can modify the above struct (i.e., modify the data type of member(s), add more members, make variable an array, etc.) but you cannot remove the already existing members. 2.1b) The 52-card deck must be implemented using a dynamic list (linked list) of cards. The cards drawn from the deck MUST be removed from the list. 2.1c) Your program then shuffles the deck. One algorithm that you may use to shuffle the deck. (a) For each card in the deck, get a random number in the range of 0 to 51 to be used as the index of the element to swap with that card , i.e. if the first node holds the Jack of clubs (J♣) and the random number generated was 24, and the 24th node holds the 9 of diamonds (9♦), then after the first swap, the first node now holds the 9 of diamonds (9♦), and the 24th node now holds the Jack of clubs (J♣). Then proceed to the second node, find a random index of a card to swap with, and swap those cards, etc. (b) Repeat step (a) at least 10,000 times. Once your code is working, seed the random number generator with a call to time() with srand(). [see sec 2.24 Random numbers in your zyBooks] 2.1d) The player’s hand is implemented using the dynamic list (linked list) of cards. The list is initially populated with the cards drawn from the deck. Note: Card(s) added to the player’s hand (drawn from the deck) must be added to that player’s linked list correctly and MUST be removed from the deck. 2.1e) The free() function should be used to free cards that have been played/discarded.2.1f) The deck should be recreated and shuffled if it has fewer than 20 cards. 2.2 Bet 2.2a) The player starts the game with 100 coins. The game terminates if a) the player loses all coins or b) the player enters -1 when your game/code asks for a bet. 2.2b) The minimum bet is 1 coin, and the maximum bet is number of coins that the player has. 4 2.3 Game 2.3a) The player places a bet (see 2.2 on page 3 for details on the bet). 2.3b) The player is dealt a 5-card hand. 2.3c) The player chooses the cards that he/she wants to keep/discard. The goal is to have the hand that can win the highest payout (see the winning ranking and payout on page 2). 2.3d) The discarded cards will then be replaced by cards drawn from the deck.