X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=spades.awk;h=1686806fc031cd0ee7996576147587845f5bb039;hb=069896bc3c2f2c21a7bb7b02650d8819766a41d4;hp=db4429e4d0fc886790ae0a2bec48badf75be25b3;hpb=353acd00953947070574442fa8464a53710b8935;p=~andy%2Frhawk diff --git a/spades.awk b/spades.awk index db4429e..1686806 100644 --- a/spades.awk +++ b/spades.awk @@ -161,6 +161,15 @@ function sp_next(who, prev) return prev } +function sp_shuf(i, mixed) +{ + asorti(sp_players, mixed, "sp_usort") + for (i in mixed) { + sp_order[i-1] = mixed[i] + sp_players[mixed[i]] = i-1 + } +} + function sp_deal( shuf) { say("/me deals the cards") @@ -230,19 +239,19 @@ function sp_bags(i, bags) return bags } +function sp_bid(who) +{ + return sp_nil[who] == 0 ? sp_bids[who] : + sp_nil[who] == 1 ? "nil" : + sp_nil[who] == 2 ? "blind" : "n/a" +} + function sp_bidders( i, turn, bid, bids) { for (i = 0; i < 4; i++) { turn = (sp_dealer + i) % 4 - if (sp_bids[turn] && !sp_nil[turn]) - bid = sp_order[turn] ":" sp_bids[turn] - else if (sp_nil[turn] == 1) - bid = sp_order[turn] ":" "nil" - else if (sp_nil[turn] == 2) - bid = sp_order[turn] ":" "blind" - else - continue - bids = bids " " bid + if (bid = sp_bid(turn)) + bids = bids " " sp_order[turn] ":" bid } gsub(/^ +| +$/, "", bids) return bids @@ -470,8 +479,10 @@ sp_state == "play" && sp_order[i] = FROM say(FROM " joins the game!") } - if (sp_state == "join" && sp_turn == 0) + if (sp_state == "join" && sp_turn == 0) { + sp_shuf() sp_deal() + } } /^\.allow \S+$/ { @@ -673,19 +684,19 @@ sp_state == "play" && } /^\.bids$/ && sp_state ~ "(pass|play)" { - say(sp_order[0] " bid " sp_bids[0] ", " \ - sp_order[2] " bid " sp_bids[2] ", " \ + say(sp_order[0] " bid " sp_bid(0) ", " \ + sp_order[2] " bid " sp_bid(2) ", " \ "total: " sp_bids[0] + sp_bids[2]) - say(sp_order[1] " bid " sp_bids[1] ", " \ - sp_order[3] " bid " sp_bids[3] ", " \ + say(sp_order[1] " bid " sp_bid(1) ", " \ + sp_order[3] " bid " sp_bid(3) ", " \ "total: " sp_bids[1] + sp_bids[3]) } /^\.tricks$/ && sp_state == "play" { - say(sp_order[0] " took " int(sp_tricks[0]) "/" int(sp_bids[0]) ", " \ - sp_order[2] " took " int(sp_tricks[2]) "/" int(sp_bids[2])) - say(sp_order[1] " took " int(sp_tricks[1]) "/" int(sp_bids[1]) ", " \ - sp_order[3] " took " int(sp_tricks[3]) "/" int(sp_bids[3])) + say(sp_order[0] " took " int(sp_tricks[0]) "/" sp_bid(0) ", " \ + sp_order[2] " took " int(sp_tricks[2]) "/" sp_bid(2)) + say(sp_order[1] " took " int(sp_tricks[1]) "/" sp_bid(1) ", " \ + sp_order[3] " took " int(sp_tricks[3]) "/" sp_bid(3)) } (TO == NICK || DST == sp_channel) && @@ -716,18 +727,3 @@ sp_state == "play" && /^\.((new|end|load)game|join|look|bid|pass|play)/ { sp_save("var/sp_cur.json"); } - -# Standin -#/^\.playfor [^ ]*$/ { -#} -# -#/^\.standin [^ ]*$/ { -# if (p in sp_players) { -# } -# for (p in sp_standin) { -# if ($2 in sp_standin) -# say(here " is already playing for " sp_standin[p]); -# } -# sp_standin[away] = here -#} -#