Re: Bridge anyone? [not off topic]
Re: Bridge anyone? [not off topic]
- Subject: Re: Bridge anyone? [not off topic]
- From: Bernard Bernu <email@hidden>
- Date: Thu, 4 Nov 2004 09:37:20 +0100
I thing this is a correct version, but probably not the fastest, but the hands keep sorted. ;-)
script Bridge
property cards : {"AS", "KS", "QS", "JS", "10S", "9S", "8S", "7S", "6S", "5S", "4S", "3S", "2S", ¬
"AH", "KH", "QH", "JH", "10H", "9H", "8H", "7H", "6H", "5H", "4H", "3H", "2H", ¬
"AD", "KD", "QD", "JD", "10D", "9D", "8D", "7D", "6D", "5D", "4D", "3D", "2D", ¬
"AC", "KC", "QC", "JC", "10C", "9C", "8C", "7C", "6C", "5C", "4C", "3C", "2C"}
property new_hands : {}
property players : {1, 2, 3, 4}
property onehand : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}
on deal()
set new_hands to {{}, {}, {}, {}}
set i to 1
set c to item i of cards
repeat
set player to (contents of some item of players)
set currhand to item player of new_hands
if (count currhand) is 13 then
(* if a hand is complete, add the new card at the end and remove one at random, but don't do the contrary
*)
set k to (some integer of onehand)
-- if k=14 do nothing
if k < 14 then -- all that can be certainly optimized : doing a replace is faster but looses the order
set cnew to item k of currhand
if k is 13 then --
set item 13 of currhand to c
else if k is 1 then
set currhand to (items 2 thru 13 of currhand) & c
else
set currhand to (items 1 thru (k - 1) of currhand) & (items (k + 1) thru 13 of currhand) & c
end if
set c to cnew
end if
else
set end of currhand to c
if i is 52 then exit repeat
set i to i + 1
set c to item i of cards
end if
end repeat
end deal
end script
chrono
repeat 100 times
tell Bridge to deal()
end repeat
chrono
--new_hands of Bridge
Le 3 nov. 04, à 18:28, Emmanuel a écrit :
At 12:11 PM -0500 02/11/04, Graff wrote:
Of the scripts I've seen so far, Bernard's is not only the fastest, but
it supplies each player's cards ready sorted! I still haven't worked out
how it works, though. :-)
Interesting, but I'm not sure if it compromises the randomness of the hands or not
Ken is right to ask. Bernard's algorithm is fast but it does not provide random hands.
For instance the probability that the owner of the 2 of clubs also own the 3 of clubs is obviously much larger than 1/4.
For example on my first test the 2, 3, 4 and 5 of clubs were in the same hand.
Emmanuel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
Bernard Bernu
Physique Théorique des Liquides
4, place Jussieu, T24, 2ème
Boîte 121
75252 Paris Cedex 05, France
Tel : (33) 01 44 27 72 38 Fax : (33) 01 44 27 51 00
http://www.lptl.jussieu.fr/users/bernu
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden