Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def gen_strategies(): #format of strategy is a 12 digit string, interpreted as each 4 digit string is for card 1,2,3.
- #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
- #1 is bet/call, 0 is fold. total of 1728 options.
- #remember that strings are 0-indexed
- cardstrats=['1000','1001','1010','1011','0000','0001','0010','0011','0100','0101','0110','0111']
- strategies=[]
- for first in cardstrats:
- for second in cardstrats:
- for third in cardstrats:
- strategies.append(first+second+third)
- return strategies
- debug=True
- debug=False
- def run_game(i,j):
- a,b=0,0
- for game in range(0,50):
- acard=random.randint(1,3)
- bcard=random.randint(1,3)
- while (acard==bcard):
- bcard=random.randint(1,3)
- if debug:
- print 'strategies: first: ',i,' second: ',j
- print 'cards ',acard,bcard
- if i[acard*4-4]=='1': #first player bets
- if j[bcard*4-2]=='1': #second player calls bet
- if acard>bcard: #a wins 2, b loses 2
- if debug:
- print "both bet, a wins 2, b loses 2"
- a+=2
- b-=2
- continue
- if bcard>acard: #b wins 2, a loses 2
- if debug:
- print "both bet, b wins 2, a loses 2"
- b+=2
- a-=2
- continue
- else: #second player folds, a wins 1, b loses 1
- if debug:
- print "second player folds, a wins 1, b loses 1"
- a+=1
- b-=1
- continue
- else: #first player checks
- if j[bcard*4-1]=='1': #second player bets
- if i[acard*4-3]=='1': # first player calls
- if acard>bcard: #a wins 2, b loses 2
- if debug:
- print "both bet after a checks, a wins 2, b loses 2"
- a+=2
- b-=2
- continue
- if bcard>acard: #b wins 2, a loses 2
- if debug:
- print "both bet after a checks, b wins 2, a loses 2"
- b+=2
- a-=2
- continue
- else: #first player folds, b wins 1, a loses 1
- if debug:
- print "first player folds, b wins 1, a loses 1"
- b+=1
- a-=1
- else: #second player checks
- if acard>bcard: #a wins 1, b loses 1
- if debug:
- print "both check, a wins 1, b loses 1"
- a+=1
- b-=1
- continue
- if bcard>acard: #b wins 1, a loses 1
- if debug:
- print "both check, a loses 1, b wins 1"
- b+=1
- a-=1
- continue
- return (a,b)
- strategies=gen_strategies()
- results=[[s,0] for s in strategies]
- for (num,i) in enumerate(results):
- print num
- for j in results:
- (a,b)=run_game(i[0],j[0])
- i[1]+=a
- j[1]+=b
- for i in results:
- print i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement