deal in probability, not in repetition

This commit is contained in:
Barak Michener 2014-08-04 15:34:53 -04:00
parent 452769a918
commit 12316a9238
3 changed files with 97 additions and 136 deletions

View file

@ -29,6 +29,7 @@ class DeceptionGame(object):
self.n_players = len(player_array)
self.n_good = len([x for x in player_array if x[1] is True])
self.trace = None
self.trace_score = 0.0
self.observations = []
self.seen = []
self.tid = 0
@ -63,7 +64,7 @@ class DeceptionGame(object):
def obs(deal):
if self.player_is_good(deal, player_id, None) == is_good:
return True
return 1.0
else:
return None
transaction.append(obs)
@ -80,7 +81,7 @@ class DeceptionGame(object):
rnd = round - 1
def obs(deal):
return True
return 1.0
self.lancelots_switch_at.append(rnd)
@ -96,7 +97,7 @@ class DeceptionGame(object):
def obs(deal):
if self.player_role(deal, player_id) == role_str:
return True
return 1.0
else:
return None
transaction.append(obs)
@ -200,47 +201,29 @@ class DeceptionGame(object):
deck = self.quick_permutations[:]
else:
deck = self.all_permutations[:]
new_deck = []
trace = {}
progress = progressbar.ProgressBar(
widgets=["Simulating games: ",
progressbar.Bar(marker="*"),
" ", progressbar.ETA()])
for i in progress(range(length)):
falses = 0
trues = 0
nones = 0
for deal in deck:
f_list = []
for obs in self.observations:
for tid in obs:
f_list.append(tid)
is_bad = False
dont_copy = False
for f in f_list:
out = f(deal)
if out is None:
is_bad = True
dont_copy = True
nones += 1
break
if out is True:
trues += 1
continue
if out is False:
is_bad = True
falses += 1
break
if not is_bad:
if deal not in trace:
trace[deal] = 1
trace[deal] += 1
if not dont_copy:
new_deck.append(deal)
deck = new_deck
new_deck = []
f_list = []
for obs in self.observations:
for tid in obs:
f_list.append(tid)
total_score = 0.0
for deal in progress(deck):
this_score = 1.0
for f in f_list:
score = f(deal)
if score is None:
this_score = 0.0
break
this_score = this_score * score
total_score += this_score
trace[deal] = this_score
self.trace = trace
self.trace_score = total_score
def report(self):
return self.get_player_data()
@ -251,24 +234,22 @@ class DeceptionGame(object):
out.append({})
out[i]["role"] = dd(float)
out[i]["side"] = dd(float)
size = sum(self.trace.values()) * 1.0
top_k = [(0.0, None)] * 5
for deal, score in self.trace.items():
weighted_score = score / self.trace_score
for i, card in enumerate(deal):
role, side = card
out[i]["role"][role] += (score * 1.0) / size
out[i]["side"][side] += (score * 1.0) / size
out[i]["role"][role] += weighted_score
out[i]["side"][side] += weighted_score
if weighted_score > top_k[-1][0]:
top_k.append((weighted_score, deal))
top_k = sorted(top_k, reverse=True)[:-1]
for i in range(self.n_players):
out[i]["role"] = dict(out[i]["role"])
out[i]["side"] = dict(out[i]["side"])
return out
def _aggregate(self, l, i):
out = dd(float)
size = len(l) * 1.0
for deal in l:
out[deal[i]] += 1 / size
return dict(out)
return out, top_k
def __str__(self):
return "%d Player Game (%d constraints)" % (self.n_players,