rajrakeshdr / pychess

Automatically exported from code.google.com/p/pychess
GNU General Public License v3.0
0 stars 0 forks source link

PyChess should be able to parse language encoded SAN and PGN #217

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Copy-pasted the beginnig of Leko-Griscsuk game into the edit box, then
started the game.
1.e4 e5 2.Hf3 Hc6 3.Fb5 a6 4.Fa4 Hf6 5.0-0 Fe7 6.Be1 b5 7.Fb3 0-0 8.a4 b4
9.d3 d6 10.Hbd2

Traceback (most recent call last):
  File "/home/tamas/svn/pychess/lib/pychess/Main.py", line 290, in
on_enter_game_notation_activate
    ionest.enterGameNotation ()
  File "/home/tamas/svn/pychess/lib/pychess/widgets/ionest.py", line 565,
in enterGameNotation
    game.loadAndStart (file, 0, -1, loader)
  File "/home/tamas/svn/pychess/lib/pychess/Utils/GameModel.py", line 221,
in loadAndStart
    chessfile.loadToModel(gameno, position, self)
  File "/home/tamas/svn/pychess/lib/pychess/Savers/pgn.py", line 133, in
loadToModel
    raise ValueError, ("Unable to parse PGN: %s\nat move %d\n" +
ValueError: Unable to parse PGN: e4 e5 f3 c6 b5 a6 a4 f6 0-0 e7 Be1 b5 b3
0-0 a4 b4 d3 d6 bd2
at move 4
Gave error: ("Bad SAN move 'b5'. No piece is able to move to b5. None None
Pawn 0  available moves: Na3 c3 Ne2 h3 Kxe2 f2 Bxe2 d3 c4+ b5 a6 Qxe2 axa3
b3 c3 d3+ g3 h3+ f4 a4+ b4 c4+ d4 g4+ h4
rnbqkbnr/pp1p1ppp/2p5/4p3/4P3/5P2/PPPP2PP/RNBQKBNR w KQkq - 0 3",)

Original issue reported on code.google.com by gbtami on 23 Sep 2007 at 11:43

GoogleCodeExporter commented 9 years ago
As far as I am aware, we have no support for parsing Hungarian san moves. I also
think it would be fairly difficult to implement, as some languages has multi 
letter
codes for some pieces.

But we might of course bring up a more sophisticated error dialog..
Or more sexy: Use a spelling checking framework, to put a red line under Hf3 
with Nf3
as a suggestion.

Original comment by lobais on 23 Sep 2007 at 5:20

GoogleCodeExporter commented 9 years ago
Yes, i missed this.
Anyhow, most languages use 1 letter code for pieces
(http://www.very-best.de/pgn-spec.htm#17.), so enhancing the PGN parser to 
support
the 1 letter case, can make happy the big part of the chess community :)

Original comment by gbtami on 23 Sep 2007 at 7:00

GoogleCodeExporter commented 9 years ago
That is right of course.

However in that case we need a way to specify the language of the file, as the 
same
letter can mean different pieces in different languages. Often we might be able 
to
guess it, but it is harder to implement, and risky.
I personally open a tons of english notated pgn's, so I wouldn't like PyChess to
expect them to be danish.

We could have a combo in enter notation and filechooser with language?.. Would 
create
some visual clutter though.
Or maybe only in enter notation. I really don't hope that anybody would put 
language
encoded data in a file meant to be computer readable. None the less I feer it.

Original comment by lobais on 23 Sep 2007 at 9:16

GoogleCodeExporter commented 9 years ago

Original comment by lobais on 23 Sep 2007 at 9:17

GoogleCodeExporter commented 9 years ago
I imagine, the "Enter game notation" best reason is not for pasting games from 
pgn
files (there is open menu for that), but for handwriting our own games 
notations for
analyze and store.
The pgn itself is a storage format and stores english piece letters by 
definition(or
de facto), so no need to support other language piece letters in pgn IMO. On the
other side, in enter game nonation box (_olnly_ there, and not in filechooser), 
we
can support locale letters for parsers. I can imagine a global setting in 
options menu:
"Use local piece letters in enter game notation", and if it was chosen, the 
parser
will use localReprSign instead of reprSign. Or maybe a flag icon, as used on 
most
keyboard swithcing applets on taskbar. (Eng/Loc flags in our case.)

Original comment by gbtami on 24 Sep 2007 at 7:17

GoogleCodeExporter commented 9 years ago
I don't think we need a preferences option. A combobox remembering the last 
value
chosen should be fine.

I'm not sure what you mean by a flag icon.

Original comment by lobais on 24 Sep 2007 at 1:52

GoogleCodeExporter commented 9 years ago
Combobox is a bit overcomplicating IMO, Most user wants to use only his native
notation and english.
The flag icon is a 2 state image area (button widget?). It starts as your native
country flag. Click. English flag. Click. Native flag.
We have flag images for all countries in svn already.

Original comment by gbtami on 24 Sep 2007 at 2:36

GoogleCodeExporter commented 9 years ago
You are right that a combobox of all languages would be hard to navigate due to 
the
many choices. On the other hand I don't think it is very intuitive what will 
happen
if you click a flag icon.

I'm not really sure how to implement it without further cluttering the gui. I 
can see
perhaps four ways:
 # A flag in the upper right corner
 # A right click menu option*
 # Two radiobuttons next to each other below the textview
 3 A combobox in the lower left corner* (can't see it fit anywhere else)

* The submenu and the combobox would have three items: Local, English and Other.
They'd all have an icon, and 'Other' would open a submenu or a dialog with the 
entire
supply of languages.

At the end of the day the flag icon (with a tooltip) might be the more simple 
way,
and if people want other languages they can translate the san by them selves.

Original comment by lobais on 24 Sep 2007 at 6:20

GoogleCodeExporter commented 9 years ago
That's agreed :)

Original comment by gbtami on 25 Sep 2007 at 9:15

GoogleCodeExporter commented 9 years ago
Committed a simple conversion code into enterGameNotation() in ionest.py (svn 
646).
Needs an UI element (flag icon) to make it live. Sorry, but i'm not familiar 
with
pygtk/glade yet :(

Original comment by gbtami on 29 Sep 2007 at 4:36

GoogleCodeExporter commented 9 years ago
The flag icon now works in svn 656. The only remaining issue is to handle 
notations
using untranslated locale (no pychess.po), or the flag icon locale not matching 
with
entered piece letters case. I mean to handle tracebaks like i'v pasted in 
Comment 1.

Original comment by gbtami on 2 Oct 2007 at 9:14

GoogleCodeExporter commented 9 years ago
Yes, we 1: Change the ValueError to a (selfdefined) ParsingError. 2: Catch the 
error.
3: Bring up an error dialog, and suggesting that the language could be wrong.

Btw. If you have english locale, will the flag button just switch between
english/english?

Original comment by lobais on 2 Oct 2007 at 9:18

GoogleCodeExporter commented 9 years ago
In 657 image button has 2 flags only for langs having .mo file.
For langs having no .mo i leave the us flag there, indicating the user have to 
enter
english piece letters. Is it acceptable this way?

Original comment by gbtami on 2 Oct 2007 at 10:28

GoogleCodeExporter commented 9 years ago
Sounds fine.
Shouldn't annoy anybody (except the fundamental anti patriots :))

Are you also on for the error catching?

Besides changing the error class, I guess it should just be a try catch around 
the
loadAndStart call in simpleLoadGame.
That will also catch bad pgn-opens though, so the error should probably be a 
little
more general.

IIRC the legal pgn before the error, is stilled parsed and opened, so the error
should just be informal.

Original comment by lobais on 2 Oct 2007 at 10:55

GoogleCodeExporter commented 9 years ago
Sorry, but i'm not to good enough on exception handling yet :(

Original comment by gbtami on 2 Oct 2007 at 6:33

GoogleCodeExporter commented 9 years ago
Error dialog is up in revision 663

Original comment by lobais on 3 Oct 2007 at 6:41

GoogleCodeExporter commented 9 years ago

Original comment by lobais on 5 Oct 2007 at 6:49