newtim
This commit is contained in:
parent
a8564ccb0c
commit
2a533c1f73
1 changed files with 31 additions and 27 deletions
58
newtim.py
58
newtim.py
|
|
@ -158,11 +158,11 @@ class DeceptionGame(object):
|
||||||
self.tid += 1
|
self.tid += 1
|
||||||
|
|
||||||
|
|
||||||
def eval(self, length=100):
|
def eval(self, length=10):
|
||||||
deck = self.all_permutations[:]
|
deck = self.all_permutations[:]
|
||||||
new_deck = []
|
new_deck = []
|
||||||
trace = []
|
trace = []
|
||||||
progress = progressbar.ProgressBar(widgets=[": ", progressbar.Bar(marker=progressbar.RotatingMarker()), " ", progressbar.ETA()])
|
progress = progressbar.ProgressBar(widgets=["Simulating games: ", progressbar.Bar(marker="*"), " ", progressbar.ETA()])
|
||||||
for i in progress(range(length)):
|
for i in progress(range(length)):
|
||||||
for deal in deck:
|
for deal in deck:
|
||||||
f_list = []
|
f_list = []
|
||||||
|
|
@ -195,23 +195,25 @@ class DeceptionGame(object):
|
||||||
def report(self):
|
def report(self):
|
||||||
if self.trace is None:
|
if self.trace is None:
|
||||||
self.eval()
|
self.eval()
|
||||||
|
return self.get_player_data()
|
||||||
|
|
||||||
|
def get_player_data(self):
|
||||||
out = []
|
out = []
|
||||||
for i in range(self.n_players):
|
for i in range(self.n_players):
|
||||||
out.append(self.get_player_data(i))
|
out.append({})
|
||||||
return out
|
out[i]["role"] = dd(float)
|
||||||
|
out[i]["side"] = dd(float)
|
||||||
|
|
||||||
def get_player_data(self, i):
|
progress = progressbar.ProgressBar(widgets=["Reticulating splines: ", progressbar.Bar(marker="*"), " ", progressbar.ETA()])
|
||||||
out = {}
|
size = len(self.trace) * 1.0
|
||||||
out["role"] = dd(float)
|
for deal in progress(self.trace):
|
||||||
out["side"] = dd(float)
|
for i, card in enumerate(deal):
|
||||||
|
role, side = card
|
||||||
cards = self._aggregate(self.trace, i)
|
out[i]["role"][role] += 1.0 / size
|
||||||
for k, v in cards.iteritems():
|
out[i]["side"][side] += 1.0 / size
|
||||||
role, side = k
|
for i in range(self.n_players):
|
||||||
out["role"][role] += v
|
out[i]["role"] = dict(out[i]["role"])
|
||||||
out["side"][side] += v
|
out[i]["side"] = dict(out[i]["side"])
|
||||||
out["role"] = dict(out["role"])
|
|
||||||
out["side"] = dict(out["side"])
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def _aggregate(self, l, i):
|
def _aggregate(self, l, i):
|
||||||
|
|
@ -227,21 +229,23 @@ class DeceptionGame(object):
|
||||||
pp.pprint(self.report())
|
pp.pprint(self.report())
|
||||||
|
|
||||||
|
|
||||||
base_game = DeceptionGame(ResistanceGame(10))
|
base_game = DeceptionGame(ResistanceGame(5))
|
||||||
#base_game.add_known_role(0, "G1")
|
#base_game.add_known_role(0, "G1")
|
||||||
#base_game.add_known_alliance(1, False)
|
#base_game.add_known_alliance(1, False)
|
||||||
base_game.player_sees_player_and_claims(0, 1, False)
|
#base_game.player_sees_player_and_claims(0, 1, True)
|
||||||
#base_game.do_vote([1,2], [0,1,1,0,1], 1)
|
#base_game.player_sees_player_and_claims(1, 2, False)
|
||||||
#base_game.do_mission([1,2], 0, False, 1)
|
#base_game.player_sees_player_and_claims(2, 3, False)
|
||||||
#base_game.do_vote([0, 1, 2], [1,1,1,0,1], 2)
|
base_game.do_vote([1,2], [0,1,1,0,1], 1)
|
||||||
#base_game.do_mission([0, 1, 2], 1, False, 2)
|
base_game.do_mission([1,2], 0, False, 1)
|
||||||
#base_game.do_vote([3, 4], [0,0,1,1,1], 3)
|
base_game.do_vote([0, 1, 2], [1,1,1,0,1], 2)
|
||||||
#base_game.do_mission([3, 4], 0, False, 3)
|
base_game.do_mission([0, 1, 2], 1, False, 2)
|
||||||
#base_game.do_vote([3, 4], [0,0,1,1,1], 4)
|
base_game.do_vote([3, 4], [0,0,1,1,1], 3)
|
||||||
#base_game.do_mission([0, 3, 4], 1, False, 4)
|
base_game.do_mission([3, 4], 0, False, 3)
|
||||||
|
base_game.do_vote([3, 4], [0,0,1,1,1], 4)
|
||||||
|
base_game.do_mission([0, 3, 4], 1, False, 4)
|
||||||
#base_game.do_vote([1, 3, 4], [0,1,1,0,1], 5)
|
#base_game.do_vote([1, 3, 4], [0,1,1,0,1], 5)
|
||||||
#base_game.do_mission([1, 3, 4], 1, True, 5)
|
#base_game.do_mission([1, 3, 4], 1, True, 5)
|
||||||
base_game.eval()
|
base_game.eval(100)
|
||||||
|
|
||||||
base_game.print_report()
|
base_game.print_report()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue