Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. /**
  2. * HI-LO games use the correct card order
  3. * values of 1 - 12.
  4. *
  5. * Blackjack games use the card order values,
  6. * of 2 - 13, where the 13th card of each suit
  7. * is the ace.
  8. *
  9. * This function sorts the blackjack card values
  10. * to comply with the correct order values of 1 - 12.
  11. *
  12. * @param $cards
  13. * @return
  14. */
  15. public static function fixCardValues($cards = array())
  16. {
  17. return $cards;
  18.  
  19. $fixed = [];
  20. foreach ($cards as $card) {
  21. if ($card % 13 === 0) {
  22. array_push($fixed, ($card - 12 <= 0) ? 0 : $card - 12);
  23. } else {
  24. array_push($fixed, (int) $card);
  25. }
  26. }
  27. return $fixed;
  28. }
  29.  
  30. /**
  31. * Retrieve the symbol for the specified suit.
  32. *
  33. * @param $suit
  34. * @return
  35. */
  36. public static function retrieveSuitSymbol($suit)
  37. {
  38. $suit = strtoupper($suit);
  39. switch ($suit) {
  40. case 'CLUBS':
  41. return "&#9827;";
  42. case 'SPADES':
  43. return "&#9824;";
  44. case 'HEARTS':
  45. return "&#9829;";
  46. case 'DIAMONDS':
  47. return "&#9830;";
  48. default:
  49. return null;
  50. }
  51. }
  52.  
  53. /**
  54. * Retrieve the face card value.
  55. *
  56. * @param $cardNo
  57. * @return String
  58. */
  59. public static function retrieveCardFace($cardNo)
  60. {
  61. $face = [
  62. 'ACE', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'JACK', 'QUEEN', 'KING'
  63. ];
  64.  
  65. return $face[$cardNo % 13];
  66. }
  67.  
  68. /**
  69. * Retrieve the suit from the card number.
  70. *
  71. * @param $cardNo
  72. * @return String
  73. */
  74. public static function retrieveCardSuit($cardNo)
  75. {
  76. $suit = floor($cardNo / 13);
  77.  
  78. switch ($suit) {
  79. case 0:
  80. return 'SPADES';
  81. case 1:
  82. return 'CLUBS';
  83. case 2:
  84. return 'HEARTS';
  85. case 3:
  86. return 'DIAMONDS';
  87. default:
  88. return null;
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement