X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=spades.awk;h=08f2776277aebd4cf895d10c44df417e09e91c62;hb=7d09c27cd66a272c71d407e1930f4b8bf327450e;hp=d60507546a26de3e9a57e42a366dcc778ddf7045;hpb=9069cb87481a936b6383b2250fa12a13cf275fe9;p=~andy%2Frhawk diff --git a/spades.awk b/spades.awk index d605075..08f2776 100644 --- a/spades.awk +++ b/spades.awk @@ -383,7 +383,7 @@ function sp_play(card, winner, pi) sp_reset(2) } else { - if (sp_scores[0] == sp_scores[1] && + if (sp_scores[0] == sp_scores[1] && sp_scores[0] >= sp_playto) sp_say("It's tie! Playing an extra round!"); sp_reset(1) @@ -397,7 +397,7 @@ function sp_delay(sec) { return (sec > 60*60*24 ? int(sec/60/60/24) "d " : "") \ (sec > 60*60 ? int(sec/60/60)%24 "h " : "") \ - int(sec/60)%60 "m" + int(sec/60)%60 "m" } function sp_max(list, i, max) @@ -415,7 +415,12 @@ function sp_avg(list, i, sum) return sum / length(list) } -function sp_stats(file, line, arr, time, user, turn, start, delay) +function sp_cur(list) +{ + return list[length(list)-1] +} + +function sp_stats(file, line, arr, time, user, turn, start, delay, extra) { # Process log file while ((stat = getline line < file) > 0) { @@ -435,22 +440,30 @@ function sp_stats(file, line, arr, time, user, turn, start, delay) delay[turn][length(delay[turn])] = time - start turn = 0 } - if (match(arr[2], /^it is your.*$/, arr)) { + if (match(arr[2], /^(it is your|you .*(first|lead)!$)/, arr)) { turn = user start = time - } + } } close(file) + # Add current latency + if (turn) { + delay[turn][length(delay[turn])] = systime() - start + debug("time: " (systime() - start)) + } + # Check for error if (stat < 0) reply("File does not exist: " file); # Output statistics for (user in delay) { + extra = (user != turn) ? "" : \ + ", " sp_delay(sp_cur(delay[user])) " (cur)"; say("latency for " user \ ": " sp_delay(sp_avg(delay[user])) " (avg)" \ - ", " sp_delay(sp_max(delay[user])) " (max)") + ", " sp_delay(sp_max(delay[user])) " (max)" extra) } } @@ -663,6 +676,15 @@ match($0, /^\.newgame ?([1-9][0-9]*) *- *([1-9][0-9]*)$/, _arr) { } } +/^\.whoami/ { + if (!(sp_from in sp_players)) + reply("You are not playing") + else if (sp_from == FROM) + say(FROM " has an existential crisis") + else + reply("You are playing for " sp_from); +} + /^\.notify$/ { if (sp_from in sp_notify) reply("Your address is " sp_notify[sp_from])