PGN reader

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

ironchess

PGN reader

Post by ironchess »

I am trying to get started on a program that reads PGN files, lets users enter moves and create their own PGN files.

How do I get started on this? Do you know of any sites where I can learn how to do this and use as a guide?

Thank you.
Harald
Posts: 318
Joined: Thu Mar 09, 2006 1:07 am

Re: PGN reader

Post by Harald »

ironchess wrote:I am trying to get started on a program that reads PGN files, lets users enter moves and create their own PGN files.

How do I get started on this? Do you know of any sites where I can learn how to do this and use as a guide?

Thank you.
Certainly you have googled, read and understood the PGN format.
http://www.very-best.de/pgn-spec.htm
Otherwise you should have asked for help on this.
So this can't be your problem.

You are also very experienced in your favourite programming language.
Whatever that is. Otherwise you would have told us about that or asked
further questions.

And last not least you have a clear plan what kind of GUI your program
should have, if any, or do you really believe we can guess this?

If you think you get some help from a few hundred lines of Python code
of a simple PGN reader without GUI then ask for it and I will post it.
By accident I have written this code but do not use it very much.

Harald
User avatar
ilari
Posts: 750
Joined: Mon Mar 27, 2006 7:45 pm
Location: Finland

Re: PGN reader

Post by ilari »

I think everyone and their dog has written a PGN parser at least once, it's not that difficult. But do you need to write this tool by yourself? I think any decent chess GUI is already able to do what you described.
ironchess

Re: PGN reader

Post by ironchess »

I want to learn how to write a program like ChessPad. The problem I'm facing is how to get started on this. I know there's hundreds of programs out there that can perform this function but the purpose of this endeavor is to learn how to do it myself.

I really don't know whether I should use somebody else's GUI or make my own. Since the goal of this project is to learn I think I should write the GUI myself. But will this make the project much more time-consuming? Is there an easy, basic GUI or site out there that can help me learn?

I see you talking about types of GUIs. What types of GUIs there are and which one do you recommend for me?

As far as the programming language goes, I will be writing this PGN reader in C. However, that programs that you recommend to me don't have to be in C.
User avatar
cms271828
Posts: 316
Joined: Wed Apr 12, 2006 10:47 pm

Re: PGN reader

Post by cms271828 »

Its kinda common sense, I wrote one, I basically extracted all the moves from a game, then you play them out on a board.

You have to play them out, cause Nd5 means the knight could come from 8 possible squares.

Also one part I messed up on..
Say the move is Rf2 and theres a white rook on f1 and a2, but the f1 rook is pinned.

Then the move won't be written Raf2 cause clearly it must be the a2 rook that moves, so you need to eliminate illegal moves.
Colin
Harald
Posts: 318
Joined: Thu Mar 09, 2006 1:07 am

Re: PGN reader

Post by Harald »

ironchess wrote:I want to learn how to write a program like ChessPad. The problem I'm facing is how to get started on this. I know there's hundreds of programs out there that can perform this function but the purpose of this endeavor is to learn how to do it myself.

I really don't know whether I should use somebody else's GUI or make my own. Since the goal of this project is to learn I think I should write the GUI myself. But will this make the project much more time-consuming? Is there an easy, basic GUI or site out there that can help me learn?

I see you talking about types of GUIs. What types of GUIs there are and which one do you recommend for me?

As far as the programming language goes, I will be writing this PGN reader in C. However, that programs that you recommend to me don't have to be in C.
Sorry for the harsh tone of my first post. But now we have a little more information.

You could start with a few basic functions and data types, perhaps in a console program.
A board representation, generate_moves(), make_move(), undo_move(), in_check() and so on.
Read a position from a FEN string, write a FEN string.
Understand SAN (standard algebraic notation), read and write a move in SAN.
Have a data structure for a game in PGN.
Read a game as PGN. Recognise all kinds of comments in it. Write a game as PGN.
Read a PGN file with lots of games. Find the start of each game in the file.

Draw the big program structure, windows, dialogue boxes and menues on paper.
Select an existing GUI framework (Qt, WxWidgets) and learn to use it.
Sorry, the last time I did this was with GEM on AtariST. I am not an expert here.
Using a GUI may be very time consuming.

C is a very good choice for a chess related program and it is very common.
C++ is like a superset of C with many more possibilities. I use it
myself to get classes and other comfortable stuff but I don't go to the
deepest, fanciest and extreme strange things of C++.
Python is a language very easy to learn, to start with and to add a GUI to it.
It may not be fast enough to compete with top rated chess engines.

Harald
Michael Sherwin
Posts: 3196
Joined: Fri May 26, 2006 3:00 am
Location: WY, USA
Full name: Michael Sherwin

Re: PGN reader

Post by Michael Sherwin »

Harald wrote:
ironchess wrote:I want to learn how to write a program like ChessPad. The problem I'm facing is how to get started on this. I know there's hundreds of programs out there that can perform this function but the purpose of this endeavor is to learn how to do it myself.

I really don't know whether I should use somebody else's GUI or make my own. Since the goal of this project is to learn I think I should write the GUI myself. But will this make the project much more time-consuming? Is there an easy, basic GUI or site out there that can help me learn?

I see you talking about types of GUIs. What types of GUIs there are and which one do you recommend for me?

As far as the programming language goes, I will be writing this PGN reader in C. However, that programs that you recommend to me don't have to be in C.
Sorry for the harsh tone of my first post. But now we have a little more information.

You could start with a few basic functions and data types, perhaps in a console program.
A board representation, generate_moves(), make_move(), undo_move(), in_check() and so on.
Read a position from a FEN string, write a FEN string.
Understand SAN (standard algebraic notation), read and write a move in SAN.
Have a data structure for a game in PGN.
Read a game as PGN. Recognise all kinds of comments in it. Write a game as PGN.
Read a PGN file with lots of games. Find the start of each game in the file.

Draw the big program structure, windows, dialogue boxes and menues on paper.
Select an existing GUI framework (Qt, WxWidgets) and learn to use it.
Sorry, the last time I did this was with GEM on AtariST. I am not an expert here.
Using a GUI may be very time consuming.

C is a very good choice for a chess related program and it is very common.
C++ is like a superset of C with many more possibilities. I use it
myself to get classes and other comfortable stuff but I don't go to the
deepest, fanciest and extreme strange things of C++.
Python is a language very easy to learn, to start with and to add a GUI to it.
It may not be fast enough to compete with top rated chess engines.

Harald
Why Qt or WxWidgets? Why not a Microsoft Visual product or Borlands free C++ Builder? Python is simple (I do not know this) and a bit slow, however, just for the GUI part being a bit slow does not really matter does it? Qt is humongous, which stops me dead in my tracks, when I see something that is 100's of megabytes in size. DirectX is also huge but it is a very focused product with many books available that show how to do 2D graphics very simply. I could put up a chessboard in a windowed environment in which the pieces could be moved, in probably a long day.

I do not have the time and energy to throw darts to find a decently good (for me) GUI language. I just want something simple, fast enough, focused, reasonably small and well documented with lots of examples. If there are good 3rd party books written about it, then all the better.

Given my needs, what is best for me? :?
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
User avatar
smrf
Posts: 484
Joined: Mon Mar 13, 2006 11:08 am
Location: Klein-Gerau, Germany

Re: PGN reader

Post by smrf »

Michael Sherwin wrote:
Harald wrote:Given my needs, what is best for me? :?
The free C++ Builder (Turbo C++) seems no longer to be available this days. It has been welcomed, that its created releases mostly seem to work fine also under Linux/Wine or MacOSX/Crossover. My SMIRF GUI with its multivariant engine might be a working example for that. Anyway, it always would make sense when developing on MS Windows systems also to check out, how to make the created solution work under Wine / Crossover, too.
wgarvin
Posts: 838
Joined: Thu Jul 05, 2007 5:03 pm
Location: British Columbia, Canada

Re: PGN reader

Post by wgarvin »

Michael Sherwin wrote:I do not have the time and energy to throw darts to find a decently good (for me) GUI language. I just want something simple, fast enough, focused, reasonably small and well documented with lots of examples. If there are good 3rd party books written about it, then all the better.

Given my needs, what is best for me? :?
Another option is to download the free version of Microsoft Visual C# Express Edition and write the GUI in C#. WinForms is far easier to use than anything from the win32 days. Its not "portable" (or at least I have no idea what level of support Mono has for it), but with GUI toolkits you can usually have at most two out of three: portable, simple and useful. WinForms is simple and useful (as opposed to Qt and wx which are portable and useful, or something like TCL which is portable and simple...)

Someone with some knowledge of C# and WinForms could build a functional GUI app with a bunch of buttons, menus, widgets etc. in less than an hour. Someone who's never used it before could probably do the same in a few hours. The designer lets you drag and drop widgets where you want them, and edit all of their properties. It generates C# code for them so that you can access them programmatically. It helps you create methods to handle the various events from the widgets that you're interested in, and you can then put whatever code you want into them.
Harald
Posts: 318
Joined: Thu Mar 09, 2006 1:07 am

Re: PGN reader

Post by Harald »

Michael Sherwin wrote:Why Qt or WxWidgets? Why not a Microsoft Visual product or Borlands free C++ Builder?
How do you know that his OS is Windows?