Created
March 2, 2016 05:10
-
-
Save KevinMarquette/999e3eaeb75dd59a04d5 to your computer and use it in GitHub Desktop.
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
function Get-ChessResult | |
{ | |
[CmdletBinding()] | |
Param( | |
[Parameter( | |
Position = 0, | |
Mandatory = $true, | |
ValueFromPipeline = $true, | |
ValueFromPipelineByPropertyName = $true | |
)] | |
[Alias('Path')] | |
[String]$Fullname | |
) | |
begin | |
{ | |
$results = @{} | |
} | |
process | |
{ | |
$file = New-Object System.IO.StreamReader -ArgumentList $Fullname | |
:loop while ($true ) | |
{ | |
$line = $file.ReadLine() | |
if ($line -eq $null) | |
{ | |
$file.close() | |
break loop | |
} | |
if($line.StartsWith('[Re')) | |
{ | |
$results[$line]+=1 | |
} | |
} | |
} | |
end | |
{ | |
Write-Output ($results | Select-Object @{N="White";E={$_.'[Result "1-0"]'}},@{N="Black";E={$_.'[Result "0-1"]'}},@{N="Tie";E={$_.'[Result "1/2-1/2"]'}}) | |
} | |
} | |
Measure-Command { | |
get-ChildItem .\ChessData-master -Filter *.pgn -recurse | Get-ChessResult | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment