Advertisement
Guest User

Untitled

a guest
Jun 4th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. import random
  2.  
  3. def gen_strategies(): #format of strategy is a 12 digit string, interpreted as each 4 digit string is for card 1,2,3.
  4. #First 2 digits are for first player, first and second decision, next 2 are for second player, decision in case of bet then in case of check by first player
  5. #1 is bet/call, 0 is fold. total of 1728 options.
  6. #remember that strings are 0-indexed
  7. cardstrats=['1000','1001','1010','1011','0000','0001','0010','0011','0100','0101','0110','0111']
  8. strategies=[]
  9. for first in cardstrats:
  10. for second in cardstrats:
  11. for third in cardstrats:
  12. strategies.append(first+second+third)
  13. return strategies
  14.  
  15. debug=True
  16. debug=False
  17. def run_game(i,j):
  18. a,b=0,0
  19. for game in range(0,50):
  20. acard=random.randint(1,3)
  21. bcard=random.randint(1,3)
  22. while (acard==bcard):
  23. bcard=random.randint(1,3)
  24. if debug:
  25. print 'strategies: first: ',i,' second: ',j
  26. print 'cards ',acard,bcard
  27. if i[acard*4-4]=='1': #first player bets
  28. if j[bcard*4-2]=='1': #second player calls bet
  29. if acard>bcard: #a wins 2, b loses 2
  30. if debug:
  31. print "both bet, a wins 2, b loses 2"
  32. a+=2
  33. b-=2
  34. continue
  35. if bcard>acard: #b wins 2, a loses 2
  36. if debug:
  37. print "both bet, b wins 2, a loses 2"
  38. b+=2
  39. a-=2
  40. continue
  41. else: #second player folds, a wins 1, b loses 1
  42. if debug:
  43. print "second player folds, a wins 1, b loses 1"
  44. a+=1
  45. b-=1
  46. continue
  47. else: #first player checks
  48. if j[bcard*4-1]=='1': #second player bets
  49. if i[acard*4-3]=='1': # first player calls
  50. if acard>bcard: #a wins 2, b loses 2
  51. if debug:
  52. print "both bet after a checks, a wins 2, b loses 2"
  53. a+=2
  54. b-=2
  55. continue
  56. if bcard>acard: #b wins 2, a loses 2
  57. if debug:
  58. print "both bet after a checks, b wins 2, a loses 2"
  59. b+=2
  60. a-=2
  61. continue
  62. else: #first player folds, b wins 1, a loses 1
  63. if debug:
  64. print "first player folds, b wins 1, a loses 1"
  65. b+=1
  66. a-=1
  67. else: #second player checks
  68. if acard>bcard: #a wins 1, b loses 1
  69. if debug:
  70. print "both check, a wins 1, b loses 1"
  71. a+=1
  72. b-=1
  73. continue
  74. if bcard>acard: #b wins 1, a loses 1
  75. if debug:
  76. print "both check, a loses 1, b wins 1"
  77. b+=1
  78. a-=1
  79. continue
  80.  
  81. return (a,b)
  82. strategies=gen_strategies()
  83. results=[[s,0] for s in strategies]
  84.  
  85. for (num,i) in enumerate(results):
  86. print num
  87. for j in results:
  88. (a,b)=run_game(i[0],j[0])
  89. i[1]+=a
  90. j[1]+=b
  91.  
  92. for i in results:
  93. print i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement