• 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: Bill <email@hidden>
  • Date: 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»}
-- white spade, black heart, black diamond & white club
set suit2 to {«data utxt2664», «data utxt2665», «data utxt2666», «data utxt2666»}


set cardValue to {"A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3", "2"}
set deck to {}


-- make a randomized deck
repeat until (count of deck) = 52
set card to ((some item of cardValue) as Unicode text) & some item of suit1
if not (card is in deck) then
set end of deck to card
end if
end repeat
set north to items 1 thru 13 of deck
set east to items 14 thru 26 of deck
set south to items 27 thru 39 of deck
set west to items 40 thru 52 of deck


{my group(north), my group(east), my group(south), my group(west)}



-- group cards according to suit, then sort card according to value
on group(hand)
set spade to {}
set heart to {}
set diamond to {}
set club to {}
repeat with i in hand
if (character -1 of (contents of i)) is in {«data utxt2660» as Unicode text, «data utxt2664» as Unicode text} then
set end of spade to (contents of i)
else if (character -1 of (contents of i)) is in {«data utxt2661» as Unicode text, «data utxt2665» as Unicode text} then
set end of heart to (contents of i)
else if (character -1 of (contents of i)) is in {«data utxt2662» as Unicode text, «data utxt2666» as Unicode text} then
set end of diamond to (contents of i)
else if (character -1 of (contents of i)) is in {«data utxt2663» as Unicode text, «data utxt2667» as Unicode text} then
set end of club to (contents of i)
end if
end repeat
return my sortCard(spade) & my sortCard(heart) & my sortCard(diamond) & my sortCard(club)
end group


-- sort card according to cardValue
on sortCard(suit)
	set yin to {}
	set yang to {}
	repeat with i in suit
		if character -2 of (contents of i) = "A" then
			set end of yin to "a" & (contents of i)
		else if character -2 of (contents of i) = "K" then
			set end of yin to "b" & (contents of i)
		else if character -2 of (contents of i) = "Q" then
			set end of yin to "c" & (contents of i)
		else if character -2 of (contents of i) = "J" then
			set end of yin to "d" & (contents of i)
		else if character -2 of (contents of i) = "0" then
			set end of yin to "e" & (contents of i)
		else if character -2 of (contents of i) = "9" then
			set end of yin to "f" & (contents of i)
		else if character -2 of (contents of i) = "8" then
			set end of yin to "g" & (contents of i)
		else if character -2 of (contents of i) = "7" then
			set end of yin to "h" & (contents of i)
		else if character -2 of (contents of i) = "6" then
			set end of yin to "i" & (contents of i)
		else if character -2 of (contents of i) = "5" then
			set end of yin to "j" & (contents of i)
		else if character -2 of (contents of i) = "4" then
			set end of yin to "k" & (contents of i)
		else if character -2 of (contents of i) = "3" then
			set end of yin to "l" & (contents of i)
		else if character -2 of (contents of i) = "2" then
			set end of yin to "m" & (contents of i)
		end if
	end repeat
	repeat with i in my ASCII_Sort(yin)
		set end of yang to (text 2 thru -1 of (contents of i) as Unicode text)
	end repeat
	return yang
end sortCard

-- sort routine from Apple
on ASCII_Sort(my_list)
	set the index_list to {}
	set the sorted_list to {}
	repeat (the number of items in my_list) times
		set the low_item to ""
		repeat with i from 1 to (number of items in my_list)
			if i is not in the index_list then
				set this_item to item i of my_list as text
				if the low_item is "" then
					set the low_item to this_item
					set the low_item_index to i
				else if this_item comes before the low_item then
					set the low_item to this_item
					set the low_item_index to i
				end if
			end if
		end repeat
		set the end of sorted_list to the low_item
		set the end of the index_list to the low_item_index
	end repeat
	return the sorted_list
end ASCII_Sort

-- script ends

-- suit1
-- {{"K♠", "9♠", "3♠", "9♡", "K♢", "Q♢", "J♢", "8♢", "3♢", "2♢", "Q♣", "5♣", "4♣"}, {"Q♠", "J♠", "4♠", "10♡", "8♡", "5♡", "10♢", "9♢", "7♢", "A♣", "6♣", "3♣", "2♣"}, {"A♠", "8♠", "6♠", "5♠", "2♠", "A♡", "K♡", "Q♡", "7♡", "3♡", "2♡", "6♢", "4♢"}, {"10♠", "7♠", "J♡", "6♡", "4♡", "A♢", "5♢", "K♣", "J♣", "10♣", "9♣", "8♣", "7♣"}}


-- suit2
-- {{"10♤", "9♤", "7♤", "6♤", "4♤", "6♥", "5♥", "2♥", "3♦", "2♦", "A♧", "J♧", "5♧"}, {"8♤", "J♥", "8♥", "4♥", "A♦", "J♦", "9♦", "8♦", "7♦", "5♦", "6♧", "3♧", "2♧"}, {"A♤", "J♤", "A♥", "7♥", "3♥", "K♦", "Q♦", "10♦", "6♦", "4♦", "K♧", "7♧", "4♧"}, {"K♤", "Q♤", "5♤", "3♤", "2♤", "K♥", "Q♥", "10♥", "9♥", "Q♧", "10♧", "9♧", "8♧"}}



bill



☠ 孤寂地
<http://homepage.mac.com/cherish/triste/>

_______________________________________________
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: Robert Poland <email@hidden>
  • Prev by Date: Orphaned disk error fixed in 10.3.6
  • Next by Date: Mail rule script interacting with FileMaker
  • Previous by thread: Re: Bridge anyone? [not off topic]
  • Next by thread: Re: Bridge anyone? [not off topic]
  • Index(es):
    • Date
    • Thread