Re: Bridge anyone? [not off topic]
Re: Bridge anyone? [not off topic]
- Subject: Re: Bridge anyone? [not off topic]
- From: Graff <email@hidden>
- Date: Mon, 01 Nov 2004 21:51:32 -0500
See if this is any faster:
----
set sortedDeck to {"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"}
on shuffle(theSet)
copy theSet to newSet
set maxSize to count of theSet
repeat with i from 1 to maxSize
set j to random number from i to maxSize
if (j > i) then
set temp to item j of newSet
set (item j of newSet) to (item i of newSet)
set (item i of newSet) to temp
end if
end repeat
return newSet
end shuffle
set shuffledDeck to shuffle(sortedDeck)
set north to items 1 thru 13 of shuffledDeck
set east to items 14 thru 26 of shuffledDeck
set south to items 27 thru 39 of shuffledDeck
set west to items 40 thru 52 of shuffledDeck
----
This might be able to be sped up using references, but I don't have a
lot of practice at using them so I didn't bother.
On my machine 10000 shuffles took my algorithm 37 seconds and took
yours 75 seconds.
- Ken
On Nov 1, 2004, at 4:16 PM, Michelle Steiner wrote:
Any way to increase the efficiency of this script that deals out a
bridge (or spades, or hearts, etc.) hand?
set the pack to {}
set the terminator to {}
set the cards to {"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"}
set the hand to {{}, {}, {}, {}}
repeat with i from 1 to 52
copy i to the end of the pack
copy 0 to the end of the terminator
end repeat
repeat until the pack is the terminator
repeat with i from 1 to 4
repeat until (count of item i of the hand) is 13
set the card to some item of the pack
if the card is not 0 then
set item card of the pack to 0
tell the hand to copy (item card of the cards) to the end of item
i of the hand
end if
end repeat
end repeat
end repeat
set north to item 1 of the hand
set east to item 2 of the hand
set south to item 3 of the hand
set west to item 4 of the hand
_______________________________________________
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