skilletwaffles

Activity 9 -- Elevens

Feb 3rd, 2015
949
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. LAB CODE FOR ELEVENSBOARD CLASS. EVERYTHING ELSE ON THE STARTER CODE
  2.  
  3. import java.util.List;
  4. import java.util.ArrayList;
  5.  
  6. /**
  7. * The ElevensBoard class represents the board in a game of Elevens.
  8. */
  9. public class ElevensBoard extends Board {
  10.  
  11. /**
  12. * The size (number of cards) on the board.
  13. */
  14. private static final int BOARD_SIZE = 9;
  15.  
  16. /**
  17. * The ranks of the cards for this game to be sent to the deck.
  18. */
  19. private static final String[] RANKS =
  20. {"ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king"};
  21.  
  22. /**
  23. * The suits of the cards for this game to be sent to the deck.
  24. */
  25. private static final String[] SUITS =
  26. {"spades", "hearts", "diamonds", "clubs"};
  27.  
  28. /**
  29. * The values of the cards for this game to be sent to the deck.
  30. */
  31. private static final int[] POINT_VALUES =
  32. {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 0};
  33.  
  34. /**
  35. * Flag used to control debugging print statements.
  36. */
  37. private static final boolean I_AM_DEBUGGING = false;
  38.  
  39.  
  40. /**
  41. * Creates a new <code>ElevensBoard</code> instance.
  42. */
  43. public ElevensBoard() {
  44. super(BOARD_SIZE, RANKS, SUITS, POINT_VALUES);
  45. }
  46.  
  47. /**
  48. * Determines if the selected cards form a valid group for removal.
  49. * In Elevens, the legal groups are (1) a pair of non-face cards
  50. * whose values add to 11, and (2) a group of three cards consisting of
  51. * a jack, a queen, and a king in some order.
  52. * @param selectedCards the list of the indices of the selected cards.
  53. * @return true if the selected cards form a valid group for removal;
  54. * false otherwise.
  55. */
  56. @Override
  57. public boolean isLegal(List<Integer> selectedCards) {
  58. boolean legal = false;
  59.  
  60. if(selectedCards.size() == 2)
  61. legal = containsPairSum11(selectedCards);
  62.  
  63. if(selectedCards.size() == 3)
  64. legal = containsJQK(selectedCards);
  65. return legal;
  66. }
  67.  
  68. /**
  69. * Determine if there are any legal plays left on the board.
  70. * In Elevens, there is a legal play if the board contains
  71. * (1) a pair of non-face cards whose values add to 11, or (2) a group
  72. * of three cards consisting of a jack, a queen, and a king in some order.
  73. * @return true if there is a legal play left on the board;
  74. * false otherwise.
  75. */
  76. @Override
  77. public boolean anotherPlayIsPossible() {
  78. boolean b = false;
  79. if(containsPairSum11() ==true || containsJQK() == true)
  80. b = true;
  81. return b;
  82. }
  83.  
  84. /**
  85. * Check for an 11-pair in the selected cards.
  86. * @param selectedCards selects a subset of this board. It is list
  87. * of indexes into this board that are searched
  88. * to find an 11-pair.
  89. * @return true if the board entries in selectedCards
  90. * contain an 11-pair; false otherwise.
  91. */
  92. private boolean containsPairSum11(List<Integer> selectedCards) {
  93. /* *** TO BE IMPLEMENTED IN ACTIVITY 9 *** */
  94. }
  95.  
  96. /**
  97. * Check for a JQK in the selected cards.
  98. * @param selectedCards selects a subset of this board. It is list
  99. * of indexes into this board that are searched
  100. * to find a JQK group.
  101. * @return true if the board entries in selectedCards
  102. * include a jack, a queen, and a king; false otherwise.
  103. */
  104. private boolean containsJQK(List<Integer> selectedCards) {
  105. /* *** TO BE IMPLEMENTED IN ACTIVITY 9 *** */
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment