Last active
June 26, 2017 20:05
-
-
Save markwragg/f4f2f94dd305aa44fb7e9f6356b6d7da to your computer and use it in GitHub Desktop.
Card game generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Generate the deck | |
$Suits = 'Hearts','Diamonds','Spades','Clubs' | |
$Pack = ForEach ($Suit in $Suits) { | |
2..10 + 'Jack','Queen','King','Ace' | ForEach-Object { "$_ of $Suit" } | |
} | |
#Shuffle the deck between 1 and 5 times | |
1..(Get-Random -Min 1 -Max 5) | ForEach-Object { $Pack = $Pack | Sort-Object {Get-Random} } | |
#Deal 5 cards to each player and sort them in natural order | |
$ToNatural = { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) } | |
1..5 | ForEach-Object { | |
"Dealing cards to player $_" | |
$Pack | Select -First 5 -Skip (5*$_) | Sort-Object $ToNatural | |
"" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment