Browse Source

better stats (needs testing)

master
Jimmy Cao 13 years ago
parent
commit
a7e8ad3831
  1. 28
      var.py
  2. 12
      wolfgame.py

28
var.py

@ -185,18 +185,13 @@ with conn: @@ -185,18 +185,13 @@ with conn:
c.execute("INSERT OR REPLACE INTO roles (role) VALUES (?)", (x,))
c.execute(('CREATE TABLE IF NOT EXISTS rolestats (playerid INTEGER, roleid INTEGER, '+
c.execute(('CREATE TABLE IF NOT EXISTS rolestats (player TEXT, roleid INTEGER, '+
'teamwins SMALLINT, individualwins SMALLINT, totalgames SMALLINT, '+
'UNIQUE(playerid, roleid))'))
'UNIQUE(player, roleid))'))
# create the players table
c.execute("CREATE TABLE IF NOT EXISTS players (id INTEGER PRIMARY KEY AUTOINCREMENT, nick TEXT, cloak TEXT, "+
"UNIQUE(nick, cloak))")
# create nick change table
c.execute("CREATE TABLE IF NOT EXISTS nick_changes (old INTEGER, new INTEGER, UNIQUE(new))")
@ -209,30 +204,17 @@ def add_away(clk): @@ -209,30 +204,17 @@ def add_away(clk):
c.execute('INSERT into away VALUES (?)', (clk,))
def add_player_record(nick, cloak):
with conn:
c.execute('INSERT OR IGNORE INTO players (nick, cloak) VALUES (?,?)', (nick, cloak))
def update_role_stats(nick, clk, role, won, iwon):
def update_role_stats(acc, role, won, iwon):
with conn:
wins, iwins, totalgames = 0, 0, 0
c.execute('SELECT id FROM players WHERE nick=? AND cloak=?', (nick, clk))
row = c.fetchone()
if row:
plid = row[0]
else:
c.execute('INSERT INTO players (nick, cloak) VALUES (?,?)', (nick, clk))
c.execute('SELECT id FROM players WHERE nick=? AND cloak=?', (nick, clk))
plid = c.fetchone()[0]
c.execute('SELECT id FROM roles WHERE role=?', (role,))
rid = c.fetchone()[0]
c.execute(("SELECT teamwins, individualwins, totalgames FROM rolestats "+
"WHERE playerid=? AND roleid=?"), (plid, rid))
"WHERE player=? AND roleid=?"), (acc, rid))
row = c.fetchone()
if row:
wins, iwins, total = row
@ -246,7 +228,7 @@ def update_role_stats(nick, clk, role, won, iwon): @@ -246,7 +228,7 @@ def update_role_stats(nick, clk, role, won, iwon):
total += 1
c.execute("INSERT OR REPLACE INTO rolestats VALUES (?,?,?,?,?)",
(plid, rid, wins, iwins, total))
(acc, rid, wins, iwins, total))

12
wolfgame.py

@ -332,8 +332,6 @@ def join(cli, nick, chan, rest): @@ -332,8 +332,6 @@ def join(cli, nick, chan, rest):
nick, _, __, cloak = parse_nick(nick)
if var.PHASE == "none":
if cloak:
var.add_player_record(nick, cloak)
cli.mode(chan, "+v", nick, nick+"!*@*")
var.ROLES["person"].append(nick)
@ -351,8 +349,6 @@ def join(cli, nick, chan, rest): @@ -351,8 +349,6 @@ def join(cli, nick, chan, rest):
elif var.PHASE != "join":
cli.notice(nick, "Sorry but the game is already running. Try again next time.")
else:
if cloak:
var.add_player_record(nick, cloak)
cli.mode(chan, "+v", nick, nick+"!*@*")
var.ROLES["person"].append(nick)
@ -710,12 +706,14 @@ def stop_game(cli, winner = ""): @@ -710,12 +706,14 @@ def stop_game(cli, winner = ""):
for plr, rol in plrl:
if plr not in var.USERS.keys(): # he died TODO: when a player leaves, count the game as lost for him
if plr in var.DEAD_USERS.keys():
clk = var.DEAD_USERS[plr]
acc = var.DEAD_USERS[plr]["account"]
else:
continue # something wrong happened
else:
clk = var.USERS[plr]["cloak"]
acc = var.USERS[plr]["account"]
if acc == "*":
continue # not logged in
# determine if this player's team won
if plr in (var.ORIGINAL_ROLES["wolf"] + var.ORIGINAL_ROLES["traitor"] +
var.ORIGINAL_ROLES["werecrow"]): # the player was wolf-aligned
@ -735,7 +733,7 @@ def stop_game(cli, winner = ""): @@ -735,7 +733,7 @@ def stop_game(cli, winner = ""):
iwon = won and plr in var.list_players() # survived, team won = individual win
var.update_role_stats(plr, clk, rol, won, iwon)
var.update_role_stats(acc, rol, won, iwon)
reset(cli)

Loading…
Cancel
Save