[SOLVED] 代写 game matlab scala ITP 168: Introduction to MATLAB

30 $

File Name: 代写_game_matlab_scala_ITP_168:_Introduction_to_MATLAB.zip
File Size: 527.52 KB

SKU: 6983200712 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


ITP 168: Introduction to MATLAB
Homework Due: 11:59pm November 9, 2019
Setup:
In this homework we will write 5 functions and one script file to play a game of single-draw 5-card poker similar to the video poker machines you’d find in casinos.
Poker is a game of 5 cards. Each card has a suit and a value associated with it. The hands in poker are ranked:
1. Pair (must be Jacks or higher)
2. Two pairs (can be any value)
3. Three of a kind (can be any value)
4. Straight (the values are all sequential)
5. Flush (the suits are all the same, but the values are not sequential)
6. Full House (a pair and three of a kind)
7. Four of a kind (can be any value)
8. Straight Flush (straight and a flush at the same time)
9. Royal Flush (straight and a flush starting with 10 and ending with Ace)
10. Five of a kind (only happens when playing with multiple decks)
If single-draw poker, you are given an initial hand of 5 cards. From that hand you can choose to keep or discard any number of cards. If you choose to discard any cards, they will be removed from your hand and you will be given new cards to replace them. After this, your final hand is calculated. Based on your hand you will either win money (if you have a winning hand) or lose your bet (if you don’t have a winning hand).
Requirements:
 Create initdeck.m, shuffledeck.m, dealcard.m, printcard.m, calchand.m, and poker.m
 The first 5 files are FUNCTION files and must have the function definition line and H1 line and
the following (without clear; and clc;)
 The last file is a script file
 Using comments, put the following information in each file:
o Name
o ITP 168 Fall 2019 o Homework 7
o USC Email
Include the clear and clc commands in the script file only
Part 1: initdeck() Function
The initdeck function should operate as follows:
 Have one input: the number of decks to create

 Have one output: a card structure array containing the correct number of cards
The function should validate the input. It should be a positive, scalar, numeric, integer value. Create an empty card structure with the following fields:
 Suit: this should store the suit as a string. It should be the entire suit and not just one character to represent it (‘Hearts’ instead of ‘H’)
 Value: this should store a character vector containing the name of the card. It should be the entire value and not just one character to represent it (‘Ace’ instead of ‘A’). All numeric values will be character vectors as well (‘2’, ‘3’, etc.)
 Score: this should be a numeric value that contains the score of the card. Cards are given scores 2 through 14. Jack through Ace is 11, 12, 13, and 14 respectively. Ace is considered the highest, never the lowest.
Replicate the card structure so it creates a full deck of 52 cards. Then, fill each card in the deck with a suit, value, and score.
Once you have created one deck, replicate the deck so that the final output of the function is a series of decks specified by the user.
Part 2: shuffledeck() Function
The shuffledeck() function should operate as follows:
 Have one input: a deck to shuffle
 Have one output: a shuffled deck
Validate the input. The input must be a card structure array of at least 52 cards. To validate that it is a card structure, use the isfield() function to validate that the input has the same fields as the card structure definition given in Part 1.
Using any method given in class or on the midterm, shuffle the deck so that the cards appear randomly. You can do this by swapping two cards at random a large number of times.
Part 3: dealcard() Function
The dealcard() function should operate as follows:
 Have one input: a deck to deal from
 Have two outputs: the top card, and the rest of the deck
Validate the input. It should be the same validation as the shuffledeck() function.
Make the first output the first card of the deck, then remove the first card of the deck so there is one less card in the deck. Set the second output to be the rest of the deck.
Part 4: printcard() Function
The printcard() function should operate as follows:
 Have one input: the card to print

 Have no outputs
Validate the input. It should be a card structure, but only one. Use the same validation as the
shuffledeck() function, but validate that it is only ONE card.
Once you’ve validated the input, print the card so that it shows up in the form “VALUE of SUIT” where VALUE is the card’s value and SUIT is the card’s suit. For example: 2 of Spades
Part 5: calchand() Function
The calchand() function should operate as follows:
 Have one input: a card structure array
 Have one output: the rank of the hand (1-10)
Validate the input. It should be a card structure array with exactly 5 cards. Use the same validation as
the shuffledeck() function, but validate that it is exactly 5 cards.
Once the input has been validated, use any combination of functions taught in class to determine what the highest rank is. Follow the rank system given in the Goal section of the assignment. The function should output the correct rank.
To accomplish this, I would suggest making local functions to test for the various hands.
To determine whether pairs, three of a kind, four of a kind, or five of a kind exist, I would suggest extracting the scores from each card and placing it in a numeric array. Since pairs, three of a kind, four of a kind, and five of a kind do not rely on the suit, it makes no sense to keep track of anything but the score. Use logic arrays and loop to determine whether there are duplicate values in the numeric array.
To determine if a flush has occurred, apply the same logic as determining if a five of a kind has occurred, but apply it to the suit.
To determine if a straight has occurred, you can use the diff() function. The diff() function finds the difference between adjacent elements in a vector. Use it’s result (and maybe another function) to determine if the values are all sequential.
To determine if a full house has occurred, determine if there is a pair AND a three of a kind.
To determine if a straight flush has occurred, just determine if the hand is a straight and a flush but NOT a royal flush.
Part 6: Script
After you have written all of your functions, write the script file so it continually plays the game of single-draw five-card poker until the user runs out of money or decides to quit. The process should be:
1. Ask the user for the number of decks to play with
a. Validate the number: must be positive integer
2. Set the user’s initial cash to be $100
3. Start a round
4. Create the decks using the input from Step 1

5. Shuffle the decks
6. Deal 5 cards and store them in the user’s hand
7. Ask the user to bet
a. Validate the bet: must be positive integer less than the total cash
8. Print the hand (all 5 cards) along with the index values of each card
9. Calculate the rank of the hand
10. Print the hand’s rank to the user (see output)
11. Ask the user to choose which cards to swap
a. They will enter index values
b. Multiple cards to swap will be given as a vector using []
c. If they don’t want to swap they will enter only a 0
12. Validate the user’s choice for cards to swap
a. They cannot enter more than 5 values
b. They cannot enter duplicate values (cannot have more than 1 of each)
c. They cannot enter invalid index values (outside the range or non-integers)
13. If the user chooses cards to swap out, delete those cards from the hand
14. Deal cards to the user’s hand if they swapped out cards
15. Calculate the new hand’s rank
16. Display the new cards
17. If the rank is at least a pair of Jacks, calculate the winning multiplier:
a. Pair: 1
b. Two Pair: 2
c. Three of a Kind: 3
d. Straight: 5
e. Flush: 7
f. Full House: 8
g. Four of a Kind: 10
h. Straight Flush: 15
i. Royal Flush: 20
j. Five of a Kind: 35
18. If the rank is at least a pair of Jacks, display the rank and the multiplier and calculate the winnings
a. If the user did not win, then the winnings are 0
19. Decrease the player’s cash by the bet and increase it by the winnings
20. Ask if they want to do it again
21. Repeat Step 4-20 as long as the user wants to keep playing and they have cash left
22. Display the cash the user leaves with
Sample Output:
This is a sample of what the program should show in the command window. If the user enters any information, it will be highlighted in RED:

Enter number of decks to play with: 1.2
Incorrect input! Enter a positive integer value!
Enter number of decks to play with: -1
Incorrect input! Enter a positive integer value!
Enter number of decks to play with: 2
You have $100
Place your bet: $1000
Invalid bet! Must be positive integer! Cannot exceed current cash! Place your bet: $0
Invalid bet! Must be positive integer! Cannot exceed current cash! Place your bet: $1.2
Invalid bet! Must be positive integer! Cannot exceed current cash! Place your bet: $1
1: 4 of Hearts
2: 3 of Clubs
3: 3 of Clubs
4: 9 of Clubs
5: 8 of Diamonds
You currently have nothing! Jacks or Higher to win!
Swap cards using index values and [], or 0 to keep all your cards: Duplicate values! Try again!
Swap cards using index values and [], or 0 to keep all your cards: 6]
Invalid number of cards to swap! Try again!
Index values invalid! Try again!
Swap cards using index values and [], or 0 to keep all your cards: Index values invalid! Try again!
Swap cards using index values and [], or 0 to keep all your cards: Index value invalid! Try again!
Swap cards using index values and [], or 0 to keep all your cards: Duplicate values! Try again!
Index values invalid! Try again!
Swap cards using index values and [], or 0 to keep all your cards: 1: 4 of Hearts
2: 3 of Clubs
3: 3 of Clubs
4: 9 of Clubs
5: 8 of Diamonds
You have nothing! You lose!
Play again? (Y/N): y
You have $99
Place your bet: $1
1: 7 of Diamonds
2: King of Hearts
3: 9 of Clubs
4: Ace of Clubs
[1 1]
[1 2 3 4 5
9
-1
[0 0]
0

5: 4 of Hearts
You currently have nothing! Jacks or Higher to win!
Swap cards using index values and [], or 0 to keep all your cards: [1 3 5] 1: King of Hearts
2: Ace of Clubs
3: 2 of Clubs
4: 5 of Hearts
5: Jack of Hearts
You have nothing! You lose!
Play again? (Y/N): y
You have $98
Place your bet: $1
1: 3 of Clubs
2: Queen of Clubs
3: 3 of Spades
4: 5 of Diamonds
5: Jack of Spades
You currently have
Swap cards using index values and [], or 0 to keep all your cards: [1 3 4] 1: Queen of Clubs
2: Jack of Spades
3: Jack of Hearts
4: 6 of Spades
5: 10 of Spades
You have Pair! You win 1x your bet!
Play again? (Y/N): y
You have $98
Place your bet: $98
1: 5 of Spades
2: 7 of Hearts
3: 5 of Hearts
4: 7 of Spades
5: 6 of Hearts
You currently have Two Pair! Your win level is 2
Swap cards using index values and [], or 0 to keep all your cards: 5
1: 5 of Spades
2: 7 of Hearts
3: 5 of Hearts
4: 7 of Spades
5: 8 of Clubs
You have Two Pair! You win 2x your bet!
Play again? (Y/N): y
You have $196
Place your bet: $196
1: Ace of Diamonds
2: 3 of Clubs
nothing! Jacks or Higher to win!

3: 2 of Hearts
4: 2 of Spades
5: 6 of Spades
You currently have nothing! Jacks or Higher to win!
Swap cards using index values and [], or 0 to keep all your cards: [2 3 4 5] 1: Ace of Diamonds
2: Queen of Clubs
3: Jack of Diamonds
4: 6 of Hearts
5: 4 of Hearts
You have nothing! You lose! Play again? (Y/N): y
You are out of money!
Deliverables:
Create a .ZIP file containing the file(s):
 initdeck.m
 shuffledeck.m  dealcard.m
 printcard.m
 calchand.m
 poker.m
Name it Homework7.ZIP and submit it to Blackboard by the due date. Grading Rubric:
*Points will be taken off for poor coding style for a maximum of 1-point deduction per file
**Up to 2 points will be taken off for not submitting a ZIP file
***Intentional instantiation of an infinite loop will result in an automatic 10% deduction of total points for each occurrence.
Item
Points
initdeck() Function
10 Points
shuffledeck() Function
10 Points
dealcard() Function
5 Points
printcard() Function
5 Points
calchand() Function
30 Points
Script File
40 Points
Total
100 Points

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 代写 game matlab scala ITP 168: Introduction to MATLAB
30 $