Skip to content

Instantly share code, notes, and snippets.

@KevinMarquette
Created March 2, 2016 05:10
Show Gist options
  • Save KevinMarquette/999e3eaeb75dd59a04d5 to your computer and use it in GitHub Desktop.
Save KevinMarquette/999e3eaeb75dd59a04d5 to your computer and use it in GitHub Desktop.
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