]> Pileus Git - ~andy/rhawk/blobdiff - spades.awk
Update select extension
[~andy/rhawk] / spades.awk
index 8feb8ea96838bd92ffd849026b1b3594978f940d..5e3be7d9a031f097184065b1cfbc98c000b22ae2 100644 (file)
@@ -33,6 +33,7 @@ function sp_reset(type)
        if (type >= 1) {
                sp_state    = "bid" #     {new,join,bid,pass,play}
                sp_broken   = 0     #     Whether spades are broken
+               delete sp_hands     # [p] Each players cards
                delete sp_looked    # [i] Whether a player has looked a their cards
                delete sp_bids      # [i] Each players bid
                delete sp_nil       # [i] Nil multiplier 0=regular, 1=nil, 2=blind
@@ -50,7 +51,6 @@ function sp_reset(type)
                sp_turn     = 0     #     Index of who's turn it is
                sp_player   = ""    #     Who's turn it is
                sp_limit    = 10    #     Bag out limit / nil bonus
-               delete sp_hands     # [p] Each players cards
                delete sp_players   # [p] Player names players["name"] -> i
                delete sp_auths     # [c] Player auth names auths["auth"] -> "name"
                delete sp_share     # [c] Player teammates share["friend"] -> "name"
@@ -61,9 +61,11 @@ function sp_reset(type)
 
 function sp_acopy(dst, src,    key)
 {
-       if (isarray(src))
+       if (isarray(src)) {
+               delete(dst)
                for (key in src)
                        json_copy(dst, key, src[key])
+       }
 }
 
 function sp_save(file, game)
@@ -296,6 +298,12 @@ function sp_score( bids, times, tricks)
                sp_scores[i%2] += sp_limit * 10 * sp_nil[i] * \
                        (sp_tricks[i] == 0 ? 1 : -1)
        }
+       if (sp_scores[0] > sp_scores[1])
+               say(sp_team(0) " lead " sp_scores[0] " to " sp_scores[1] " of " sp_playto)
+       else if (sp_scores[1] > sp_scores[0])
+               say(sp_team(1) " lead " sp_scores[1] " to " sp_scores[0] " of " sp_playto)
+       else
+               say("tied at " sp_scores[0])
 }
 
 function sp_play(card, winner, pi)
@@ -453,12 +461,12 @@ sp_state == "play" &&
 
 
 # Setup
-match($0, /^\.newgame ?([0-9]+) *- *([0-9]+)$/, _arr) {
+match($0, /^\.newgame ?([1-9][0-9]*) *- *([1-9][0-9]*)$/, _arr) {
        if (_arr[2] > _arr[1])
                $0 = $1 " " int(rand() * (_arr[2]-_arr[1])+_arr[1])
 }
 
-/^\.newgame ?([0-9]+)?$/ {
+/^\.newgame ?([1-9][0-9]*)?$/ {
        if (sp_state != "new") {
                reply("There is already a game in progress.")
        } else {
@@ -571,7 +579,7 @@ sp_state ~ "(bid|pass|play)" &&
 
 sp_valid &&
 sp_state == "bid" &&
-/^\.bid [0-9]+$/ {
+/^\.bid [1-9][0-9]*$/ {
        if ($2 < 0 || $2 > 13) {
                say("You can only bid from 0 to 13")
        } else {
@@ -693,16 +701,23 @@ sp_state == "play" &&
 
 /^\.bids/ && sp_state == "bid" ||
 /^\.turn/ && sp_state ~ "(bid|pass|play)" {
-       _bids = sp_bidders()
-       _pile = sp_pretty(sp_piles, FROM)
+       _bids  = sp_bidders()
+       _pile  = sp_pretty(sp_piles, FROM)
+       _extra = ""
+
+       for (_i in sp_share)
+               if (/!/ && sp_share[_i] == sp_player)
+                       _extra = _extra " " _i "!"
+
        if (sp_state == "bid" && !_bids)
-               say("It is " sp_player "'s bid!")
+               say("It is " sp_player "'s bid!" _extra)
        if (sp_state == "bid" && _bids)
-               say("It is " sp_player "'s bid! (" _bids ")")
+               say("It is " sp_player "'s bid!" _extra " (" _bids ")")
        if (sp_state == "play" && !_pile)
-               say("It is " sp_player "'s turn!")
+               say("It is " sp_player "'s turn!" _extra)
        if (sp_state == "play" && _pile)
-               say("It is " sp_player "'s turn! (" _pile ")")
+               say("It is " sp_player "'s turn!" _extra " (" _pile ")")
+
        for (_i=0; sp_state == "pass" && _i<4; _i++)
                if (sp_passer(_i) && !sp_pass[_i])
                        say("Waiting for " sp_order[_i] " to pass a card!")