]> Pileus Git - ~andy/rhawk/commitdiff
Improve shuffling algorithm
authorAndy Spencer <andy753421@gmail.com>
Fri, 6 Dec 2013 20:14:35 +0000 (20:14 +0000)
committerAndy Spencer <andy753421@gmail.com>
Fri, 6 Dec 2013 20:14:35 +0000 (20:14 +0000)
spades.awk

index 8e7e7ee62df3544677c16af40e8043e3d35f1ecd..b6eff64bd2542b0c06c36d30df79d24ae7a19bd6 100644 (file)
@@ -163,7 +163,7 @@ function sp_next(who, prev)
 
 function sp_shuf(i, mixed)
 {
-       asorti(sp_players, mixed, "sp_usort")
+       sp_usort(sp_players, mixed)
        for (i in mixed) {
                sp_order[i-1] = mixed[i]
                sp_players[mixed[i]] = i-1
@@ -173,7 +173,7 @@ function sp_shuf(i, mixed)
 function sp_deal(      shuf)
 {
        say("/me deals the cards")
-       asorti(sp_deck, shuf, "sp_usort")
+       sp_usort(sp_deck, shuf)
        for (i=1; i<=52; i++)
                sp_hands[sp_order[i%4]][shuf[i]] = 1
        sp_state  = "bid"
@@ -206,8 +206,10 @@ function sp_type(card)
        return substr(card, length(card))
 }
 
-function sp_usort(a,b,c,d) {
-       return rand() - 0.5
+function sp_usort(list, out) {
+       for (i in list)
+               out[i] = rand()
+       asorti(out, out, "@val_num_asc")
 }
 
 function sp_csort(i1,v1,i2,v2) {