Skip to content

Instantly share code, notes, and snippets.

@markwragg
Last active June 26, 2017 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markwragg/f4f2f94dd305aa44fb7e9f6356b6d7da to your computer and use it in GitHub Desktop.
Save markwragg/f4f2f94dd305aa44fb7e9f6356b6d7da to your computer and use it in GitHub Desktop.
Card game generator
#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