Re: Bridge anyone? [not off topic]
Re: Bridge anyone? [not off topic]
- Subject: Re: Bridge anyone? [not off topic]
- From: Nigel Garvey <email@hidden>
- Date: Fri, 5 Nov 2004 12:20:39 +0000
John Baltutis wrote on Thu, 4 Nov 2004 16:36:04 -0800:
>> Unfortunately,
>> even if this is in average very few operations, it needs really more
>coding
>> and it takes at the end a longer time and it looses the ordering of the
>> hands. So forget it.
>
>The proper way is to:
>
>1. the dealer, south, shuffles the deck-- randomizing the cards
>2. deal the shuffled cards, one at a time from the shuffled deck, to the
>east, north, west, and south hands, until each has been dealt--preserves
>the random shuffle
>3. sort the four hands into suit order: spades, hearts, diamonds, and clubs.
>
>I'll leave the scripting details to the experts.
One approach might be:
Maintain a list of the integers 1 - 52, the integers representing the
cards in an ordered pack: "AS" (1) -> "2C" (52).
Shuffle the integers rather than the cards, using your own preferred
technique.
Initialise each player's 'hand' to a frame of 52 missing values.
Deal, using each shuffled integer (n) to set slot n of the relevant hand
to card n of an ordered pack.
Set each hand to its own strings or 'every Unicode text' to leave just
the ordered cards.
The integer list can remain unsorted for later deals.
property integerList : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ¬
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, ¬
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, ¬
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52}
on shuffle()
-- Your favourite shuffle algorithm shuffles integerList here.
end shuffle
on deal()
script o
property deck : {"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 hands : {}
end script
set mv to missing value
set frame to {mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, ¬
mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, ¬
mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, ¬
mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv}
repeat 4 times
copy frame to the end of o's hands
end repeat
repeat with c from 1 to 52
set n to item c of my integerList
set item n of item ((c - 1) mod 4 + 1) of o's hands to item n of
o's deck
end repeat
repeat with h from 1 to 4
set item h of o's hands to strings of item h of o's hands
-- or to every Unicode text of item h of o's hands
end repeat
return o's hands
end deal
shuffle()
set {east, north, west, south} to deal()
NG
_______________________________________________
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