Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PGN parser #494

Open
nescitus opened this issue Dec 13, 2023 · 0 comments
Open

PGN parser #494

nescitus opened this issue Dec 13, 2023 · 0 comments

Comments

@nescitus
Copy link

I have tried to add a very basic PGN parser. Internal board is updated correctly, but it crashes on trying to execute a move in BoardUI. What am I doing wrong?

public void SetPgn(string pgn)
{
board.LoadPosition("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
boardUI.UpdatePosition(board);
boardUI.ResetSquareColours();
SetBoardPerspective();

        pgn = ExtractMovesFromPGN(pgn);
        pgn.Trim();
        Console.WriteLine(pgn);
        string[] moveList = pgn.Split(' ');

        foreach (string moveString in moveList)
        {
            MoveGenerator moveGenerator = new();
            var moves = moveGenerator.GenerateMoves(board);
            foreach (var move in moves)
            {
                if (moveString.Equals(MoveUtility.GetMoveNameSAN(move, board)))
                {
                    Console.WriteLine(moveString);
                    PlayMove(move); // CRASH
                    board.MakeMove(move); 
                    break;
                }
            }
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant