From 9e89588b7a4735aecb3a500bdb519457de2a0682 Mon Sep 17 00:00:00 2001 From: gashapwn Date: Sun, 4 Apr 2021 20:51:47 +0000 Subject: [PATCH] lpst.pl - shade_cell handles movement patterns exceeding the bounds of the board --- lpst.pl | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/lpst.pl b/lpst.pl index 5f76632..7572c84 100644 --- a/lpst.pl +++ b/lpst.pl @@ -173,7 +173,10 @@ my %MOVE = ( [ 0,-4], [ 0,-3], [ 0, 3], [ 0, 4], [ 1, 2], [ 3,-2], [ 3,-3], [ 4,-4] ] -); + ); + +my %BLOCK = ( + ); # Special cells my $EMPTY_CELL = "_"; @@ -191,6 +194,8 @@ my %SHADE = ( $EMPTY_ENUM => [$HEX_1, $HEX_2, $HEX_3] ); +my $ERR_C_1 = -1; + my %sc = (); my %board; @@ -457,7 +462,8 @@ sub apply_shift($$){ $r0 += $my_shift->[0]; $c0 += $my_shift->[1]; - die "cell index [$r0, $c0]: out of bound exception" if $r0 > 11 or $c0 > 11 or $r0 < 1 or $c0 < 1; + # die "cell index [$r0, $c0]: out of bound exception" if $r0 > 11 or $c0 > 11 or $r0 < 1 or $c0 < 1; + return $ERR_C_1 if $r0 > 11 or $c0 > 11 or $r0 < 1 or $c0 < 1; return cell_index_rev($r0, $c0); } @@ -498,17 +504,22 @@ sub calc_move($$){ sub shade_move($){ my $not = shift; my $c1; + my @mv1; + my @mv2; $c1 = cell_pi($not); - for my $mv (@{$MOVE{$c1}}){ - shade_cell(calc_move($not, $mv), $SHADE_1_ENUM); - } -} -# sub shade_block(){ + @mv1 = @{$MOVE{$c1}}; + @mv2 = grep { + $_ ne $ERR_C_1 + } map { + calc_move($not, $_) + } @mv1; -# } - + for my $mv (@mv2){ + shade_cell($mv, $SHADE_1_ENUM); + } +} # Main starts here! binmode(STDOUT, ":utf8"); @@ -525,7 +536,8 @@ binmode(STDOUT, ":utf8"); $AXIS_RV{$_} }(1...11); -my $m1 = "F7"; +# my $m1 = "F7"; +my $m1 = "A1"; my $c1 = $MG_QS; $board{$m1} = $P1.$DIV.$c1;