Powershell Poker Game

There is more to life than just work. For that reason, and because I enjoy a puzzle, I have created a little Poker game in Powershell. The games’ concept is based on a poker game by Arne Rippe, which I enjoyed so much, I recreated it. You have to survive 20 rounds of poker. You can bet 100 credits, half your bankroll or go all-in. The payout is always 2 to 1. The special part about this game is the fact you get to see all starting hands and get to choose which you prefer. Give it a go, I’m sure you’ll like it! My high score is 3400 credits.

Hugo

# Powershell Poker: Pick the Box
# Created by Hugo Peeters
# http://www.peetersonline.nl

# Clear the screen
Clear-Host

# Show Explanation
Write-Host “====================================================”
Write-Host ” Powershell Poker: Pick the Box”
Write-Host ” Created by Hugo Peeters”
Write-Host ” http://www.peetersonline.nl”
Write-Host “====================================================”
Write-Host ” The game consists of 20 rounds.”
Write-Host ” You get to choose which hand you play.”
Write-Host ” But you compete against all other hands.”
Write-Host ” You can bet 100, half your bankroll or go all-in.”
Write-Host ” Win ratio is 2:1.”
Write-Host ” Try to survive all 20 rounds. Have fun!”
Write-Host “====================================================”

# Variables
$delay = 1
$BankRoll = 1000
$Min = 100
$NumberOfHands = 20

$HandNumber = 0

# Start Script Loop
While ($Bankroll -gt 0)
{
$HandNumber++
If ($HandNumber -gt $NumberOfHands)
{
# End of Game
Write-Host “FINAL SCORE: $Bankroll” -BackgroundColor “Green” -ForegroundColor “Blue”
Break
}

# Decrease number of boxes throughout the game
If ($HandNumber -eq 1)
{
$Boxes = 1..6
}
If (($HandNumber/$NumberOfHands) -ge 0.2)
{
$Boxes = 1..5
}
If (($HandNumber/$NumberOfHands) -ge 0.4)
{
$Boxes = 1..4
}
If (($HandNumber/$NumberOfHands) -ge 0.6)
{
$Boxes = 1..3
}
If (($HandNumber/$NumberOfHands) -ge 0.8)
{
$Boxes = 1..2
}

# Create the deck
$Values = 2..10 + “J”,”Q”,”K”,”A”
$Suits = @()
$Suits += [char]3
$Suits += [char]4
$Suits += [char]5
$Suits += [char]6
$Cards = @()
ForEach ($Suit in $Suits)
{
ForEach($Value in $Values)
{
$Card = “” | Select Value, Rank, Suit, Picked
$Card.Value = $Value
If ($Card.Value -eq “J”){$Card.Rank = 11}
ElseIf ($Card.Value -eq “Q”){$Card.Rank = 12}
ElseIf ($Card.Value -eq “K”){$Card.Rank = 13}
ElseIf ($Card.Value -eq “A”){$Card.Rank = 14}
Else{$Card.Rank = $Card.Value}
$Card.Suit = $Suit
$Card.Picked = $False
$Cards += $Card
}
}
$Rand = New-Object Random

# Card picking function
function Pick-Card
{
$Number = $Rand.Next(0,51)
If ($Cards[$Number].Picked -eq $True)
{
Pick-Card
}
Else
{
$Cards[$Number].Picked = $True
Return $Cards[$Number]
}
}

# Straigth checking function
function Check-Straight
{
param([Array]$Hand)
$StartCard = $Hand[$i]
$AllRanks = $Hand | Select Rank -Unique | %{$_.Rank}
If ($AllRanks -contains ($StartCard.Rank + 1) -and $AllRanks -contains ($StartCard.Rank + 2) -and $AllRanks -contains ($StartCard.Rank + 3) -and $AllRanks -contains ($StartCard.Rank + 4) -and $AllRanks -contains ($StartCard.Rank + 5) -and $AllRanks -contains ($StartCard.Rank + 6))
{
$Result = “” | Select WinningCards, Rank, Score
$Result.WinningCards = @()
$Result.WinningCards += ($Hand|?{$_.Rank -eq ($StartCard.Rank + 6)} | Select -First 1)
$Result.WinningCards += ($Hand|?{$_.Rank -eq ($StartCard.Rank + 5)} | Select -First 1)
$Result.WinningCards += ($Hand|?{$_.Rank -eq ($StartCard.Rank + 4)} | Select -First 1)
$Result.WinningCards += ($Hand|?{$_.Rank -eq ($StartCard.Rank + 3)} | Select -First 1)
$Result.WinningCards += ($Hand|?{$_.Rank -eq ($StartCard.Rank + 2)} | Select -First 1)
$Result.Rank = “STRAIGHT {0} to {1}” -f ($Result.WinningCards | Sort Rank -Descending | Select -Last 1).Value, ($Result.WinningCards | Sort Rank -Descending | Select -First 1).Value
$Result.Score = 40000000000
$Result.Score += (100000000 * ($Result.WinningCards | Sort Rank -Descending)[0].Rank)
$Result.Score += (1000000 * ($Result.WinningCards | Sort Rank -Descending)[1].Rank)
$Result.Score += (10000 * ($Result.WinningCards | Sort Rank -Descending)[2].Rank)
$Result.Score += (100 * ($Result.WinningCards | Sort Rank -Descending)[3].Rank)
$Result.Score += (1 * ($Result.WinningCards | Sort Rank -Descending)[4].Rank)
Return $Result
}
ElseIf ($AllRanks -contains ($StartCard.Rank + 1) -and $AllRanks -contains ($StartCard.Rank + 2) -and $AllRanks -contains ($StartCard.Rank + 3) -and $AllRanks -contains ($StartCard.Rank + 4) -and $AllRanks -contains ($StartCard.Rank + 5))
{
$Result = “” | Select WinningCards, Rank, Score
$Result.WinningCards = @()
$Result.WinningCards += ($Hand|?{$_.Rank -eq ($StartCard.Rank + 5)} | Select -First 1)
$Result.WinningCards += ($Hand|?{$_.Rank -eq ($StartCard.Rank + 4)} | Select -First 1)
$Result.WinningCards += ($Hand|?{$_.Rank -eq ($StartCard.Rank + 3)} | Select -First 1)
$Result.WinningCards += ($Hand|?{$_.Rank -eq ($StartCard.Rank + 2)} | Select -First 1)
$Result.WinningCards += ($Hand|?{$_.Rank -eq ($StartCard.Rank + 1)} | Select -First 1)
$Result.Rank = “STRAIGHT {0} to {1}” -f ($Result.WinningCards | Sort Rank -Descending | Select -Last 1).Value, ($Result.WinningCards | Sort Rank -Descending | Select -First 1).Value
$Result.Score = 40000000000
$Result.Score += (100000000 * ($Result.WinningCards | Sort Rank -Descending)[0].Rank)
$Result.Score += (1000000 * ($Result.WinningCards | Sort Rank -Descending)[1].Rank)
$Result.Score += (10000 * ($Result.WinningCards | Sort Rank -Descending)[2].Rank)
$Result.Score += (100 * ($Result.WinningCards | Sort Rank -Descending)[3].Rank)
$Result.Score += (1 * ($Result.WinningCards | Sort Rank -Descending)[4].Rank)
Return $Result
}
ElseIf ($AllRanks -contains ($StartCard.Rank + 1) -and $AllRanks -contains ($StartCard.Rank + 2) -and $AllRanks -contains ($StartCard.Rank + 3) -and $AllRanks -contains ($StartCard.Rank + 4))
{
$Result = “” | Select WinningCards, Rank, Score
$Result.WinningCards = @()
$Result.WinningCards += ($Hand|?{$_.Rank -eq ($StartCard.Rank + 4)} | Select -First 1)
$Result.WinningCards += ($Hand|?{$_.Rank -eq ($StartCard.Rank + 3)} | Select -First 1)
$Result.WinningCards += ($Hand|?{$_.Rank -eq ($StartCard.Rank + 2)} | Select -First 1)
$Result.WinningCards += ($Hand|?{$_.Rank -eq ($StartCard.Rank + 1)} | Select -First 1)
$Result.WinningCards += ($Hand|?{$_.Rank -eq $StartCard.Rank} | Select -First 1)
$Result.Rank = “STRAIGHT {0} to {1}” -f ($Result.WinningCards | Sort Rank -Descending | Select -Last 1).Value, ($Result.WinningCards | Sort Rank -Descending | Select -First 1).Value
$Result.Score = 40000000000
$Result.Score += (100000000 * ($Result.WinningCards | Sort Rank -Descending)[0].Rank)
$Result.Score += (1000000 * ($Result.WinningCards | Sort Rank -Descending)[1].Rank)
$Result.Score += (10000 * ($Result.WinningCards | Sort Rank -Descending)[2].Rank)
$Result.Score += (100 * ($Result.WinningCards | Sort Rank -Descending)[3].Rank)
$Result.Score += (1 * ($Result.WinningCards | Sort Rank -Descending)[4].Rank)
Return $Result
}
ElseIf ($AllRanks -contains 1 -and $AllRanks -contains 2 -and $AllRanks -contains 3 -and $AllRanks -contains 4 -and $AllRanks -contains 14)
{
$Result = “” | Select WinningCards, Rank, Score
$Result.Rank = “STRAIGHT A to 4″
$Result.WinningCards = $Hand | Where {$_.Rank -eq 1 -or $_.Rank -eq 2 -or $_.Rank -eq 3 -or $_.Rank -eq 4 -or $_.Rank -eq 14}
$Result.Score = 40000000000
$Result.Score += (100000000 * ($Result.WinningCards | Sort Rank -Descending)[0].Rank)
$Result.Score += (1000000 * ($Result.WinningCards | Sort Rank -Descending)[1].Rank)
$Result.Score += (10000 * ($Result.WinningCards | Sort Rank -Descending)[2].Rank)
$Result.Score += (100 * ($Result.WinningCards | Sort Rank -Descending)[3].Rank)
$Result.Score += (1 * ($Result.WinningCards | Sort Rank -Descending)[4].Rank)
Return $Result
}
Else
{
$i++
If ($i -eq 7)
{
Return $False
}
Else
{
Check-Straight $Hand
}
}
}

$myCol = @()

# Dealing hole cards
ForEach ($Box in $Boxes)
{
$myObj = “” | Select Box, Hole, Result, Score
$myObj.Box = $Box
$myObj.Hole = @()
$Card = Pick-Card
$myObj.Hole += $Card
$Card = Pick-Card
$myObj.Hole += $Card
$myCol += $myObj
}

$Community = @()
$Card = Pick-Card
$Community += $Card
$Card = Pick-Card
$Community += $Card
$Card = Pick-Card
$Community += $Card
$Card = Pick-Card
$Community += $Card
$Card = Pick-Card
$Community += $Card

# Result checking function
Function Check-Result
{
param([Array]$Hand)

$Result = “” | Select WinningCards, Rank, Score

# STRAIGHT FLUSH & ROYAL FLUSH
$Hand = $Hand | Sort Rank
$i = 0
$StraightResult = Check-Straight $Hand
If ($StraightResult -ne $False)
{
If ($StraightResult.WinningCards | Group Suit | Where {$_.Count -ge 5})
{
$FlushSuit = ($StraightResult.WinningCards | Group Suit | Where {$_.Count -ge 5}).Name
$Result.WinningCards = $StraightResult.WinningCards
$LowCard = ($StraightResult.WinningCards | Sort Rank | Select -First 1).Value
$HighCard = ($StraightResult.WinningCards | Sort Rank -Descending | Select -First 1).Value
If ($HighCard -eq “A”)
{
$Result.Rank = “ROYAL FLUSH!!!!!!!”
$Result.Score = 90000000000
Return $Result
}
Else
{
$Result.Rank = “STRAIGHT FLUSH {0} to {1}” -f $LowCard, $HighCard
$Result.Score = 80000000000
$Result.Score += (100000000 * ($Result.WinningCards | Sort Rank -Descending)[0].Rank)
$Result.Score += (1000000 * ($Result.WinningCards | Sort Rank -Descending)[1].Rank)
$Result.Score += (10000 * ($Result.WinningCards | Sort Rank -Descending)[2].Rank)
$Result.Score += (100 * ($Result.WinningCards | Sort Rank -Descending)[3].Rank)
$Result.Score += (1 * ($Result.WinningCards | Sort Rank -Descending)[4].Rank)
Return $Result
}
}
}
# QUADS
If ($Hand | Group Value | Where {$_.Count -ge 4})
{
$QuadValue = ($Hand | Group Value | Where {$_.Count -ge 4}).Name
$Result.WinningCards = $Hand | ?{$_.Value -eq $QuadValue}
$Result.WinningCards += $Hand | ?{$_.Value -ne $QuadValue} | Sort Rank -Descending | Select -First 1
$Result.Rank = “QUAD {0}s” -f $QuadValue
$Result.Score = 70000000000
$Result.Score += (100000000 * ($Result.WinningCards | ?{$_.Value -eq $QuadValue} | Sort Rank -Descending)[0].Rank)
$Result.Score += (1000000 * ($Result.WinningCards | ?{$_.Value -eq $QuadValue} | Sort Rank -Descending)[1].Rank)
$Result.Score += (10000 * ($Result.WinningCards | ?{$_.Value -eq $QuadValue} | Sort Rank -Descending)[2].Rank)
$Result.Score += (100 * ($Result.WinningCards | ?{$_.Value -eq $QuadValue} | Sort Rank -Descending)[3].Rank)
$Result.Score += (1 * ($Result.WinningCards | ?{$_.Value -ne $QuadValue}).Rank)
Return $Result
}
# FULL HOUSE
ElseIf (($Hand | Group Value | Where {$_.Count -ge 2} | %{$_.Count}) -contains 3 -and ($Hand | Group Value | Where {$_.Count -ge 2} | %{$_.Count}) -contains 2)
{
$Full1Value = ($Hand | Group Value | Where {$_.Count -eq 3}).Name
$Full2Rank = ($Hand | Group Rank | Where {$_.Count -eq 2} | Sort Rank -Descending | Select -First 1).Name
$Full2Value = ($Hand | ?{$_.Rank -eq $Full2Rank} | Select -First 1).Value
$Result.WinningCards = $Hand | ?{$_.Value -eq $Full1Value -or $_.Value -eq $Full2Value}
$Result.Rank = “FULL HOUSE {0}s full of {1}s” -f $Full1Value, $Full2Value
$Result.Score = 60000000000
$Result.Score += (100000000 * ($Result.WinningCards | ?{$_.Value -eq $Full1Value} | Sort Rank -Descending)[0].Rank)
$Result.Score += (1000000 * ($Result.WinningCards | ?{$_.Value -eq $Full1Value} | Sort Rank -Descending)[1].Rank)
$Result.Score += (10000 * ($Result.WinningCards | ?{$_.Value -eq $Full1Value} | Sort Rank -Descending)[2].Rank)
$Result.Score += (100 * ($Result.WinningCards | ?{$_.Value -eq $Full2Value} | Sort Rank -Descending)[0].Rank)
$Result.Score += (1 * ($Result.WinningCards | ?{$_.Value -eq $Full2Value} | Sort Rank -Descending)[1].Rank)
Return $Result
}
ElseIf (($Hand | Group Value | Where {$_.Count -ge 2} | %{$_.Count}) -contains 4 -and ($Hand | Group Value | Where {$_.Count -ge 2} | %{$_.Count}) -contains 2)
{
$Full1Value = ($Hand | Group Value | Where {$_.Count -eq 4}).Name
$Full2Value = ($Hand | Group Value | Where {$_.Count -eq 2}).Name
$Result.WinningCards = $Hand | ?{$_.Value -eq $Full1Value -or $_.Value -eq $Full2Value}
$Result.Rank = “FULL HOUSE {0}s full of {1}s” -f $Full1Value, $Full2Value
$Result.Score = 60000000000
$Result.Score += (100000000 * ($Result.WinningCards | ?{$_.Value -eq $Full1Value} | Sort Rank -Descending)[0].Rank)
$Result.Score += (1000000 * ($Result.WinningCards | ?{$_.Value -eq $Full1Value} | Sort Rank -Descending)[1].Rank)
$Result.Score += (10000 * ($Result.WinningCards | ?{$_.Value -eq $Full1Value} | Sort Rank -Descending)[2].Rank)
$Result.Score += (100 * ($Result.WinningCards | ?{$_.Value -eq $Full2Value} | Sort Rank -Descending)[0].Rank)
$Result.Score += (1 * ($Result.WinningCards | ?{$_.Value -eq $Full2Value} | Sort Rank -Descending)[1].Rank)
Return $Result
}
ElseIf (($Hand | Group Value | Where {$_.Count -eq 3} | Measure-Object).Count -eq 2)
{
$Full1Value = ($Hand | Group Value | Where {$_.Count -eq 3})[0].Name
$Full2Value = ($Hand | Group Value | Where {$_.Count -eq 3})[1].Name
$Result.WinningCards = $Hand | ?{$_.Value -eq $Full1Value -or $_.Value -eq $Full2Value}
$TopValue = ($Result.WinningCards | Sort Rank -Descending | Select -First 1).Value
$BottomValue = ($Result.WinningCards | Sort Rank | Select -First 1).Value
$Result.Rank = “FULL HOUSE {0}s full of {1}s” -f $TopValue, $BottomValue
$Result.Score = 60000000000
$Result.Score += (100000000 * ($Result.WinningCards | ?{$_.Value -eq $TopValue} | Sort Rank -Descending)[0].Rank)
$Result.Score += (1000000 * ($Result.WinningCards | ?{$_.Value -eq $TopValue} | Sort Rank -Descending)[1].Rank)
$Result.Score += (10000 * ($Result.WinningCards | ?{$_.Value -eq $TopValue} | Sort Rank -Descending)[2].Rank)
$Result.Score += (100 * ($Result.WinningCards | ?{$_.Value -eq $BottomValue} | Sort Rank -Descending)[0].Rank)
$Result.Score += (1 * ($Result.WinningCards | ?{$_.Value -eq $BottomValue} | Sort Rank -Descending)[1].Rank)
Return $Result
}
# FLUSH
ElseIf ($Hand | Group Suit | Where {$_.Count -ge 5})
{
$FlushSuit = ($Hand | Group Suit | Where {$_.Count -ge 5}).Name
$Result.WinningCards = $Hand | ?{$_.Suit -eq $FlushSuit}
$Result.Rank = “FLUSH of {0}” -f $FlushSuit
$Result.Score = 50000000000
Return $Result
}
# STRAIGHT
$Hand = $Hand | Sort Rank
$i = 0
$StraightResult = Check-Straight $Hand
If ($StraightResult -ne $False)
{
Return $StraightResult
}
# TRIPS
ElseIf ($Hand | Group Value | Where {$_.Count -ge 3})
{
$TripsValue = ($Hand | Group Value | Where {$_.Count -ge 3}).Name
$Result.WinningCards = $Hand | ?{$_.Value -eq $TripsValue}
$Result.WinningCards += $Hand | ?{$_.Value -ne $TripsValue} | Sort Rank -Descending | Select -First 2
$Result.Rank = “TRIPS {0}s” -f $TripsValue
$Result.Score = 30000000000
$Result.Score += (100000000 * ($Result.WinningCards | ?{$_.Value -eq $TripsValue} | Sort Rank -Descending)[0].Rank)
$Result.Score += (1000000 * ($Result.WinningCards | ?{$_.Value -eq $TripsValue} | Sort Rank -Descending)[1].Rank)
$Result.Score += (10000 * ($Result.WinningCards | ?{$_.Value -eq $TripsValue} | Sort Rank -Descending)[2].Rank)
$Result.Score += (100 * ($Result.WinningCards | ?{$_.Value -ne $TripsValue} | Sort Rank -Descending)[0].Rank)
$Result.Score += (1 * ($Result.WinningCards | ?{$_.Value -ne $TripsValue} | Sort Rank -Descending)[1].Rank)
Return $Result
}
# TWO PAIR
ElseIf (($Hand | Group Value | Where {$_.Count -ge 2} | Measure-Object).Count -ge 2)
{
$PairValues = ($Hand | Group Value | Where {$_.Count -eq 2} | %{$_.Name})
$TP1Value = ($Hand | ?{$PairValues -contains $_.Value} | Sort Rank -Descending)[0].Value
$TP2Value = ($Hand | ?{$PairValues -contains $_.Value} | Sort Rank -Descending)[2].Value
$Result.WinningCards = $Hand | ?{$_.Value -eq $TP1Value -or $_.Value -eq $TP2Value}
$Result.WinningCards += $Hand | ?{$_.Value -ne $TP1Value -and $_.Value -ne $TP2Value} | Sort Rank -Descending | Select -First 1
$Result.Rank = “TWO PAIR {0}s and {1}s” -f $TP1Value, $TP2Value
$Result.Score = 20000000000
$Result.Score += (100000000 * ($Result.WinningCards | ?{$_.Value -eq $TP1Value -or $_.Value -eq $TP2Value} | Sort Rank -Descending)[0].Rank)
$Result.Score += (1000000 * ($Result.WinningCards | ?{$_.Value -eq $TP1Value -or $_.Value -eq $TP2Value} | Sort Rank -Descending)[1].Rank)
$Result.Score += (10000 * ($Result.WinningCards | ?{$_.Value -eq $TP1Value -or $_.Value -eq $TP2Value} | Sort Rank -Descending)[2].Rank)
$Result.Score += (100 * ($Result.WinningCards | ?{$_.Value -eq $TP1Value -or $_.Value -eq $TP2Value} | Sort Rank -Descending)[3].Rank)
$Result.Score += (1 * ($Result.WinningCards | ?{$_.Value -ne $TP1Value -and $_.Value -ne $TP2Value}).Rank)
Return $Result
}
# PAIR
ElseIf ($Hand | Group Value | Where {$_.Count -ge 2})
{
$PairValue = ($Hand | Group Value | Where {$_.Count -ge 2}).Name
$Result.WinningCards = $Hand | ?{$_.Value -eq $PairValue}
$Result.WinningCards += $Hand | ?{$_.Value -ne $PairValue} | Sort Rank -Descending | Select -First 3
$Result.Rank = “PAIR of {0}s” -f $PairValue
$Result.Score = 10000000000
$Result.Score += (100000000 * ($Result.WinningCards | ?{$_.Value -eq $PairValue})[0].Rank)
$Result.Score += (1000000 * ($Result.WinningCards | ?{$_.Value -eq $PairValue})[1].Rank)
$Result.Score += (10000 * ($Result.WinningCards | ?{$_.Value -ne $PairValue} | Sort Rank -Descending)[0].Rank)
$Result.Score += (100 * ($Result.WinningCards | ?{$_.Value -ne $PairValue} | Sort Rank -Descending)[1].Rank)
$Result.Score += (1 * ($Result.WinningCards | ?{$_.Value -ne $PairValue} | Sort Rank -Descending)[2].Rank)
Return $Result
}
# HIGH CARD
Else
{
$Result.WinningCards = $Hand | Sort Rank -Descending | Select -First 5
$HighValue = ($Hand | Sort Rank -Descending | Select -First 1).Value
$Result.Rank = “HIGH CARD {0}” -f $HighValue
$Result.Score = (100000000 * ($Result.WinningCards | Sort Rank -Descending)[0].Rank)
$Result.Score += (1000000 * ($Result.WinningCards | Sort Rank -Descending)[1].Rank)
$Result.Score += (10000 * ($Result.WinningCards | Sort Rank -Descending)[2].Rank)
$Result.Score += (100 * ($Result.WinningCards | Sort Rank -Descending)[3].Rank)
$Result.Score += (1 * ($Result.WinningCards | Sort Rank -Descending)[4].Rank)
Return $Result
}
}

# Calculate Results for each hand
ForEach ($myObj in $myCol)
{
$Hand = $myObj.Hole + $Community
$myObj.Result = Check-Result $Hand
$myObj.Score = $myObj.Result.Score
}
$WinningScore = ($myCol | Sort Score -Descending | Select -First 1).Score
$NumberOfWinners = ($myCol | ?{$_.Score -eq $WinningScore} | Measure-Object).Count

# Start Game Display
Write-Host “”
Write-Host “=======================”
Write-Host “Hand Number $HandNumber”
Write-Host “=======================”
Write-Host “”
Write-Host “Your Bankroll: $BankRoll”
# Show Boxes
$myCol | Format-Table Box, @{L=”Hole”;E={“{0}{1} {2}{3}” -f $_.Hole[0].Value, $_.Hole[0].Suit,$_.Hole[1].Value, $_.Hole[1].Suit}} -AutoSize
# Select Box
$Pick = Read-Host “Pick a box”
$PickedHand = $myCol | ?{$_.Box -eq $Pick}
# Determine Bets
$Half = [math]::Round(($BankRoll / 2),0)
If ($Bankroll -lt $Min)
{
$HalfBet = $Bankroll
$MinBet = $BankRoll
}
ElseIf ($Half -lt $Min)
{
$HalfBet = $Min
}
Else
{
$HalfBet = $Half
$MinBet = $Min
}
# Select Bet Amount
$title = “BET”
$message = “How much would you like to bet?”
$choiceMIN = New-Object System.Management.Automation.Host.ChoiceDescription “&Minimum ($MinBet)”, `
“Bet the minimum amount of 100.”
$choiceHALF = New-Object System.Management.Automation.Host.ChoiceDescription “&Half ($HalfBet)”, `
“Bet half your bankroll ($Half).”
$choiceALLIN = New-Object System.Management.Automation.Host.ChoiceDescription “&All-in ($Bankroll)”, `
“Bet your entire bankroll ($Bankroll).”
$options = [System.Management.Automation.Host.ChoiceDescription[]]($choiceMIN, $choiceHALF, $choiceALLIN)
$Choice = $host.ui.PromptForChoice($title, $message, $options, 0)
Switch ($Choice)
{
0 {$Bet = $MinBet}
1 {$Bet = $HalfBet}
2 {$Bet = $Bankroll}
}
Write-Host “”
Start-Sleep -Seconds $Delay
# Deal Community Cards
Write-Host “Community Cards:”
Start-Sleep -Seconds $delay
ForEach ($Card in $Community)
{
Write-Host (“{0}{1} ” -f $Card.Value, $Card.Suit) -NoNewLine
Start-Sleep -Seconds $Delay
}
Write-Host “”
Write-Host “”
# Display Hand Results
ForEach ($Hand in $myCol)
{
If ($Hand.Box -eq $Pick)
{$color = “yellow”}
Else {$color = “white”}
Write-Host (“Hand {0}: ” -f $Hand.Box) -NoNewline -ForegroundColor $color
If ($Hand.Result.Score -eq $WinningScore){$color = “green”}
Else {$Color = “white”}
Write-Host (“{0}” -f $Hand.Result.Rank) -ForegroundColor $Color
}
Write-Host “”
Write-Host “”
# Display Your Result:
$WinningScore = ($myCol | Sort Score -Descending | Select -First 1).Score
$NumberOfWinners = ($myCol | ?{$_.Score -eq $WinningScore} | Measure-Object).Count
If ($PickedHand.Score -eq $WinningScore)
{
If ($NumberOfWinners -gt 1)
{
Write-Host “Standoff”
}
Else
{
Write-Host “You WIN!” -ForegroundColor “Green”
$BankRoll += ([int]$Bet *2)
}
}
Else
{
Write-Host “You LOSE!” -ForegroundColor “Red”
$BankRoll -= $Bet
}
If ($BankRoll -le 0)
{
# Bankrupt means Game Over
Write-Host “GAME OVER” -BackgroundColor “Red”
}
Start-Sleep -Seconds $delay
}

»crosslinked«

2 thoughts on “Powershell Poker Game”

Leave a Reply