Skip Menu |

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

Report information
The Basics
Id: 74854
Status: new
Priority: 0/
Queue: Chess-Rep

People
Owner: Nobody in particular
Requestors: upi [...] apocalypse.rulez.org
Cc:
AdminCc:

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



Subject: Any move can promote
The go_move() sub doesn't properly validate the promote part of the move. For example, opening with e3=Q gives you a queen. Also, *not* providing a promote part in a move that would otherwise need to promote a pawn results in a board that is in an invalid state. Both of these are easily fixed with the following patch: --- a/Chess/Rep.pm Wed Feb 08 14:39:23 2012 +0100 +++ b/Chess/Rep.pm Fri Feb 10 17:50:36 2012 +0100 @@ -736,8 +736,11 @@ { my $promote_id; - if ($promote) { - $promote_id = PIECE_TO_ID->{lc $promote} | $color; + unless ($is_pawn && ($to_row == 0 || $to_row == 7)) { + $promote = undef; + } else { + $promote ||= 'Q'; + $promote_id = PIECE_TO_ID->{lc $promote} | $color; } my $tmp = $self->_move_piece($from_index, $to_index, $promote_id); $captured ||= $tmp;