- LAB 4 TASK/INSTRUCTIONS
Task 0: [This will be the same for all labs]: Start you code with comments that include this lab ID, your full name, email address, and student id as follows:
# Lab 4
# Author: Michael S. Brown
# Email: [email protected] # Student ID: 10233030
This lab has only 1 task. Please read carefully. A video of this lab running is available here.
https://www.eecs.yorku.ca/~mbrown/EECS1015_Lab4.mp4
See explanation of the task on next page.
Main Task Two Card Poker Game
In this lab you are to write a simple two card poker game as follows:
Each play of the game, the user will get two cards and the computer will get two cards.
Cards are an integer value between 2-14, but are printed out as 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A The winner of the game is based on the following rankings:
Pair (2 cards of the same value)
- if both players have a pair, then the pair with the highest numerical value wins
- if only one player has a pair, then the pair wins
Highest Cards
- if neither player has a pair, then the player with the highest card wins.
- if both players highest card is the same, then the winner goes to the player with the second highest card Tie: If both players have the exact same cards then no winner, it is a tie
Example:
[A] [A] beats [K] [K] when both players have a pair, the highest pair wins
[2] [2] beats [A] [K] if only one player has a pair, the pair wins
[A] [K] beats [A] [Q] if neither has a pair, the highest card wins. If both players have the same highest card, then the 2nd highest card wins (in this case, [K] (13) beats [Q] (12) ) [A] [2] beats [K] [Q] Otherwise, the highest card wins.
If both plays have the same card, then it is a tie (e.g., [J] [8] and [J] [8] is a tie)
Your requirements read carefully, there are functions you must define to get full marks:
- Write a function named drawcards() [no parameters] that generates two random cards represented as integers with values [2 to 14] inclusive. Your function should return the two cards such that the first card is greater than or equal to the second card.
For example, if random numbers are 2 and 13, then your function should return in the order 13 and 2.
Please see notes on how to return two values with a function.
- Write a function named card2str() [one parameter] that will convert a card integer value to a string and return the string result. Use the following conversion:
Cards with values between 2-10 should be converted their string representation 2 10.
Card value 11 is J, value 12 is Q, value 13 is K and value 14 is A.
For example, card2str(2) will return 2. card2str(12) will return Q
- Write a function named printhand() [three parameters] that will print out the two cards as follows (depending on the player and their cards). [A] [2] Your Cards
[3] [3] Computers Cards
- Write a function named printoutcome() [four parameters] that will print out if you win, lose, or tie. This function should take four arguments (your 2 cards and the computers 2 cards). In my opinion, this is the most difficult function for lab 4. Take care to get it work properly. This functoin needs to compute the correct answer based on the ranking criteria above.
- You program should play one round of the game an then ask the user if youd like to play again (Y/N). If the user doesnt type in N or n, keep playing the game.
Note that you can have more functions that mentioned above, but we will be expecting to see: drawCards, card2str, printhand, printoutput
See next page for example game play.
Example of game play:
** EECS1015 AMAZING TWO CARD POKER GAME **
Pair wins |
[K] [K] YOUR CARDS
[K] [9] COMPUTERS CARDS
YOU WIN
Want to play again? (Y/N) y
High card wins |
[10] [9] YOUR CARDS
[9] [7] COMPUTERS CARDS
YOU WIN
Want to play again? (Y/N) y
High card wins |
[K] [9] YOUR CARDS
[Q] [5] COMPUTERS CARDS
YOU WIN
Want to play again? (Y/N) y
[7] [7] YOUR CARDS Highest pair wins
[A] [A] COMPUTERS CARDS YOU LOSE!
Want to play again? (Y/N) y
[7] [4] YOUR CARDS High card wins
[10] [4] COMPUTERS CARDS
YOU LOSE
Want to play again? (Y/N) y
[J] [9] YOUR CARDS High card wins
[6] [5] COMPUTERS CARDS
YOU WIN
Want to play again? (Y/N) y
[A] [2] YOUR CARDS High card wins
[Q] [8] COMPUTERS CARDS
YOU WIN
Want to play again? (Y/N) y
[J] [10] YOUR CARDS High card wins
[Q] [2] COMPUTERS CARDS
YOU LOSE
Want to play again? (Y/N) y
[7] [6] YOUR CARDS High card wins
[9] [7] COMPUTERS CARDS
YOU LOSE
Want to play again? (Y/N) y
[A] [9] YOUR CARDS 2nd highest card wins
[A] [2] COMPUTERS CARDS
YOU WIN
Want to play again? (Y/N) y
[J] [8] YOUR CARDS High card wins
[Q] [2] COMPUTERS CARDS
YOU LOSE
Want to play again? (Y/N) N STOP PLAYING
** Thank you for playing! **
Reviews
There are no reviews yet.