From 8136c1e1916241545f5e475800eab4cb4aa47f10 Mon Sep 17 00:00:00 2001 From: gashapwn Date: Mon, 19 Apr 2021 00:26:00 +0000 Subject: [PATCH] LPST.pm - added fix for tricking notation test.pl - updated test cases --- LPST.pm | 18 ++++++++++++++---- test.pl | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/LPST.pm b/LPST.pm index 4770532..ec49a43 100644 --- a/LPST.pm +++ b/LPST.pm @@ -780,11 +780,20 @@ sub check_valid_cell($$){ # } keys %board; } -sub check_src_cell($$$){ - my ($self, $hx1, $apl) = (shift, shift, shift); +sub check_match_pi($$$$){ + my ($self, $hx1, $pi) = (shift, shift, shift); + my $hx2; + + $hx2 = $self->cell_pi($hx1); + die "$pi - Wrong piece notation for $hx1 should be $hx2" if $hx2 ne $pi; +} + +sub check_src_cell($$$$){ + my ($self, $hx1, $apl, $pi) = (shift, shift, shift, shift); $hx1 = uc $hx1; $self->check_nonempty_cell($hx1); + $self->check_match_pi($hx1, $pi); die "This cell is not owned by $apl" if $self->cell_pl($hx1) ne $apl; } @@ -867,11 +876,12 @@ sub ft_summon($$$){ sub mov($$$){ my ($self, $s0, $apl) = (shift, shift, shift); - my ($src, $dst) = $s0 =~ /([A-Za-z][0-9]{1,2})([A-Za-z][0-9]{1,2})$/; + my ($pi, $src, $dst) = $s0 =~ /([A-Za-z]){1,2}([A-Za-z][0-9]{1,2})([A-Za-z][0-9]{1,2})$/; + $src = uc $src; $dst = uc $dst; $self->check_valid_player($apl); - $self->check_src_cell($src, $apl); + $self->check_src_cell($src, $apl, $pi); $self->check_empty_cell($dst); $self->check_valid_mov($src, $dst); $self->{"board"}{$dst} = $self->cell_pl($src).$DIV.$self->cell_pi($src); diff --git a/test.pl b/test.pl index 5d22c2a..79479c7 100644 --- a/test.pl +++ b/test.pl @@ -31,7 +31,7 @@ $ns0 .= "A I H It N\n"; $ns0 .= "A I H It N\n"; $ns0 .= "Ac3*, Qd3*\n"; $ns0 .= "Ac11*, Qd11*\n"; - +$ns0 .= "Sc3c4"; sub roll_back($){