Guest User

Untitled

a guest
Feb 24th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.97 KB | None | 0 0
  1. Project - Baccarat - Macao
  2. Goal
  3. The goal of this program is to produce a text-based Baccarat game. If you are unfamiliar with Baccarat (and its variant Macao), the general premise is as follows: Players attempt to obtain a higher hand value than the banker by adding the values of cards and taking the last digit of the result. Bets are made and can be increased based on how the player wins. The rules and their details will be clarified below. More information can be found here: https://en.wikipedia.org/wiki/Baccarat_(card_game)#Macao
  4.  
  5. Your game should handle a minimum of one player against the banker. The player will start with an initial chip count and place a bet before each hand is played. Players can play as many hands as they like until they run out of money or choose to quit. When the player quits, the total amount of chips won will be displayed along with a farewell message.
  6. Pair Programming
  7. During this project, you will each work in pairs. Pair programming is a development technique that can often lead to better results and understanding of programming challenges. More details can be found here: https://en.wikipedia.org/wiki/Pair_programming.
  8.  
  9. Setup
  10. Create a Netbeans project similar to how you did so in previous projects. Name it using the following convention: Last1Last2_Project_Baccarat where Last1 and Last2 are the partner’s respective last names.
  11.  
  12. Additionally, please place this header in all of your java source files:
  13.  
  14. /* PROGRAMMERS:
  15. * CLASS: AP Computer Science
  16. * ASSIGNMENT:
  17. *
  18. * CERTIFICATION: We certify that this work is our own and that
  19. * none of it is the work of any other group.
  20. */
  21.  
  22. Specification
  23. Use the following steps to guide your program development. Pay attention to data types and the necessary arithmetic operations, conditional statements, loops, and more. Test your programs thoroughly! This means trying a variety of input values within the possible ranges described below.
  24.  
  25. The Following descriptions are intentionally less explicit in details than previous projects. You will not see “The instance variables are…” Your team must read the specification and come up with things like appropriate instance variables, constants, and method implementation details. This is the design process and allows for flexibility in creating your program.
  26.  
  27. There will be multiple classes and enumerations in this program: Suit, Rank, Card, Hand, Deck, Shoe, Banker, Punter, and Baccarat. Each class is described below. Required methods are explained, but you can (and probably should) make other helper methods. How this is done is up to you, but you should aim to minimize code redundancy and keep your classes readable.
  28.  
  29. NOTE: Do NOT assume that the described methods and variables are the only things needed to complete the program.
  30. NOTE: Just because a method exists does NOT mean you must use it.
  31.  
  32. Enumeration: Suit
  33. Create an Enumeration representing the possible suits cards may be: clubs, diamonds, hearts, or spades.
  34. Enumeration: Rank
  35. Create an Enumeration representing the possible values cards may be: 2 - 10, Jack, Queen, King, or Ace.
  36. Class: Card
  37. Represents a single card in a deck of cards.
  38.  
  39. Every Card has a Suit and Rank.
  40. Create accessors for the suit and rank
  41. Create a constructor that accepts a Suit and Rank.
  42. Create a toString method.
  43. Cards can be represented by two characters: their rank and their suit.
  44. Ace of Spades ⇒ AS
  45. Four of Diamonds ⇒ 4D
  46. Jack of Clubs ⇒ JC
  47. Return the String representation of the Card.
  48. Class: Hand
  49. Represents a single Baccarat Hand. May contain 0 or more cards.
  50. Every Hand has a list of Cards.
  51. Create a default constructor that creates an empty list.
  52. Create an addCard method
  53. Accepts a Card and stores it in the list.
  54. Create a getCard method
  55. Accepts an index and returns the card at that index in the list of Cards.
  56. Create a calculateScore method.
  57. Returns the numeric score of the cards in the hand.
  58. Numeric cards are worth their face value (2 of hearts ⇒ 2), except 10s.
  59. Face cards and 10s are worth 0.
  60. Aces are worth 1.
  61. Scores are calculated by summing the values of individual cards and taking the rightmost digit of the total.
  62. Examples
  63. 5H 5D 7D ⇒ 7
  64. JD KD ⇒ 0
  65. AD AS 10H 2S ⇒ 4
  66. 9H KD ⇒ 9
  67. Create a toString method.
  68. Return a String representation of the Hand.
  69. Each card should be displayed with a space between them.
  70. Examples:
  71. AH 8H
  72. 7D JS 4C
  73.  
  74.  
  75. Class: Deck
  76. Represents a single deck of playing cards with 4 suits, each having 13 cards ranking from 2 - 10, Jack, Queen, King, and Ace totalling 52 cards.
  77.  
  78. A Deck contains a list of Cards.
  79. Create a constructor that accepts a boolean value that represents whether or not to shuffle the deck when created. The constructor should load the list with all 52 cards. If the boolean given is true, shuffle the deck, otherwise leave them in the order created.
  80. Consider using the values method available to all Enumerations.
  81. Values() returns an array containing all the values in the Enumeration and can be used in a loop.
  82. Create a shuffle method.
  83. Shuffle the cards in the deck randomly. Use the Fisher-Yates Shuffle algorithm described in the following pseudo-code. For more information on this shuffle, visit https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle.
  84.  
  85. -- To shuffle an array a of n elements (indices 0..n-1):
  86. for i from n−1 downto 1 do
  87. j ← random integer such that 0 ≤ j ≤ i
  88. exchange a[j] and a[i]
  89.  
  90. Create a getCard method.
  91. Returns a single Card from the deck.
  92. The card returned should no longer be in the deck after the method is called.
  93. Create an isEmpty method.
  94. Returns true if there are no more cards left in the deck, and false otherwise.
  95. Create a toString method.
  96. Returns a String representation of the Deck. Every card should be seen.
  97. Class: Shoe
  98. Represents a card dealing shoe. This will hold two decks for the game, but should be able to hold any number of decks.
  99.  
  100. A Shoe should be able to hold any number of card Decks, but should load them into one collection. Imagine this as a “super deck” where all cards from added Decks are together.
  101. Create a constructor that creates an empty Shoe, i.e. one containing no Cards.
  102. Create an addDeck method that accepts a Deck of cards and adds the cards of this new deck into the Shoe.
  103. Mirroring the Deck class, create a shuffle method following the Fisher-Yates Shuffle algorithm. https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle.
  104. Create a deal method that returns the next available card from the shoe. The dealt card should no longer be in the Shoe after the deal method is called.
  105. Create a method needsShuffle that returns true if less than 25% of the original number of cards is left in the Shoe.
  106.  
  107. Class: Punter
  108. Represents a single human player in the game of Baccarat.
  109.  
  110. Every Punter has a Hand and some whole number of chips. Punters gain and lose chips by playing rounds of Baccarat.
  111. Create a constructor that accepts an initial amount of chips for the Punter.
  112. Create a setHand method.
  113. Accepts a Hand and stores it as the Punter’s hand.
  114. Create an addCard method.
  115. Accepts a single Card to add to the Punter Hand.
  116. Create an accessor to get the number of chips the Punter has.
  117. Create an adjustChips method.
  118. Accepts a number to adjust the chip total by. This may be a positive or negative whole number.
  119. Create a getHandScore method.
  120. Returns the value of the Punter’s hand based on the cards they have.
  121. Create a getCurrentHand method.
  122. Return a String representing the Punter’s current Hand.
  123.  
  124.  
  125. Class: Banker
  126. Represents the Baccarat Banker, which is run by the computer. The banker controls the shoe that contains the decks of cards and has a hand that is challenged by the human players.
  127.  
  128. The banker has a Hand just like the player but also has a Shoe of cards.
  129. Create a default constructor that creates a new Shoe. It must be shuffled before dealing any cards.
  130. Create a shuffle method.
  131. Shuffles the cards in the Shoe.
  132. Create a hasUseableShoe method.
  133. Returns true if the Shoe the Banker has does not need to be shuffled.
  134. Create a dealCard method.
  135. Returns a single card from the Shoe.
  136. Create a dealInitialHand method.
  137. Returns a new Hand with two Cards from the Shoe.
  138. Create a setHand method.
  139. Accepts a Hand and stores it as the banker’s Hand.
  140. Create an addCard method.
  141. Accepts a single Card to add to the banker Hand.
  142. Create a getHandScore method.
  143. Returns the value of the banker’s hand based on the cards they have.
  144. Create a getCurrentHand method.
  145. Returns a String representing the banker’s current Hand.
  146. Create a getIncompleteHand method.
  147. Returns a String representing the banker’s initial Hand, but only shows the first card.
  148. This method can assume there are only two cards in the current hand.
  149.  
  150.  
  151. Class: Baccarat
  152. This class represents the entire game of Baccarat and has the main method that starts the program. It will use all previously created classes to produce a functioning game of Baccarat.
  153.  
  154. NOTE: When asking for numeric input from the user, you MUST validate that given values are within any necessary and appropriate ranges, e.g. chip count, number of decks, etc.
  155.  
  156. The flow the Game is as follows:
  157. Welcome the users to the game.
  158. Ask how many humans (Punters) will be playing the game. Each Punter plays against the banker individually and may leave after any hand.
  159. Ask for the desired number of card decks to be placed in the shoe.
  160. There must be a minimum of 2 decks.
  161. Shuffle the contents of the shoe.
  162. For Each Punter do the following:
  163. Ask the Punter for his or her bet.
  164. The bet must be valid.
  165. If the Shoe has less than 25% of its cards left, let the Punter know with a message and then rebuild the Shoe with a new set of Decks, and finally shuffle it once again.
  166. Deal two cards to the Punter and then deal two cards to the Banker.
  167. When displaying the Banker’s hand only show one of the two cards. As in a physical game, one card would be face down and unknown to the Punter. Show both Punter’s cards.
  168. Ask the Punter if they wish to add another card.
  169. The punter aims to beat the banker’s card value. If not, the bet is lost to the banker.
  170. Hand values are determined by adding the cards in the hand, and taking the last digit of the sum. Numeric cards, except tens, are worth their value; tens and face cards are worth zero; Aces are worth one.
  171. Example: a hand with a 2 and 3 is valued at 5, while a hand with a 2, 4, and 7 is valued at 3.
  172. Once the Punter does not want any other cards or has reached the limit of 6 cards in their hand, the Banker will display its current hand and the winner will be decided. The winner has a higher Hand value.
  173. If there is a tie, the player with the fewest cards wins.
  174. If there is a tie and players have the same number of cards, the banker wins.
  175. If a Punter has a “natural” 9 (meaning the first two cards value at 9), they win triple the bet, unless the banker also has a natural 9.
  176. If a punter has a natural 8, they win double the bet, unless the banker has a natural 8 or higher score.
  177. If a Punter wins with a 7 or lower, only the initial bet is won.
  178. Adjust the Punter’s chip count accordingly and ask if they wish to play again.
  179. If the Punter has no more chips, end the game for that Punter with a message disparaging their lack of Baccarat-playing abilities.
  180. Repeat this process of each Punter playing the game.
  181. Repeat steps a to g until all Punters still playing have finished.
  182. If the Punter has a higher chip count than they started with, leave them with a message congratulating his or her success.
  183. If the Punter has broken even or ended with fewer chips than started with, leave them with a message that neither praises them nor overly disparages them.
  184. Finally, display all players and their total chip count in order of most chips to fewest and The percentage of wins for each player and the banker.
  185. Example: There were 2 punters. Each played 10 hands against the banker. Player 1 won 5 out of 10 hands. Player 2 won 3 out of 10 hands. This means the dealer won 12 out of 20 hands. So the stats would be:
  186. Banker - 12/20 = 60% wins
  187. Player 1 - 5/10 = 50% wins
  188. Player 2 - 3 / 10 = 30% wins
Add Comment
Please, Sign In to add comment