Logikos

Blackjack bot and user = 21, should give user money, OR push

Feb 17th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.07 KB | None | 0 0
  1. ;Coded by Illpastethat, Adam, Illjustinthat, and modified noobishly by Chromatic
  2. ;Blackjack, against bot, !bj (start) !hm (hit me) !stand (stand/hold);
  3. on $*:text:/^[!](bj|blackjack)(\s|$)/Si:#qi_interesting: {
  4. if (%flood3227) { return }
  5. set -u20 %flood32 On
  6. var %bank12 = $readini(Casino.ini, $nick, Money)
  7. var %moneypercent12 = $calc($2 / %bank12)
  8. var %moneypercentbj = $calc(%moneypercent12 * 100)
  9. var %Balance = $readini( casino.ini, $nick, Money)
  10. if ($($+(%,bj.,$nick,.cards),2)) {
  11. msg $chan $+($caps($nick),$chr(44)) you still have a game in progress!
  12. describe $chan $+($caps($nick),$chr(44)) your cards are: $($+(%,bj.,$nick,.cards),2) = $($+(%,bj.,$nick,.ctotal),2)
  13. }
  14. elseif (%moneypercentbj > 30) { describe $chan ( $+ $Nick $+ ) Maximum Bet for Blackjack is 30 Percent of your Total Money, use !money To see your Funds. | halt }
  15. elseif ($2 !isnum) {
  16. msg $chan $caps($nick) $+ , that is not a valid bet, try $1 10
  17. }
  18. elseif ($2 < 10) {
  19. msg $chan $caps($nick) $+ , the minimum bet is 10 Dollars.
  20. }
  21. ; elseif ($2 > 7500) {
  22. ; msg $chan $caps($nick) $+ , the maximum bet is 7500 Dollars.
  23. ;}
  24. elseif ($readini( casino.ini, $nick, Money ) == $null) {
  25. describe $chan $caps($nick) , You have not registered yet. Please have some complimentary Money. Type: !ATM
  26. halt
  27. }
  28. elseif %Balance == 0 {
  29. msg $chan $caps($nick) $+ , you don't have any Money, Ask someone for a loan, or for 100 Dollars type !ATM.
  30. }
  31. elseif ($2 < 10) {
  32. msg $chan $caps($nick) $+ , the minimum bet is 10 Dollars.
  33. }
  34. elseif ($left($2,1) == $chr(45)) {
  35. msg $chan $caps($nick) $+ , you can not use negative numbers.
  36. }
  37. elseif ($2 <= 0) {
  38. msg $chan $caps($nick) $+ , please use a positive number.
  39. }
  40. elseif ($2) && (%Balance < $2) {
  41. msg $chan $caps($nick) $+ , you can not wager that much because you only have $bytes(%Balance,b) Dollars.
  42. }
  43. else {
  44. /set %housemoney $calc( $readini( house.ini, House, Money) + $2 )
  45. /writeini house.ini House Money %housemoney
  46. unset $+(%,bj.,$nick,.*)
  47. set $+(%,bj.,$nick,.bet) $2
  48. set $+(%,bj.,$nick,.cards) $instok($($+(%,bj.,$nick,.cards),2),$getcard,1,43)
  49. set $+(%,bj.,$nick,.cards) $instok($($+(%,bj.,$nick,.cards),2),$getcard,1,43)
  50. set $+(%,bj.,$nick,.ctotal) $gettotal($($+(%,bj.,$nick,.cards),2))
  51. set $+(%,bj.,$nick,.bcards) $instok($($+(%,bj.,$nick,.bcards),2),$getcard,1,43)
  52. set $+(%,bj.,$nick,.bcards) $instok($($+(%,bj.,$nick,.bcards),2),$getcard,1,43)
  53. set $+(%,bj.,$nick,.btotal) $gettotal($($+(%,bj.,$nick,.bcards),2))
  54. describe $chan $+($caps($nick),) your cards are: $($+(%,bj.,$nick,.cards),2) = $($+(%,bj.,$nick,.ctotal),2)
  55. ;In regular blackjack at this point the game would show you the dealers face card (use $gettok to get the last card)
  56. }
  57. if ($($+(%,bj.,$nick,.ctotal),2) > 21) {
  58. describe $chan $+(,$caps($nick)) has Busted and [Qi_bot] wins ([Qi_bot] $+ 's score: $($+(%,bj.,$nick,.btotal),2) - $nick $+ 's score: $($+(%,bj.,$nick,.ctotal),2) $+ )
  59. msg $chan $+(,$caps($nick)) you lose $($+(%,bj.,$nick,.bet),2) Dollars.
  60. var %Dollars $calc($readini( Casino.ini, $nick, Money) - $($+(%,bj.,$nick,.bet),2))
  61. ; You should notice it's using a different file and an .Ini file at that.. I still used your algorithm, just had it write to Casino.Ini which simply outputs
  62. ; [Nick] on line 1, then next line is Money=their money for each person who plays.
  63. writeini casino.ini $nick Money %Dollars
  64. unset $+(%,bj.,$nick,.*)
  65. }
  66. elseif ($($+(%,bj.,$nick,.ctotal),2) == 21) {
  67. botHits
  68. describe $chan $+(,$caps($nick)) got ,[||[B-L-A-C-K-J-A-C-K!]||] ([Qi_bot] $+ 's score: $($+(%,bj.,$nick,.btotal),2) - $+($nick,'s) score: $($+(%,bj.,$nick,.ctotal),2) $+ )
  69. if ($($+(%,bj.,$nick,.btotal),2) == 21) {
  70. var %Dollars $calc($readini( Casino.ini, $nick, Money) - $($+(%,bj.,$nick,.bet),2))
  71. writeini casino.ini $nick Money %Dollars
  72. describe $chan [Qi_bot] got ,[||[B-L-A-C-K-J-A-C-K!]||] [Qi_bot] $+ 's cards: $($+(%,bj.,$nick,.bcards),2)
  73. msg $chan $+(,$caps($nick)) you lose $($+(%,bj.,$nick,.bet),2) Dollars.
  74. unset $+(%,bj.,$nick,.*)
  75. }
  76. else {
  77. var %Dollars $calc($readini( Casino.ini, $nick, Money) + $($+(%,bj.,$nick,.bet),2))
  78. writeini casino.ini $nick Money %Dollars
  79. msg $chan $+(,$caps($nick)) you win $($+(%,bj.,$nick,.bet),2) Dollars.
  80. unset $+(%,bj.,$nick,.*)
  81. }
  82. }
  83. }
  84. alias getcard {
  85. ;Experimented here with the [ and ] Characters which are $chr(91) and $chr(93)... I tried to put those $chr(91) and 93 after the Return surrounding the card description..
  86. ; I thought maybe making them Variables.. then putting the %beg before the Ace and %end after the $Suit would somehow work.. no go.
  87. ;var %beg $chr(91)
  88. ;var %end $chr(93)
  89. var %r $r(1,13)
  90. if (%r == 1) { return Ace of $suit }
  91. elseif (%r == 10) { return 10 of $suit }
  92. elseif (%r == 11) { return Jack of $suit }
  93. elseif (%r == 12) { return Queen of $suit }
  94. elseif (%r == 13) { return King of $suit }
  95. else { return %r of $suit }
  96. }
  97. alias suit {
  98. ; I also tried to do it here..
  99. var %r $r(1,4)
  100. ;Added the spades, hearts, diamonds, and clubs ascii here.. surprised it actually worked.
  101. if (%r == 1) { return ♠Spades♠ }
  102. elseif (%r == 2) { return ♥Hearts♥ }
  103. elseif (%r == 3) { return ♦Diamonds♦ }
  104. elseif (%r == 4) { return ♣Clubs♣ }
  105. }
  106. alias gettotal {
  107. ; I started to do it here, then realized this was nothing but calculation of the amount. :)
  108. var %x 1
  109. while (%x <= $numtok($1-,43)) {
  110. var %tok $gettok($gettok($1-,%x,43),1,32)
  111. ; Is there any smart way to give the user an option to use both Values of the Ace during a game?
  112. if (%tok == Ace) { var %t $calc(%t + 11) }
  113. elseif (%tok == Jack) { var %t $calc(%t + 10) }
  114. elseif (%tok == Queen) { var %t $calc(%t + 10) }
  115. elseif (%tok == King) { var %t $calc(%t + 10) }
  116. else { var %t $calc(%t + %tok) }
  117. inc %x
  118. }
  119. return %t
  120. }
  121. ;Hit command during Blackjack .. Meat of the results of Busting, hitting Blackjack, etc.
  122. on $*:text:/^[!](hit)(\s|$)/Si:#qi_interesting: {
  123. if (!$($+(%,bj.,$nick,.ctotal),2)) { msg # $nick $+ , to start a game type !Blackjack <bet> to start a new game | halt }
  124. set $+(%,bj.,$nick,.cards) $instok($($+(%,bj.,$nick,.cards),2),$getcard,1,43)
  125. set $+(%,bj.,$nick,.ctotal) $gettotal($($+(%,bj.,$nick,.cards),2))
  126. describe $chan $+($caps($nick),$chr(44)) your cards are: $($+(%,bj.,$nick,.cards),2) = $($+(%,bj.,$nick,.ctotal),2)
  127. ;Could run a check at this point to see if they got a five card charlie
  128. if ($($+(%,bj.,$nick,.ctotal),2) >= 22) {
  129. var %Dollars $calc($readini( Casino.ini, $nick, Money) - $($+(%,bj.,$nick,.bet),2))
  130. writeini casino.ini $nick Money %Dollars
  131. msg $chan $+(,$caps($nick)) has gone bust and [Qi_bot] wins ([Qi_bot] $+ 's score: $($+(%,bj.,$nick,.btotal),2) - $nick $+ 's score: $($+(%,bj.,$nick,.ctotal),2) $+ )
  132. msg $chan $+(,$caps($nick)) you lose $($+(%,bj.,$nick,.bet),2) Dollars.
  133. unset $+(%,bj.,$nick,.*)
  134. }
  135. elseif ($($+(%,bj.,$nick,.ctotal),2) == 21) {
  136. msg $chan $+(,$caps($nick)) got - [||[B-L-A-C-K-J-A-C-K!]||] ([Qi_bot] $+ 's score: $($+(%,bj.,$nick,.btotal),2) - $+($nick,'s) score: $($+(%,bj.,$nick,.ctotal),2) $+ )
  137. botHits
  138. if ($($+(%,bj.,$nick,.btotal),2) == 21) {
  139. var %Dollars $calc($readini( Casino.ini, $nick, Money) - $($+(%,bj.,$nick,.bet),2))
  140. writeini casino.ini $nick Money %Dollars
  141. msg $chan [Qi_bot] got [||[B-L-A-C-K-J-A-C-K!]||] [Qi_bot] $+ 's cards: $($+(%,bj.,$nick,.bcards),2)
  142. msg $chan $+(,$caps($nick)) you lose $($+(%,bj.,$nick,.bet),2) Dollars.
  143. unset $+(%,bj.,$nick,.*)
  144. }
  145. else {
  146. var %Dollars $calc($readini( Casino.ini, $nick, Money) + $($+(%,bj.,$nick,.bet),2))
  147. writeini casino.ini $nick Money %Dollars
  148. msg $chan $+(,$caps($nick)) you win $($+(%,bj.,$nick,.bet),2) Dollars.
  149. unset $+(%,bj.,$nick,.*)
  150. }
  151. }
  152. }
  153. ; Stand/Stay portion -- Similar to above. -- I changed the code to include a "PUSH" result.. if Dealer and user have equal values then it's a push, bet it given back and that's that.
  154. on $*:text:/^[!](stand|stay)(\s|$)/Si:#qi_interesting: {
  155. if (!$($+(%,bj.,$nick,.ctotal),2)) { msg # $nick $+ , to start a game type !Blackjack <bet> to start a new game | halt }
  156. botHits
  157. describe $chan $+($caps($nick),$chr(44)) your cards are: $($+(%,bj.,$nick,.cards),2) = $($+(%,bj.,$nick,.ctotal),2) [Qi_bot] $+ 's cards: $($+(%,bj.,$nick,.bcards),2) = $($+(%,bj.,$nick,.btotal),2)
  158. if ($($+(%,bj.,$nick,.btotal),2) >= 22) {
  159. var %Dollars $calc($readini( Casino.ini, $nick, Money) + $($+(%,bj.,$nick,.bet),2))
  160. writeini casino.ini $nick Money %Dollars
  161. msg $chan [Qi_bot] has gone bust and $nick wins! ([Qi_bot] $+ 's score: $($+(%,bj.,$nick,.btotal),2) - $nick $+ 's score: $($+(%,bj.,$nick,.ctotal),2) $+ )
  162. msg $chan $+(,$caps($nick)) you win $($+(%,bj.,$nick,.bet),2) Dollars.
  163. unset $+(%,bj.,$nick,.*)
  164. }
  165. elseif ($($+(%,bj.,$nick,.btotal),2) == 21) {
  166. var %Dollars $calc($readini( Casino.ini, $nick, Money) - $($+(%,bj.,$nick,.bet),2))
  167. writeini casino.ini $nick Money %Dollars
  168. msg $chan [Qi_bot] got [||[B-L-A-C-K-J-A-C-K!]||] ([Qi_bot] $+ 's score: $($+(%,bj.,$nick,.btotal),2) - $+($nick,'s) score: $($+(%,bj.,$nick,.ctotal),2) $+ )
  169. msg $chan $+(,$caps($nick)) you lose $($+(%,bj.,$nick,.bet),2) Dollars.
  170. unset $+(%,bj.,$nick,.*)
  171. }
  172. elseif ($($+(%,bj.,$nick,.btotal),2) > $($+(%,bj.,$nick,.ctotal),2)) {
  173. var %Dollars $calc($readini( Casino.ini, $nick, Money) - $($+(%,bj.,$nick,.bet),2))
  174. writeini casino.ini $nick Money %Dollars
  175.  
  176. msg $chan $+($caps($nick),) stands and [Qi_bot] wins ([Qi_bot] $+ 's score: $($+(%,bj.,$nick,.btotal),2) - $+($nick,'s) score: $($+(%,bj.,$nick,.ctotal),2) $+ )
  177. msg $chan $+(,$caps($nick)) you lose $($+(%,bj.,$nick,.bet),2) Dollars.
  178. unset $+(%,bj.,$nick,.*)
  179. }
  180. ; Here is the PUSH section of code I added. I'm not sure it works yet, because I haven't had it happen again in chat.
  181. elseif ($($+(%,bj.,$nick,.btotal),2) == $($+(%,bj.,$nick,.ctotal),2)) {
  182. var %Dollars $calc($readini( Casino.ini, $nick, Money) - $($+(%,bj.,$nick,.bet),2))
  183. msg $chan It's a PUSH, $caps($nick)! No-one Wins or Loses this hand. Try Again.
  184. describe $chan Neither one of us Wins or Loses that Hand. Try Again, $Caps($nick). [Qi-Bot] hands $caps($nick) back $($+(%,bj.,$nick,.bet),2) Dollars.
  185. unset $+(%,bj.,$nick,.*)
  186. }
  187. else {
  188. msg $chan $+($caps($nick),) stands and wins ([Qi_bot] $+ 's score: $($+(%,bj.,$nick,.btotal),2) - $+($nick,'s) score: $($+(%,bj.,$nick,.ctotal),2) $+ )
  189. msg $chan $+(,$caps($nick)) you win $($+(%,bj.,$nick,.bet),2) Dollars.
  190. var %Dollars $calc($readini( Casino.ini, $nick, Money) + $($+(%,bj.,$nick,.bet),2))
  191. writeini casino.ini $nick Money %Dollars
  192. unset $+(%,bj.,$nick,.*)
  193. }
  194. }
  195. alias botHits {
  196. while ($($+(%,bj.,$nick,.btotal),2) < 17) {
  197. set $+(%,bj.,$nick,.bcards) $instok($($+(%,bj.,$nick,.bcards),2),$getcard,1,43)
  198. set $+(%,bj.,$nick,.btotal) $gettotal($($+(%,bj.,$nick,.bcards),2))
  199. }
  200. }
Add Comment
Please, Sign In to add comment