Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

172 lines
5.0KB

  1. #!/usr/bin/python3
  2. # plays the wizard's ace-five count
  3. # <http://wizardofodds.com/games/blackjack/appendix/17/>
  4. # with the simple strategy at
  5. # <http://wizardofodds.com/games/blackjack/appendix/21/>
  6. #
  7. #
  8. # Player's hand Dealer's upcard
  9. #
  10. # -- hard --------------------------------
  11. # 2 to 6 7 to A
  12. # 4 to 8 H H
  13. # 9 D H
  14. # 10 or 11 D with more than dealer
  15. # 12 to 16 S H
  16. # 17 to 21 S S
  17. #
  18. # -- soft --------------------------------
  19. # 2 to 6 7 to A
  20. # 13 to 15 H H
  21. # 16 to 18 D H
  22. # 19 to 21 S S
  23. #
  24. # -- split -------------------------------
  25. # 2 to 6 7 to A
  26. # 22,33,66,77,99 Y N
  27. # 88,AA Y Y
  28. # 44,55,TT N N
  29. #
  30. # Plus:
  31. # 1. surrender 16 vs 10
  32. # 2. never take insurance
  33. # 3. if not allowed to double, stand with soft 18
  34. #
  35. import sys
  36. import fileinput
  37. max_bet = 8
  38. debug = False
  39. n_player_cards = 0
  40. count = 0
  41. bet = 1
  42. for linenl in fileinput.input():
  43. line = linenl.rstrip()
  44. if debug:
  45. print("<- %s" % line, file = sys.stderr)
  46. if line == "bye":
  47. sys.exit(0)
  48. elif line == "shuffling":
  49. count = 0
  50. bet = 1
  51. elif line[:8] == "new_hand":
  52. n_player_cards = 0
  53. elif line == "insurance?":
  54. print("no", flush = True)
  55. if debug:
  56. print("<- no", file = sys.stderr)
  57. elif line == "bet?":
  58. if count <= 1:
  59. bet = 1
  60. elif bet < max_bet:
  61. bet *= 2
  62. print(bet, flush = True)
  63. #print("1", flush = True)
  64. elif line[:15] == "player_split_ok":
  65. n_player_cards = 1
  66. elif line[:5] == "card_":
  67. tokens = line.split()
  68. if (len(tokens) > 1):
  69. card = tokens[1][0]
  70. else:
  71. card = "" # the dealer's hole card
  72. # count aces and fives
  73. if card == "A":
  74. count -= 1
  75. if debug:
  76. print("ACE, count is %d" % count, file = sys.stderr)
  77. elif card == "5":
  78. count += 1
  79. if debug:
  80. print("FIVE, count is %d" % count, file = sys.stderr)
  81. if line[:11] == "card_player":
  82. n_player_cards += 1
  83. if n_player_cards == 1:
  84. card_player_first = card
  85. elif n_player_cards == 2:
  86. card_player_second = card
  87. elif line[:5] == "play?":
  88. tokens = line.split()
  89. player = int(tokens[1])
  90. dealer = abs(int(tokens[2]))
  91. action = "quit"
  92. if n_player_cards == 2 and card_player_first == card_player_second and \
  93. ((card_player_first == "8" or card_player_first == "A") or \
  94. (dealer < 7 and \
  95. (card_player_first == "2" or \
  96. card_player_first == "3" or \
  97. card_player_first == "6" or \
  98. card_player_first == "7" or \
  99. card_player_first == "9"))): # --- split------------------------------------
  100. action = "split" # always split aces and 8s but 2,3,6,7 & 9 only against 6 or less
  101. else:
  102. if player > 0: # --- hard ------------------------------------
  103. if player < 9:
  104. action = "hit" # hit 4 to 8 against anything
  105. elif player == 9:
  106. if dealer < 7:
  107. if n_player_cards == 2:
  108. action = "double" # double 9 against 2 to 6
  109. else:
  110. action = "hit" # else hit
  111. else:
  112. action = "hit" # hit 9 against 7 to A
  113. elif player < 12:
  114. if player > dealer:
  115. if n_player_cards == 2:
  116. action = "double" # double with 10 or 11 and more than dealer
  117. else:
  118. action = "hit"
  119. else:
  120. action = "hit" # otherwise hit
  121. elif player < 17:
  122. if dealer < 7:
  123. action = "stand" # stand with 12 to 16 against 2 to 6
  124. else:
  125. action = "hit" # hit with 12 to 16 against 7 to A
  126. else:
  127. action = "stand" # stand with hard 17 or more
  128. else:
  129. # soft
  130. player = abs(player)
  131. if player < 16:
  132. action = "hit" # hit every soft hand less than 16
  133. elif player < 19:
  134. if dealer < 7:
  135. if n_player_cards == 2:
  136. action = "double" # double soft 16 to 18 againt 2 to 6
  137. elif player == 18:
  138. action = "stand" # stand with soft 18
  139. else:
  140. action = "hit" # hit soft 17
  141. else:
  142. action = "hit" # hit soft 16 to 18 against 7 to A
  143. else:
  144. action = "stand" # stand with soft 19 or more
  145. print(action, flush = True)
  146. if debug:
  147. print("-> %s" % action, file = sys.stderr)
  148. elif line == "invalid_command":
  149. print("I sent an invalid command!", file = sys.stderr)