• 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: kai <email@hidden>
  • Date: Tue, 2 Nov 2004 21:39:55 +0000


On Tue, 02 Nov 2004 02:53:31 -0500, Graff wrote:

On Nov 2, 2004, at 2:04 AM, kai wrote:

[snip]

Some nifty shuffling routines there from Ken and Tim - which I've 'borrowed' from here:

[snip: script]

Also not timed...

That speeds things up a bit, 10000 shuffles now take 25 seconds verses 37 for my shuffle.

Even then, I managed to let at least one superfluous assignment slip through, Ken. (The penalty of trying to think when your brain's fried. Shoulda given up and sneaked off to bed much earlier!)


This wouldn't change the timing that much, but I should have written something like:

-----------

script deck
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"}
end script


repeat with n from 1 to 52
	set r to random number from 1 to 52
	set rStore to item r of deck's cards
	set item r of deck's cards to item n of deck's cards
	set item n of deck's cards to rStore
end repeat

set north to items 1 thru 13 of deck's cards
set east to items 14 thru 26 of deck's cards
set south to items 27 thru 39 of deck's cards
set west to items 40 thru 52 of deck's cards

-----------

On Tue, 2 Nov 2004 17:47:17 +0800, Bill <email@hidden> wrote:

May I suggest a unicode version of cards ;)

Cute! (Or, as Martin Orpen reacted: "Yeah, pictures!") :-)

Anyone whose email app displayed the results of Bill's suggestion as gobbledygook might like to check out the html version here:

http://lists.apple.com/archives/applescript-users/2004/Nov/msg00040.html

-----------

On Tue, 2 Nov 2004 16:42:14 +0000, Nigel Garvey wrote:

kai wrote on Tue, 2 Nov 2004 00:25:53 +0000:

This variation manages a speed bump of roughly 50% OMM, Michelle:

[snip]

If NG's around, he'll probably wipe the floor with us both anyway... ;-)

Hi, Kai. Good to be reading your posts again. :-)

Nigel! It's so good to get the chance to drop by again. I've really missed the stimulating company around here! :-)


I saw this coming in the Web archive last night and cobbled something
together to post when the digest arrived today. Since then, of course,
Graff, Tim, and Bernard have posted their scripts and you've posted
another. Mine was essentially the same as your second one, but very much
longer-winded because it used its own random number generator and
actually distributed the cards rather than simply giving each player 13
at a time.

I'd expect nothing less from you than that level of attention to detail, Mr Garvey. ;-)


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. :-)

Took me a while too. I had to 'rephrase' it slightly to get to grips with it:


-----------

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"}

set dealtHands to {{}, {}, {}, {}}
set handNumList to {1, 2, 3, 4}

repeat with currCard in cards

-- initial routine deals sorted cards to randomly chosen hands
set currHandNum to some item of handNumList
set currHand to item currHandNum of dealtHands
set end of currHand to contents of currCard
-- / initial routine

-- this routine simply removes currHandNum from handNumList, once it has 13 cards:
if (count currHand) is 13 then -- don't deal any more cards to this hand
set nextHandNumList to {}
repeat with thisHandNum in handNumList
if contents of thisHandNum is not currHandNum then set end of nextHandNumList to thisHandNum
end repeat
set handNumList to nextHandNumList
end if
-- / routine

end repeat


dealtHands

-----------

On Tue, 02 Nov 2004 12:11:13 -0500, Graff wrote:

It looks like it (the quicker of the two scripts) chooses a random hand
to put a card in, then it puts the top card of the sorted set into that
hand.  If the hand is already full then it removes the hand from the
list of available hands.  Interesting, but I'm not sure if it
compromises the randomness of the hands or not since you are relying on
a random number from 1 to 4 rather than from 1 to 52 and if some hands
get full first then the rest of the hands will tend to have more cards
from a single suit.

Very interesting though.

That was my initial reaction, too, Ken. The cards are always dealt from a sorted deck, but assigned to hands in a random fashion. Then I wondered if it really mattered. On balance though, I find your point about hands completed later containing a 'less random' selection of cards quite persuasive. I wonder what the statisticians around here think of such an approach? (I still need to be convinced...)


Finally (so far), on Tue, 2 Nov 2004 20:48:04 +0000, Nigel came back with:

on NewDeal()
set new_hands to {{}, {}, {}, {}}
set nh to {1, 2, 3, 4}
repeat with c from 1 to 52
set h to (some integer of nh)
set end of item h of my new_hands to item c of my cards
if (count item h of my new_hands) is 13 then set item h of nh to missing value
end repeat
end NewDeal

How cool is that? :-)

Michelle - what kind of a monster have you created here?!!!!  ;-)

---
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


  • Follow-Ups:
    • Re: Bridge anyone? [not off topic]
      • From: David Andrews <email@hidden>
  • Prev by Date: Re: Trouble Getting Into AppleScript
  • Next by Date: Re: Trouble Getting Into AppleScript
  • Previous by thread: Re: Bridge anyone? [not off topic]
  • Next by thread: Re: Bridge anyone? [not off topic]
  • Index(es):
    • Date
    • Thread