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
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');