• 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: Nigel Garvey <email@hidden>
  • Date: Sun, 7 Nov 2004 01:44:48 +0000

Bill wrote on Sat, 6 Nov 2004 14:20:54 +0800:

>Well, here's a grouped, sorted unicode bridge :)
>
>-- script starts
>
>-- black spade, white heart, white diamond & black club
>set suit1 to {«data utxt2660», «data utxt2661», «data utxt2662»,
>«data utxt2663»}

I reported a couple of days ago that trying to coerce these data to
Unicode characters makes Script Editor and Smile quit suddenly in Jaguar.
It now turns out that a safe way to convert them is to write the lists to
disk and read them back again!

I'm now fairly convinced that the rethink I posted the other day of
Bernard's "next card to random hand" approach is just as valid as the
conventional "random card to next hand". It's also fast and economical.
So my contribution for sorted, Unicode hands would be:

  on makeDeck() -- This is run when the script's compiled.
    script o
      -- Black spade, white heart, white diamond, black club.
      property suits : {«data utxt2660», «data utxt2661», «data
utxt2662», «data utxt2663»}
      property cards : {"A", "K", "Q", "J", "10", "9", "8", "7", "6",
"5", "4", "3", "2"}
      property deck : {}
    end script

    if ((system attribute "sysv") < 4144) then -- pre-Panther, assume
Jaguar.
      set fred to (open for access file ((path to desktop as string) &
"suitsTemp.txt") with write permission)
      try
        set eof fred to 0
        write o's suits to fred
        set o's suits to (read fred from 1 as list)
      end try
      close access fred
      tell application "Finder" to delete file "suitsTemp.txt" of desktop
    end if

    repeat with i from 0 to 51
      set the end of o's deck to ((item (i mod 13 + 1) of o's cards) as
Unicode text) & item (i div 13 + 1) of o's suits
    end repeat

    return o's deck
  end makeDeck

  property deck : makeDeck()

  on deal()
    script o
      property chances : {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}
      property hands : {{}, {}, {}, {}}
    end script

    repeat with i from 1 to 52
      set c to some integer of o's chances
      set item c of o's chances to missing value
      set end of item ((c - 1) mod 4 + 1) of o's hands to item i of my
deck
    end repeat

    return o's hands
  end deal

  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

  • Follow-Ups:
    • Re: Bridge anyone? [not off topic]
      • From: David Andrews <email@hidden>
    • Re: Bridge anyone? [not off topic]
      • From: Bernard Bernu <email@hidden>
    • Fraction Maker Revisited Solved?
      • From: Jason Bourque <email@hidden>
  • Prev by Date: Re: HTML and Applescript?
  • Next by Date: Re: Alias Forms as Property
  • Previous by thread: Re: Bridge anyone? [not off topic]
  • Next by thread: Fraction Maker Revisited Solved?
  • Index(es):
    • Date
    • Thread