-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.ps1
69 lines (51 loc) · 1.67 KB
/
Game.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<#
TODO: Find a code style/format so that this is idiomatic
From what I can tell, functions have a different style than formal Cmdlets
#>
# https://github.com/PoshCode/PowerShellPracticeAndStyle/blob/master/Style-Guide/Code-Layout-and-Formatting.md
$here = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
. "$here\Strategy.ps1"
function getDeck ([int] $numCards) {
1..$numCards
}
function shuffleDeck ([int[]] $deck) {
[int[]] ($deck | Sort-Object {Get-Random})
}
# https://stackoverflow.com/a/26850233/12704
function dealDeck ([int[]] $deck, [int] $handSize) {
$counter = [pscustomobject] @{ Value = 0 }
$groups = $deck | Group-Object -Property { [math]::Floor($counter.Value++ / $handSize) }
$groups
}
function playGame ([int []] $kitty, $players) {
foreach ($prizeCard in $kitty) {
playRound $prizeCard $players
}
$winningPlayer = findWinner $players
Write-Host "Winner: "
logPlayer $winningPlayer
}
function playRound ([int] $prizeCard, $players) {
Write-Host "`n`n----------------"
Write-Host "TRACER prizeCard: ${prizeCard}"
$winningBid = -1
$winningPlayer = $null
foreach ($player in $players) {
$bid = playerTakesTurn $player $prizeCard
if ($bid -gt $winningBid) {
$winningBid = $bid
$winningPlayer = $player
}
}
playerWins $winningPlayer $prizeCard
Write-Host "TRACER winner: " $winningPlayer.Name " with bid: " $winningBid
}
# ------ main
<#
$deck = Get-Deck 20
Write-Host "TRACER deck : " + $deck
$deck = Shuffle-Deck $deck
$hands = Deal-Deck $deck 5
Write-Host "TRACER x : " + $hands.Count
Write-Host "TRACER y : " + $hands[0].Group
#>