From: Andy Spencer Date: Thu, 31 Oct 2013 04:29:24 +0000 (+0000) Subject: Add player shuffling X-Git-Url: http://pileus.org/git/?p=~andy%2Frhawk;a=commitdiff_plain;h=069896bc3c2f2c21a7bb7b02650d8819766a41d4 Add player shuffling --- diff --git a/spades.awk b/spades.awk index 41d2ab8..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") @@ -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+$/ { diff --git a/test.txt b/test.txt index 9ba0ddf..801460d 100644 --- a/test.txt +++ b/test.txt @@ -42,12 +42,18 @@ # | | |- Is not playing for # | | |- Can no longer play # | | |- Is not playing for -auth/auth: . . . . . . . -As -nope: . . Yauth Nauth . . . . -a/aa: n . Ya Na d b1 Yauth +As -b/bb: Ynewgame j Ynope Nnope d b1 . Ah -c/cc: Nnewgame j Yauth Nauth d b1 . Ad -d/dd: . j Yauth Nauth d b1 . Ac +#auth/auth: . . . . . . . -As +#nope: . . Yauth Nauth . . . . +#a/aa: n . Ya Na d b1 Yauth +As +#b/bb: Ynewgame j Ynope Nnope d b1 . Ah +#c/cc: Nnewgame j Yauth Nauth d b1 . Ad +#d/dd: . j Yauth Nauth d b1 . Ac + +# Test sorting +a: n j s +b: . j . +c: . j . +d: . j . # Test scoring #x: s s s s s s s s s s s s