• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Bridge anyone? [not off topic]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bridge anyone? [not off topic]


  • Subject: Re: Bridge anyone? [not off topic]
  • From: Tim Mansour <email@hidden>
  • Date: Tue, 2 Nov 2004 14:40:53 +1100

I haven't timed this Michelle, but my two cents worth is a technique I used to use on a HP programmable calculator once upon a time ...

set deck 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 hands to {{}, {}, {}, {}}

repeat with decksize from 52 to 1 by -1
	set r to random number from 1 to decksize
	set h to decksize mod 4 + 1
	set the end of item h of hands to item r of deck
	set item r of deck to item decksize of deck
end repeat

set north to item 1 of hands
set east to item 2 of hands
set south to item 3 of hands
set west to item 4 of hands




Subject: Bridge anyone? [not off topic]


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


--
Tim Mansour <email@hidden>
Mobile 0405 500 846
_______________________________________________
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


  • Follow-Ups:
    • Re: Bridge anyone? [not off topic]
      • From: Graff <email@hidden>
  • Prev by Date: Re: Trouble Getting Into AppleScript
  • Next by Date: Re: Best practices- nested loops or handlers or both
  • Previous by thread: Re: Bridge anyone? [not off topic]
  • Next by thread: Re: Bridge anyone? [not off topic]
  • Index(es):
    • Date
    • Thread