class PostMatchHistoryGenerator: def __init__(self):#, fileName): #self.fileName = fileName self.game = GameState() self.archive = PostMatchHistory() self.history = ParseMatchHistory(1000) #self.history.parseHistory(fileName) def run(self): self.history.packets.reverse() while len(self.history.packets) > 0: data = self.history.packets.pop() self.game.parseInput(data[0] + "\n") if self.game.state == NEWGAME: self.archive.reset(self.game) elif self.game.state == HANDOVER: self.game.leftOpp.holeCard1 = data[1][0] self.game.leftOpp.holeCard2 = data[1][1] self.game.rightOpp.holeCard1 = data[2][0] self.game.rightOpp.holeCard2 = data[2][1] self.archive.update(self.game) def plotBets(self): #fig = plt.figure() for pname in self.archive.history.keys(): for s in range(RIVER+1): #t = RAISE for t in self.archive.history[pname][s].keys(): #print s,t ys = [int(a.amount) for a in self.archive.history[pname][s][t]] xs = [a.ev[0] for a in self.archive.history[pname][s][t]] ps = [a.potAmount for a in self.archive.history[pname][s][t]] bs = [a.betAmount for a in self.archive.history[pname][s][t]] if len(xs) == 0: continue print "potamt:%.3f %.3f" % (min(ps),max(ps)), print "betamt:%.3f %.3f" %(min(bs),max(bs)) #print xs,ys plt.figure() plt.title(pname) if min(ys) == max(ys): zs = [0 for i in range(1001)] for y in xs: zs[y] += 1 x = [] y = [] for i,z in enumerate(zs): if z>0: x+=[i] y+=[z] plt.scatter(x,y) plt.xlabel("HandStrength") plt.ylabel("Frequency of "+ACTION_TYPES[t]+":"+str(min(ys))) elif min(xs)==max(xs): zs = [0 for i in range(201)] for x in ys: zs[x] += 1 x = [] y = [] for i,z in enumerate(zs): if z>0: x+=[i] y+=[z] plt.scatter(x,y) plt.ylabel("Frequency of EV="+str(min(xs))) plt.xlabel(ACTION_TYPES[t] + ".absAmount") else: plt.hexbin(xs,ys,mincnt=1) plt.axis([0,1000,0,205]) plt.xlabel("Hand Strength") plt.ylabel(ACTION_TYPES[t] + ".absAmount") cb = plt.colorbar() cb.set_label('counts') plt.savefig(pname + "-" + STREET_TYPES[s]+"-"+ACTION_TYPES[t] + ".png")
fs = s.makefile() game = GameState() while 1: # block until the engine sends us a packet # data = s.recv(4096) data = fs.readline() # if we receive a null return, then the connection is dead if not data: print "Gameover, engine disconnected" break # Here is where you should implement code to parse the packets from # the engine and act on it. ## print data game.parseInput(data) # When appropriate, reply to the engine with a legal action. # The engine will ignore all spurious packets you send. # The engine will also check/fold for you if you return an # illegal action. # When sending responses, you need to have a newline character (\n) or # carriage return (\r), or else your bot will hang! if game.timebank < 0: print "RUN OUT OF TIME" if game.state == "GETACTION": s.send("CALL\n") # if we get here, the server disconnected us, so clean up the socket s.close()