Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,92 @@
|
|||
use AppleScript version "2.5" -- OS X 10.11 (El Capitan) or later
|
||||
use framework "Foundation"
|
||||
use framework "GameplayKit" -- For randomising functions.
|
||||
|
||||
on cardTrick()
|
||||
(* Create a pack of "cards" and shuffle it. *)
|
||||
set suits to {"♥️", "♣️", "♦️", "♠️"}
|
||||
set cards to {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}
|
||||
set deck to {}
|
||||
repeat with s from 1 to (count suits)
|
||||
set suit to item s of suits
|
||||
repeat with c from 1 to (count cards)
|
||||
set end of deck to item c of cards & suit
|
||||
end repeat
|
||||
end repeat
|
||||
set deck to (current application's class "GKRandomSource"'s new()'s arrayByShufflingObjectsInArray:(deck)) as list
|
||||
|
||||
(* Perform the black pile/red pile/discard stuff. *)
|
||||
set {blackPile, redPile, discardPile} to {{}, {}, {}}
|
||||
repeat with c from 1 to (count deck) by 2
|
||||
set topCard to item c of deck
|
||||
if (character -1 of topCard is in "♣️♠️") then
|
||||
set end of blackPile to item (c + 1) of deck
|
||||
else
|
||||
set end of redPile to item (c + 1) of deck
|
||||
end if
|
||||
set end of discardPile to topCard
|
||||
end repeat
|
||||
-- When equal numbers of two possibilities are randomly paired, the number of pairs whose members are
|
||||
-- both one of the possibilities is the same as the number whose members are both the other. The cards
|
||||
-- in the red and black piles have effectively been paired with cards of the eponymous colours, so
|
||||
-- the number of reds in the red pile is already the same as the number of blacks in the black.
|
||||
|
||||
(* Take a random number of random cards from one pile and swap them with an equal number from the other,
|
||||
religiously following the "red bunch"/"black bunch" ritual instead of simply swapping pairs of cards. *)
|
||||
-- Where swapped cards are the same colour, this will make no difference at all. Where the colours
|
||||
-- are different, both piles will either gain or lose a card of their relevant colour, maintaining
|
||||
-- the defining balance either way.
|
||||
set {redBunch, blackBunch} to {{}, {}}
|
||||
set {redPileCount, blackPileCount} to {(count redPile), (count blackPile)}
|
||||
set maxX to blackPileCount
|
||||
if (redPileCount < maxX) then set maxX to redPileCount
|
||||
set X to (current application's class "GKRandomDistribution"'s distributionForDieWithSideCount:(maxX))'s nextInt()
|
||||
set RNG to current application's class "GKShuffledDistribution"'s distributionForDieWithSideCount:(redPileCount)
|
||||
repeat X times
|
||||
set r to RNG's nextInt()
|
||||
set end of redBunch to item r of redPile
|
||||
set item r of redPile to missing value
|
||||
end repeat
|
||||
set RNG to current application's class "GKShuffledDistribution"'s distributionForDieWithSideCount:(blackPileCount)
|
||||
repeat X times
|
||||
set b to RNG's nextInt()
|
||||
set end of blackBunch to item b of blackPile
|
||||
set item b of blackPile to missing value
|
||||
end repeat
|
||||
set blackPile to (blackPile's text) & redBunch
|
||||
set redPile to (redPile's text) & blackBunch
|
||||
|
||||
(* Count and compare the number of blacks in the black pile and the number of reds in the red. *)
|
||||
set blacksInBlackPile to 0
|
||||
repeat with card in blackPile
|
||||
if (character -1 of card is in "♣️♠️") then set blacksInBlackPile to blacksInBlackPile + 1
|
||||
end repeat
|
||||
set redsInRedPile to 0
|
||||
repeat with card in redPile
|
||||
if (character -1 of card is in "♥️♦️") then set redsInRedPile to redsInRedPile + 1
|
||||
end repeat
|
||||
|
||||
return {truth:(blacksInBlackPile = redsInRedPile), reds:redPile, blacks:blackPile, discards:discardPile}
|
||||
end cardTrick
|
||||
|
||||
on join(lst, delim)
|
||||
set astid to AppleScript's text item delimiters
|
||||
set AppleScript's text item delimiters to delim
|
||||
set txt to lst as text
|
||||
set AppleScript's text item delimiters to astid
|
||||
return txt
|
||||
end join
|
||||
|
||||
on task()
|
||||
set output to {}
|
||||
repeat with i from 1 to 5
|
||||
set {truth:truth, reds:reds, blacks:blacks, discards:discards} to cardTrick()
|
||||
set end of output to "Test " & i & ": Assertion is " & truth
|
||||
set end of output to "Red pile: " & join(reds, ", ")
|
||||
set end of output to "Black pile: " & join(blacks, ", ")
|
||||
set end of output to "Discards: " & join(items 1 thru 13 of discards, ", ")
|
||||
set end of output to " " & (join(items 14 thru 26 of discards, ", ") & linefeed)
|
||||
end repeat
|
||||
return text 1 thru -2 of join(output, linefeed)
|
||||
end task
|
||||
return task()
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
"Test 1: Assertion is true
|
||||
Red pile: 3♦️, 2♦️, 9♣️, 6♣️, 3♥️, 9♥️, A♠️, 3♠️, 2♥️, Q♠️, 7♥️, K♥️
|
||||
Black pile: Q♥️, J♣️, 7♦️, 4♦️, 8♦️, 5♥️, K♣️, 10♠️, 10♣️, 7♣️, 2♣️, 9♦️, 5♣️, 6♦️
|
||||
Discards: 9♠️, Q♦️, 3♣️, 6♠️, 8♠️, 8♥️, Q♣️, 4♠️, J♠️, K♦️, 7♠️, A♦️, 5♦️
|
||||
10♥️, J♦️, A♥️, 4♥️, 6♥️, J♥️, K♠️, 5♠️, 10♦️, 4♣️, 2♠️, 8♣️, A♣️
|
||||
|
||||
Test 2: Assertion is true
|
||||
Red pile: 7♣️, Q♠️, 2♦️, K♣️, J♠️, A♠️, J♣️, 5♣️, 6♥️, 7♦️, 5♥️, 9♥️, 8♠️, 3♠️, 6♣️, 4♠️
|
||||
Black pile: K♠️, J♦️, 4♣️, 10♠️, 4♥️, 3♥️, 6♠️, 4♦️, 10♣️, 9♦️
|
||||
Discards: 8♦️, J♥️, A♣️, 10♥️, 8♣️, 9♠️, A♦️, 2♣️, K♥️, Q♣️, A♥️, 5♦️, 9♣️
|
||||
K♦️, 3♣️, 2♠️, 7♠️, 5♠️, 2♥️, 6♦️, 10♦️, 3♦️, Q♦️, 8♥️, 7♥️, Q♥️
|
||||
|
||||
Test 3: Assertion is true
|
||||
Red pile: 4♥️, 2♠️, Q♦️, 9♣️, 4♣️, 7♥️, A♣️, 6♠️, 3♥️, 8♣️, A♦️, 2♣️, 6♥️, 5♦️
|
||||
Black pile: K♦️, 2♦️, 5♠️, 10♠️, J♠️, 9♦️, 4♦️, 4♠️, Q♣️, 6♣️, 3♣️, 10♦️
|
||||
Discards: J♦️, 9♥️, K♠️, 10♥️, 5♥️, 10♣️, K♣️, 8♠️, 8♥️, A♠️, 7♣️, 7♦️, 8♦️
|
||||
Q♠️, 9♠️, 6♦️, 3♠️, 2♥️, J♣️, A♥️, K♥️, Q♥️, 5♣️, 7♠️, 3♦️, J♥️
|
||||
|
||||
Test 4: Assertion is true
|
||||
Red pile: 6♠️, A♣️, 8♥️, 4♣️, 5♥️, J♠️, 9♠️, 7♥️, 7♣️, 4♦️, A♠️, A♥️, 8♠️, 6♦️, 5♣️, Q♣️, 6♥️, K♠️
|
||||
Black pile: 5♦️, 4♠️, 2♣️, 6♣️, 10♣️, 8♣️, Q♠️, 10♠️
|
||||
Discards: J♥️, A♦️, 7♠️, 9♥️, K♦️, 10♥️, Q♦️, 10♦️, 8♦️, 3♥️, 3♠️, 2♦️, J♣️
|
||||
9♦️, J♦️, 9♣️, 2♠️, 3♦️, 2♥️, 7♦️, Q♥️, 3♣️, K♥️, K♣️, 5♠️, 4♥️
|
||||
|
||||
Test 5: Assertion is true
|
||||
Red pile: 2♣️, 9♠️, 5♦️, 4♥️, K♥️, 5♥️, 8♦️, 2♠️, 3♦️, 10♥️, 10♦️
|
||||
Black pile: 2♦️, 2♥️, 8♣️, 9♣️, 7♥️, 3♣️, Q♠️, 10♠️, 8♥️, 10♣️, K♣️, 5♠️, 4♦️, 3♥️, 6♥️
|
||||
Discards: 7♦️, J♥️, 7♣️, 4♠️, 6♦️, 4♣️, 7♠️, Q♥️, J♠️, Q♦️, 6♠️, J♣️, A♥️
|
||||
9♦️, K♦️, J♦️, 3♠️, 5♣️, Q♣️, A♣️, K♠️, 8♠️, 9♥️, A♠️, 6♣️, A♦️"
|
||||
Loading…
Add table
Add a link
Reference in a new issue