Re: Bridge anyone? [not off topic]
Re: Bridge anyone? [not off topic]
- Subject: Re: Bridge anyone? [not off topic]
- From: kai <email@hidden>
- Date: Tue, 2 Nov 2004 00:25:53 +0000
On Mon, 1 Nov 2004 14:16:57 -0700, 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
This variation manages a speed bump of roughly 50% OMM, Michelle:
------------------
script getFullDeck
set text item delimiters to return
set d 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"} as string
set text item delimiters to {""}
d
end script
property fullDeck : run getFullDeck
on everyCard from currDeck apart from currCard
set text item delimiters to return & currCard & return
set d to (return & currDeck & return)'s text items
set text item delimiters to return
(d as string)'s text 2 thru -2
end everyCard
copy fullDeck to currDeck
set dealtCards to {}
repeat 51 times
tell some paragraph of currDeck
set end of dealtCards to it
set currDeck to my (everyCard from currDeck apart from it)
end tell
end repeat
set text item delimiters to {""}
tell dealtCards & currDeck
set north to items 1 thru 13
set east to items 14 thru 26
set south to items 27 thru 39
set west to items 40 thru 52
end tell
------------------
If NG's around, he'll probably wipe the floor with us both anyway... ;-)
---
kai
_______________________________________________
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