Author Topic: Blackjack game (unfortunately variable names compressed)  (Read 4693 times)

0 Members and 1 Guest are viewing this topic.

Offline qbguy

  • Newbie
  • Posts: 11
    • View Profile
Blackjack game (unfortunately variable names compressed)
« on: October 06, 2018, 09:21:08 pm »
Code: QB64: [Select]
  1. DECLARE SUB N (Y!)
  2. DIM SHARED A(1 TO 52), B(0 TO 16, 1 TO 16), C(0 TO 16)
  3. DIM SHARED D(0 TO 16), E(1 TO 16)
  4. F = 1000
  5. G = 0
  6. FOR I = 0 TO 16
  7. C(I) = 0
  8. FOR J = 1 TO 16
  9. B(I, J) = 0
  10. E(J) = 0
  11. PRINT "Your money: "; F
  12. E(1) = -1
  13. WHILE E(1) < 0 AND E(1) <= 1000
  14. INPUT "Wager"; E(1)
  15. IF E(1) < 0 THEN PRINT "Bet must be nonnegative."
  16. IF E(1) > 1000 THEN PRINT "Max bet $1000."
  17. H = 1
  18. K = 1
  19. N 0
  20. N 0
  21. N 1
  22. N 1
  23. O
  24. PRINT "Dealer Upcard: "; R$(B(0, 1))
  25. PRINT "Your hand:"; R(B(1, 1)); R(B(1, 2))
  26.  
  27. IF B(0, 1) = 11 THEN
  28. 1 INPUT "Would you like insurance"; X$
  29. X$ = UCASE$(LTRIM$(RTRIM$(X$)))
  30. CASE "Y", "YES", "AYE", "YUP", "YEAH", "OUI", "JA", "SI"
  31. L = .5 * E(1)
  32. CASE "N", "NAY", "NOPE", "NO", "NEIN", "NYET", "NON"
  33. L = 0
  34. IF D(0) = 21 THEN
  35. PRINT "Dealer Blackjack."
  36. IF D(1) <> 21 THEN F = F - E(1)
  37. IF L > 0 THEN
  38. PRINT "You get "; L * 2; "from insurance"
  39. F = F + L * 2
  40. L = 0
  41. ELSEIF D(1) = 21 THEN
  42. IF L > 0 THEN
  43. PRINT "You lose the insurance bet"
  44. F = F - L
  45. L = 0
  46. PRINT "Blackjack!"
  47. F = F + E(1) * 1.5
  48. ELSEIF L > 0 THEN
  49. PRINT "You lose the insurance bet"
  50. F = F - L
  51. L = 0
  52. DO WHILE H <= K
  53. 2 LINE INPUT "Your move:"; X$
  54. X$ = LTRIM$(RTRIM$(UCASE$(X$)))
  55. CASE "HIT", "H"
  56. N H
  57. O
  58. IF D(H) >= 21 THEN H = H + 1
  59. CASE "STAND", "S"
  60. H = H + 1
  61. CASE "DOUBLE", "D"
  62. E(H) = E(H) * 2
  63. N H
  64. O
  65. H = H + 1
  66. CASE "SPLIT", "P"
  67. IF (P(B(H, 1)) <> P(B(H, 2))) OR (C(H) <> 2) THEN
  68. PRINT "You cannot split."
  69. B(K + 1, 1) = B(H, 2)
  70. C(K + 1) = 1
  71. N K + 1
  72. B(H, 2) = 0
  73. C(H) = 1
  74. N H
  75. K = K + 1
  76. E(K) = E(H)
  77. O
  78. CASE "QUIT", "Q", "BYE", "ADIOS"
  79. PRINT "Invalid Selection"
  80. PRINT "Dealer Upcard: "; R$(B(0, 1))
  81. FOR I = 1 TO K
  82. PRINT "Hand"; I; ": ";
  83. FOR J = 1 TO C(I)
  84. PRINT R(B(I, J));
  85. IF H = I THEN PRINT "<- Current hand ";
  86. PRINT "(Sum ="; D(I); ")"
  87. PRINT "Dealer's hand:"; R$(B(0, 1)); R$(B(0, 2));
  88. 3 O
  89. IF D(0) < 17 THEN
  90. T = TIMER + .5
  91. N 0
  92. PRINT R$(B(0, C(0)));
  93. FOR I = 1 TO K
  94. IF D(I) > 21 THEN
  95. PRINT "Bust on Y"; I
  96. F = F - E(I)
  97. ELSEIF D(0) > 21 THEN
  98. PRINT "Dealer bust: win on Y"; I
  99. F = F + E(I)
  100. ELSEIF D(I) > D(0) THEN
  101. PRINT "Win on Y"; I
  102. F = F + E(I)
  103. ELSEIF D(I) < D(0) THEN
  104. PRINT "Lose on Y"; I
  105. F = F - E(I)
  106. PRINT "Push on Y"; I
  107.  
  108. SUB M
  109. FOR I = 1 TO 52
  110. A(I) = I
  111. J = 52
  112. K = INT(J * RND(1)) + 1
  113. SWAP A(K), A(J)
  114. J = J - 1
  115. LOOP WHILE J > 1
  116.  
  117. SUB N (Y)
  118. C(Y) = C(Y) + 1
  119. B(Y, C(Y)) = Q
  120.  
  121. SUB O
  122. FOR I = 0 TO K + 1
  123. T = 0
  124. S = 0
  125. FOR J = 1 TO C(I)
  126. X = P(B(I, J))
  127. S = S + X
  128. IF X = 11 THEN T = T + 1
  129. DO WHILE (S > 21 AND T > 0)
  130. S = S - 10
  131. T = T - 1
  132. D(I) = S
  133.  
  134. FUNCTION P (W)
  135. V = (W MOD 13) + 1
  136. P = 11
  137. CASE 2 TO 10
  138. P = V
  139. CASE 11 TO 13
  140. P = 10
  141.  
  142. IF G = 52 THEN M: G = 0
  143. G = G + 1
  144. Q = A(G)
  145.  
  146. FUNCTION R$ (W)
  147. SUIT = CHR$(((W - 1) \ 13) + 3)
  148. V = 1 + (W MOD 13)
  149. R$ = "A" + SUIT + " "
  150. CASE 2 TO 10
  151. R$ = LTRIM$(STR$(V)) + SUIT + " "
  152. CASE 11
  153. R$ = "J" + SUIT + " "
  154. CASE 12
  155. R$ = "Q" + SUIT + " "
  156. CASE 13
  157. R$ = "K" + SUIT + " "
  158.  
  159.