• 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: Bernard Bernu <email@hidden>
  • Date: Sun, 7 Nov 2004 18:13:23 +0100

Bravo Nigel,
You have solved the problem in a very elegant way. The use of the "chances" indirection is very nice.


Now, I have an AppleScript question :

If you put the handler deal inside script o instead of script o inside deal, you have to explicitely make a copy of chances as:
script o
property cchances : {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 : {{}, {}, {}, {}}
on deal()
try
set hands to {{}, {}, {}, {}}
copy cchances to chances
repeat with i from 1 to 52
set c to some integer of chances
set item c of chances to missing value
set end of item ((c - 1) mod 4 + 1) of hands to item i of my deck
end repeat
return hands
on error s number n
error "deal : " & s number n
end try
end deal
end script


Then the time increases from 36s to 96s (10000 deal on a PBG4 667).
I understand that the property chance inside the script o is defined at compiled time.
Is the explicit copy statment only responsible for doubling the time or are there other deeper reasons for that?


But I tried to add many lines "copy cchances to chances" in deal and the time is always the same.
Does Applescript knows that some lines can be removed?


Bernard

Le 7 nov. 04, à 02:44, Nigel Garvey a écrit :

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:
email@hidden


This email sent to email@hidden

Bernard Bernu
Physique Théorique des Liquides
4, place Jussieu, T24, 2ème
Boîte 121
75252 Paris Cedex 05, France
Tel : (33) 01 44 27 72 38 Fax : (33) 01 44 27 51 00
http://www.lptl.jussieu.fr/users/bernu


_______________________________________________
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


References: 
 >Re: Bridge anyone? [not off topic] (From: Nigel Garvey <email@hidden>)

  • Prev by Date: Re: Alias Forms as Property
  • Next by Date: Re: Alias Forms as Property
  • Previous by thread: Fastest way to find mod files?
  • Next by thread: Re: Bridge anyone? [not off topic]
  • Index(es):
    • Date
    • Thread