craylton / PgnToFen

2 stars 1 forks source link

Bug fix for PgnToFenConverter #3

Open doctorscott opened 5 months ago

doctorscott commented 5 months ago

You examples in the readme.md do not work when including in a project. Specifically, the lines converter.Convert(conversionStrategy, "MyPgnFile.pgn"); fail because of the static nature of the function. I pulled it out and all was good. While I was at it, I allowed the same function to return the pgn gameDB variable so I didn't have to parse the file twice. Just a quick and easy two-line fix... Here's what I suggest:

using ilf.pgn;
using ilf.pgn.Data;
using PgnToFenCore.Conversion;
using System;

namespace PgnToFenCore
{
    public class PgnToFenConverter
    {
        public Database Convert(IConversionStrategy strategy, string pgnFilename)  // scott 6/2024
        {
            var pgnFileReader = new PgnReader();
            Database gameDb = pgnFileReader.ReadFromFile(pgnFilename);

            Console.WriteLine(gameDb.Games.Count + " games found");

            foreach (var game in gameDb.Games)
            {
                strategy.ConvertAllFens(game);
            }
            return gameDb; // scott 6/2024
        }
    }
}
craylton commented 5 months ago

Thanks for spotting that, I've updated the readme. Out of curiosity, why are you needing to access the parsed games after getting your FENs? Is there some other functionality that isn't possible in the converter?

doctorscott commented 5 months ago

No problem! Thanks for putting your program out there!

I am using your library to do additional parsing of pgn files. There's a bunch that the pgn.net library also provides that I cannot get from the fen. Between both of them, I have much of what I need.

Scott McDermott Assistant Professor of Computer Science Department of Mathematics and Computer Science Associate Chair Loyola University New Orleans Need to schedule an appointment? https://drscott.link/schedule sms:504-641-6783 (text preferred)

On Sun, Jun 30, 2024 at 4:22 AM Simon Palmer @.***> wrote:

Thanks for spotting that, I've updated the readme. Out of curiosity, why are you needing to access the parsed games after getting your FENs? Is there some other functionality that isn't possible in the converter?

— Reply to this email directly, view it on GitHub https://github.com/craylton/PgnToFen/issues/3#issuecomment-2198494724, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALK7ZK24CJE4CCT7VPVWALLZJ7E35AVCNFSM6AAAAABKDSBOGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJYGQ4TINZSGQ . You are receiving this because you authored the thread.Message ID: @.***>

craylton commented 5 months ago

Okay. There are a bunch of properties in the FenData object which you might find useful. If you need something that isn't in there, I'm happy to add more things in. https://github.com/craylton/PgnToFen/blob/a48858f717d7a7d89bb675719946f614f1403bc0/PgnToFenCore/FenData.cs#L7-L27