berak/ants-tcp — Issue #4: Highlight player code
Author: romans01
Created: 2011-11-12 12:57:50+00:00
State: open

tcpserver.py

See line with "pdata". Let's save player rank and player skill during the time of the game.

# save to db
db = game_db.GameDB()
data = json.dumps(game_result)
db.add_replay( self.id, data )

plr = {}
for i,p in enumerate(self.players):
pdata = db.get_player((p,))
plr[p] = (scores[i], states[i], pdata[0][4], pdata[0][5])
db.update("insert into gameindex values(?,?,?)",(None,p,self.id))
db.add_game( self.id, self.map_name, self.ants.turn, draws,json.dumps(plr) )

webserver.py: See game_line function.

def mapPlayerData(self,name,values):
return {
'name':name,
'status':str(values[1]),
'score':str(values[0]),
'rank':str(values[2]),
'skill':str(round(values[3],2))
}

def game_line(self, g, player):
html = "
Replay " + str(g[0]) + "	"
for key, value in sorted(json.loads(g[1]).iteritems(), key=lambda (k,v): (v,k), reverse=True):
pd = self.mapPlayerData(key,value)
if str(key)==player:
html += " "+pd['name']+" (" + pd['score']+ ", "+pd['status']+", "+pd['rank']+" / "+pd['skill']+" ) "
else:
html += " "+pd['name']+" (" + pd['score']+ ", "+pd['status']+", "+pd['rank']+" / "+pd['skill']+" ) "
html += "	" + str(g[4]) + ""
html += "	" + str(g[2]) + ""
html += "	" + str(g[3]) + ""
html += "
\n"
return html

Results you can see on http://tcpant.com