diff --git a/lpst.pl b/lpst.pl index ac80cae..b2c02a2 100644 --- a/lpst.pl +++ b/lpst.pl @@ -574,14 +574,19 @@ sub disp_board(){ # Caclulate movement #================================================== +sub not_split($$){ + my ($not, $i0) = (shift, shift); + return (split(/$DIV/, $board{$not}))[$i0]; +} + sub cell_pi($){ my $not = shift; - return (split(/$DIV/, $board{$not}))[1] + return not_split($not, 1); } sub cell_pl($){ my $not = shift; - return (split(/$DIV/, $board{$not}))[0] + return not_split($not, 0); } sub cell_index_rev($$){ @@ -637,16 +642,21 @@ sub calc_move($$){ $n0 = ($r0 + (($ni + 1)/2) ) % 2; $x_shift += int(($y_shift + ($n0 * $ni)) / 2); - { - my $app_shift = apply_shift($not, [$x_shift, $y_shift]); - return $app_shift; - } - # return apply_shift($not, [$x_shift, $y_shift]); + return apply_shift($not, [$x_shift, $y_shift]); } +sub find_all_mov($$){ + return grep { + $_ if $_->[0] ne $ERR_C_1; + } map { + [ + calc_move($_[1], $_->{"mov"}), + $_->{"type"} + ] + } @{$_[0]}; +} - -sub shade_move($$){ +sub shade_mvmt($$){ my ($not, $en) = (shift, shift); my $c1; my @mv1; @@ -654,22 +664,27 @@ sub shade_move($$){ $c1 = cell_pi($not); @mv1 = grep { - $_ if $_->[0] ne $ERR_C_1; - } map { - [ - calc_move($not, $_->{"mov"}), - $_->{"type"} - ] - } grep { ($_->{"type"} & $en) eq $_->{"type"} } @{$MOVE{$c1}}; + @mv1 = find_all_mov(\@mv1, $not); for my $mv (@mv1){ shade_cell($mv->[0], $mv->[1]); } } + + +# sub get_block_cell(){ +# map { +# cell_pi($_) +# } keys($board); +# } + + + # Main starts here! +#================================================== binmode(STDOUT, ":utf8"); # Creates a hash of the the form @@ -686,10 +701,14 @@ binmode(STDOUT, ":utf8"); # my $m1 = "F7"; my $m1 = "C10"; +my $m2 = "C3"; my $c1 = $MG_SY; +my $c2 = $MG_A; $board{$m1} = $P1.$DIV.$c1; -shade_move($m1, $MOVBLOCK_ENUM); +$board{$m2} = $P1.$DIV.$c2; + +shade_mvmt($m1, $MOVBLOCK_ENUM); disp_board();