Skip Menu |

This queue is for tickets about the Chess-Rep CPAN distribution.

Report information
The Basics
Id: 45257
Status: open
Priority: 0/
Queue: Chess-Rep

People
Owner: Nobody in particular
Requestors: jeremy.gardiner [...] btinternet.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Chess::Rep go_move bug : Moves on 'B' file are reported as illegal
Date: Thu, 23 Apr 2009 22:18:54 +0100
To: <bug-Chess-Rep [...] rt.cpan.org>
From: Jeremy Gardiner <jeremy.gardiner [...] btinternet.com>
Chess::Rep go_move bug : Moves on 'B' file are reported as illegal: perhaps parser is confusing with 'B' for Bishop? Workaround: put moves in lower case. Sample program below: use Chess::Rep; my $pos = Chess::Rep->new; $pos->go_move('B2-B3'); Result: Illegal move: B2-B3 at /Library/Perl/5.8.8/Chess/Rep.pm line 650. System: Chess::Rep 0.5 Perl v5.8.8 Mac OS X 10.5.6 Darwin Kernel Version 9.6.0
On Thu Apr 23 17:19:24 2009, jeremy.gardiner@btinternet.com wrote: Show quoted text
> Chess::Rep go_move bug : > > Moves on 'B' file are reported as illegal: perhaps parser is confusing with > 'B' for Bishop? Workaround: put moves in lower case.
Moves in lower case are probably preferable as FIDE's current (in effect from 1st July 2017) laws of chess require a-h and not A-H be used to specify files. As Chess::Rep is not strict about the notation it will accept and in order to avoid a breaking change, the attached fix is suggested. Two test cases have been added: a) A test case that worked with the 0.8 released code b) A test case which fails with the 0.8 released code but which passes with this fix applied. Otherwise, no testing has been done; this module is new to me and I have no substantial application yet using it. When I do, I expect to be using PGN input only. Giles
Subject: 45257-fix.diff
diff -r 2836735b9810 -r 8134e6737232 lib/Chess/Rep.pm --- a/lib/Chess/Rep.pm Sun May 27 04:56:01 2018 +1000 +++ b/lib/Chess/Rep.pm Sun May 27 05:44:52 2018 +1000 @@ -106,7 +106,7 @@ =head1 SYNOPSIS my $pos = Chess::Rep->new; - print $pos->get_fen; + print $pos->get_fen, "\n"; # use any decent notation to describe moves # the parser will read pretty much anything which isn't ambiguous @@ -590,27 +590,27 @@ $move = $color ? 'E1G1' : 'E8G8'; } - if ($move =~ s/^([PNBRQK])//) { - $piece = lc $1; - } + if ($move =~ s/^([PNBRQK]?)([a-h][1-8])[:x-]?([a-h][1-8])//i) { + + $piece = lc $1 if $1; + ($from, $to) = ($2, $3); - if ($move =~ s/^([a-h][1-8])[:x-]?([a-h][1-8])//i) { # great, no ambiguities + } elsif ($move =~ s/^([PNBRQK]?)([a-h])[:x-]?([a-h][1-8])//i) { - ($from, $to) = ($1, $2); - - } elsif ($move =~ s/^([a-h])[:x-]?([a-h][1-8])//i) { + $piece = lc $1 if $1; + $col = ord(uc $2) - 65; + $to = $3; - $col = ord(uc $1) - 65; - $to = $2; - - } elsif ($move =~ s/^([1-8])[:x-]?([a-h][1-8])//i) { + } elsif ($move =~ s/^([PNBRQK]?)([1-8])[:x-]?([a-h][1-8])//i) { - $row = ord($1) - 49; - $to = $2; + $piece = lc $1 if $1; + $row = ord($2) - 49; + $to = $3; - } elsif ($move =~ s/^[:x-]?([a-h][1-8])//i) { + } elsif ($move =~ s/^([PNBRQK]?)[:x-]?([a-h][1-8])//i) { - $to = $1; + $piece = lc $1 if $1; + $to = $2; } else { diff -r 2836735b9810 -r 8134e6737232 t/sangeneration.t --- a/t/sangeneration.t Sun May 27 04:56:01 2018 +1000 +++ b/t/sangeneration.t Sun May 27 05:44:52 2018 +1000 @@ -1,6 +1,6 @@ #!/usr/bin/perl -T -use Test::Simple tests => 6; +use Test::Simple tests => 8; use Chess::Rep; use Data::Dumper; @@ -41,3 +41,16 @@ $h = $pos->go_move('c5d4'); ok($h->{'san'} eq 'cxd4', 'Pawn capturing(2)'); + +# Bug 45257: working case +$pos->set_from_fen('rnbqknbr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKNBR w KQkq -'); +$h = $pos->go_move('b2-b4'); + +ok($h->{'san'} eq 'b4', 'Sokolsky Opening'); + +# Bug 45257: failing case (Chess-Rep-0.8) +# 'B2-B4' was the initial bug report; 'B2-b4' is sufficient +$pos->set_from_fen('rnbqknbr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKNBR w KQkq -'); +$h = $pos->go_move('B2-b4'); + +ok($h->{'san'} eq 'b4', 'Sokolsky Opening');
On Sat May 26 16:02:22 2018, giles.lean@pobox.com wrote: Show quoted text
> On Thu Apr 23 17:19:24 2009, jeremy.gardiner@btinternet.com wrote:
> > Chess::Rep go_move bug : > > > > Moves on 'B' file are reported as illegal: perhaps parser is > > confusing with > > 'B' for Bishop? Workaround: put moves in lower case.
> > Moves in lower case are probably preferable as FIDE's current (in > effect from 1st July 2017) laws of chess require a-h and not A-H be > used to specify files. > > As Chess::Rep is not strict about the notation it will accept and in > order to avoid a breaking change, the attached fix is suggested. > > Two test cases have been added: > a) A test case that worked with the 0.8 released code > b) A test case which fails with the 0.8 released code but which passes > with this fix applied. > > Otherwise, no testing has been done; this module is new to me and I > have no substantial application yet using it. When I do, I expect to > be using PGN input only. > > Giles
Ah, annoyance! There is a change to the POD documentation which is not necessary for this fix included in the diff. As I appear not to be able to delete the attachment and re-upload it, it's how it is. :-( Giles