Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.