def playgame(p1, p2): p1 = Pokerbot(p1) p2 = Pokerbot(p2) t = Table(p1, p2, False) while t.p1.stack > 0 and t.p2.stack > 0: t.play() return t.p2.stack == 0 #return 1 if p1 won, 0 if p2 won
def rungames(my_id, MATCHES, in_q, out_q): match_count = 1 for p1, p2 in iter(in_q.get, "STOP"): if p1 == p2: continue if not p1._lock._callmethod("acquire", (False,)): in_q.put((p1, p2)) try: p1._lock._callmethod("release") except: pass try: p2._lock._callmethod("release") except: pass # print "core %d couldn't get lock for %16s" % (my_id,p1.name) time.sleep(1) continue elif not p2._lock._callmethod("acquire", (False,)): in_q.put((p1, p2)) try: p1._lock._callmethod("release") except: pass try: p2._lock._callmethod("release") except: pass # print "core %d couldn't get lock for %16s" % (my_id,p2.name) time.sleep(1) continue print "core %d running %16s vs %16s" % (my_id, p1.name, p2.name) metrics = [] log = [] for i in range(1, MATCHES + 1): start_time = time.time() t = Table(p1, p2, False) while t.p1.stack > 0 and t.p2.stack > 0: t.play() end_time = time.time() if t.p1.stack == 0: winner = t.p2.name loser = t.p1.name else: winner = t.p1.name loser = t.p2.name stats = [ t.p1.name, t.p2.name, str(i), str(end_time - start_time), str(t.hands_played), # str(float(t.p1.time)/t.p1.num_actions), # str(float(t.p2.time)/t.p2.num_actions), str(t.p1.num_actions), str(t.p2.num_actions), str(asizeof(t.p1.bot)), str(asizeof(t.p2.bot)), winner, loser, ] metrics.append(stats) # data.writerow(stats) print "Match #" + str(match_count) + " complete, " + winner + " beats " + loser output = [t.p1.name, t.p2.name, "True"] # out.writerow(output) match_count += 1 try: match_count = match_count except: t.p1.stack = 0 t.p2.stack = 0 print "Match #" + str(match_count) + " failed" print "Offenders were " + t.p1.name + " & " + t.p2.name output = [t.p1.name, t.p2.name, "False"] stats = [] # out.writerow(output) match_count += 1 log.append(output) out_q.put((metrics, log)) p1._lock._callmethod("release") p2._lock._callmethod("release")