Commit 49f5a035 authored by sqozz's avatar sqozz
Browse files

Add more metrics

parent 395f5eca
...@@ -11,7 +11,7 @@ import time ...@@ -11,7 +11,7 @@ import time
MESSAGES = { "GameInfo" : 0x00, MESSAGES = { "GameInfo" : 0x00,
"WorldUpdate" : 0x01, "WorldUpdate" : 0x01,
"BotSpawn" : 0x20, "BotSpawn" : 0x20,
"BotKill" : 0x21, "BotKill" : 0x21,
"BotMove" : 0x22, "BotMove" : 0x22,
"BotStats" : 0x24 "BotStats" : 0x24
} }
...@@ -110,13 +110,13 @@ class Game(): ...@@ -110,13 +110,13 @@ class Game():
victim = self.users.get_user_by_worm(js.get("victim_id")) victim = self.users.get_user_by_worm(js.get("victim_id"))
killer = self.users.get_user_by_worm(js.get("killer_id")) killer = self.users.get_user_by_worm(js.get("killer_id"))
if js.get("killer_id") == js.get("victim_id"): if js.get("killer_id") == js.get("victim_id"):
print("☕ {} killed himself".format(victim.name)) #print("☕ {} killed himself".format(victim.name))
pass pass
else: else:
#print("☠ {} fragged {}".format(killer.name, victim.name)) #print("☠ {} fragged {}".format(killer.name, victim.name))
pass pass
#killer.kills += 1 killer.kills += 1
#victim.deaths += 1 victim.deaths += 1
except AttributeError as e: except AttributeError as e:
print(e) print(e)
print("Error in kill: {}".format(js)) print("Error in kill: {}".format(js))
...@@ -124,9 +124,9 @@ class Game(): ...@@ -124,9 +124,9 @@ class Game():
elif typ == MESSAGES["BotStats"]: elif typ == MESSAGES["BotStats"]:
msg_data = js.get("data") msg_data = js.get("data")
for worm in msg_data: for worm in msg_data:
user = self.users.get_user_by_worm(worm) user = self.users.get_user_by_worm(int(worm))
if user != None: if user != None:
print("updating {}".format(user.name)) user.update({ "id" : int(worm), "data" : msg_data.get(worm)})
pass pass
elif typ == MESSAGES["WorldUpdate"]: elif typ == MESSAGES["WorldUpdate"]:
bots = js.get("bots") bots = js.get("bots")
...@@ -178,6 +178,13 @@ class BotUser(): ...@@ -178,6 +178,13 @@ class BotUser():
def update(self, data): def update(self, data):
rev_id = data.get("db_id") rev_id = data.get("db_id")
worm_id = data.get("id") #TODO: does this work? worm_id = data.get("id") #TODO: does this work?
if "data" in data.keys():
user = game.users.get_user_by_worm(worm_id)
current_rev = user.revs.get(user.current_rev)
current_rev.carrion_food_consumed = data.get("data").get("c")
current_rev.natural_food_consumed = data.get("data").get("n")
current_rev.hunted_food_consumed = data.get("data").get("h")
pdb.set_trace()
if rev_id in self.revs.keys(): # revision already known if rev_id in self.revs.keys(): # revision already known
rev = self.revs.get(rev_id) rev = self.revs.get(rev_id)
rev.update(data) rev.update(data)
...@@ -195,6 +202,7 @@ class BotRevision(): ...@@ -195,6 +202,7 @@ class BotRevision():
self.worms.update({self.current_worm : [self.rev_id]}) self.worms.update({self.current_worm : [self.rev_id]})
self.deaths = 0 self.deaths = 0
self.kills = 0 self.kills = 0
self.mass = 0
self.natural_food_consumed = 0 self.natural_food_consumed = 0
self.carrion_food_consumed = 0 self.carrion_food_consumed = 0
self.hunted_food_consumed = 0 self.hunted_food_consumed = 0
...@@ -204,8 +212,11 @@ class BotRevision(): ...@@ -204,8 +212,11 @@ class BotRevision():
pass pass
def update(self, data): def update(self, data):
if "food" in data.keys():
pdb.set_trace()
self.current_worm = data.get("id") self.current_worm = data.get("id")
self.rev_id = data.get("db_id") self.rev_id = data.get("db_id")
self.mass = data.get("mass")
self.worms.update({self.current_worm : [self.rev_id]}) self.worms.update({self.current_worm : [self.rev_id]})
pass pass
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment