X-Git-Url: http://pileus.org/git/?p=~andy%2Frhawk;a=blobdiff_plain;f=spades.awk;h=740d1b8e347003b11fc6acf764fe22719521374f;hp=a377ed5c415b6e6a6ac9a1e5c351e580e8f8b249;hb=HEAD;hpb=8b3b0b2b7b0127174db88e2a72076adc63d34247 diff --git a/spades.awk b/spades.awk index a377ed5..740d1b8 100644 --- a/spades.awk +++ b/spades.awk @@ -164,7 +164,7 @@ function sp_say(msg) { say(sp_channel, msg) print msg |& sp_sock - print strftime("%Y-%m-%d %H:%M:%S | ") msg >> "logs/" sp_log + print strftime("%Y-%m-%d %H:%M:%S | ") sp_ugly(msg) >> "logs/" sp_log fflush("logs/" sp_log) } @@ -183,6 +183,16 @@ function sp_pretty(cards, who) return cards } +function sp_ugly(cards, who) +{ + gsub(/[\2\17]|\3[14],00|/, "", cards) + gsub(/♠/, "s", cards) + gsub(/♥/, "h", cards) + gsub(/♦/, "d", cards) + gsub(/♣/, "c", cards) + return cards +} + function sp_next(who, prev) { prev = sp_turn @@ -379,8 +389,8 @@ function sp_play(card, winner, pi) sp_tricks[2] + sp_tricks[3] == 13) { sp_say("Round over!") sp_score() - if (sp_scores[0] >= sp_playto || sp_scores[1] >= sp_playto && - sp_scores[0] != sp_scores[1]) { + if ((sp_scores[0] >= sp_playto || sp_scores[1] >= sp_playto) && + (sp_scores[0] != sp_scores[1])) { sp_say("Game over!") winner = sp_scores[0] > sp_scores[1] ? 0 : 1 looser = !winner @@ -393,7 +403,7 @@ function sp_play(card, winner, pi) } else { if (sp_scores[0] == sp_scores[1] && sp_scores[0] >= sp_playto) - sp_say("It's tie! Playing an extra round!"); + sp_say("It's a tie! Playing an extra round!"); sp_reset(1) sp_deal() } @@ -529,7 +539,7 @@ AUTH == OWNER && } /^\.help game$/ { - say(".newgame [score] -- start a game to points, default 500") + say(".newgame [score] -- start a game to points, default 300") say(".endgame -- abort the current game") say(".savegame -- save the current game to disk") say(".loadgame -- load the previously saved game") @@ -600,7 +610,7 @@ match($0, /^\.newgame ?([1-9][0-9]*) *- *([1-9][0-9]*)$/, _arr) { } else { $1 = ".join" sp_owner = FROM - sp_playto = $2 ? $2 : 200 + sp_playto = $2 ? $2 : 300 sp_limit = sp_playto > 200 ? 10 : 5; sp_state = "join" sp_channel = DST @@ -609,14 +619,27 @@ match($0, /^\.newgame ?([1-9][0-9]*) *- *([1-9][0-9]*)$/, _arr) { } } -(sp_from == sp_owner || AUTH == OWNER) && -/^\.endgame$/ { +/^\.(endgame|fliptable)$/ { if (sp_state == "new") { reply("There is no game in progress.") - } else { + } + else if (!(sp_from in sp_players)) { + reply("You are not playing") + } + else if (sp_state == "join") { sp_say(FROM " ends the game") sp_reset(2) } + else { + _looser = (sp_players[sp_from]+0) % 2; + _winner = (sp_players[sp_from]+1) % 2; + sp_say(FROM " goes on a rampage") + say(CHANNEL, sp_team(_winner) " wins the game " \ + sp_scores[_winner] " to " sp_scores[_looser]) + say(CHANNEL, sp_order[_winner+0] "++") + say(CHANNEL, sp_order[_winner+2] "++") + sp_reset(2) + } } /^\.join/ { @@ -638,6 +661,8 @@ match($0, /^\.newgame ?([1-9][0-9]*) *- *([1-9][0-9]*)$/, _arr) { sp_say(FROM " joins the game!") } if (sp_state == "join" && sp_turn == 0) { + sp_scores[0] = 0 + sp_scores[1] = 0 sp_shuf() sp_deal() } @@ -997,6 +1022,6 @@ sp_state == "play" && sp_stats("logs/" $2 ".log"); } -/^\.((new|end|load)game|join|look|bid|pass|play|allow|deny|team|notify)/ { +/^\.((new|end|load)game|fliptable|join|look|bid|pass|play|allow|deny|team|notify)/ { sp_save("var/sp_cur.json"); }