From 700e0364b385dd76948462d2d19ae7617d0aa051 Mon Sep 17 00:00:00 2001 From: gashapwn Date: Mon, 5 Apr 2021 02:59:24 +0000 Subject: [PATCH] lpst.pl - get_block_cell() returns all cells being blocked by pieces in play --- lpst.pl | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/lpst.pl b/lpst.pl index b2c02a2..a1a6183 100644 --- a/lpst.pl +++ b/lpst.pl @@ -376,6 +376,7 @@ sub shade_cell($$){ $sc{$not} = $en unless (grep /^$not$/, keys(%sc)); } +# TODO rename/rethink these 3 functions sub shade_t($){ my $not = shift; return $sc{$not} if (grep /^$not$/, keys(%sc)); @@ -574,6 +575,44 @@ sub disp_board(){ # Caclulate movement #================================================== + +# TODO: rename / rethink these 4 functions +sub gm1($){ + my $not = shift; + my $pi; + + $pi = cell_pi($not); + + if($pi){ + return gm2($pi); + } + return (); +} +sub gm2(){ + my $pi = shift; + return grep { + $_ if ($_->{"type"} & $MOVE_ENUM) eq $MOVE_ENUM + } @{$MOVE{$pi}} +} + +sub gb1($){ + my $not = shift; + my $pi; + + $pi = cell_pi($not); + + if($pi){ + return gb2($pi); + } + return (); +} +sub gb2($){ + my $pi = shift; + return grep { + $_ if ($_->{"type"} & $BLOCK_ENUM) eq $BLOCK_ENUM + } @{$MOVE{$pi}} +} + sub not_split($$){ my ($not, $i0) = (shift, shift); return (split(/$DIV/, $board{$not}))[$i0]; @@ -666,20 +705,20 @@ sub shade_mvmt($$){ @mv1 = grep { ($_->{"type"} & $en) eq $_->{"type"} } @{$MOVE{$c1}}; - @mv1 = find_all_mov(\@mv1, $not); + @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); -# } +sub get_block_cell(){ + return map { + $_->[0] + } map { + ( find_all_mov([gb1($_)], $_) ); + } keys(%board); +} @@ -708,8 +747,12 @@ my $c2 = $MG_A; $board{$m1} = $P1.$DIV.$c1; $board{$m2} = $P1.$DIV.$c2; -shade_mvmt($m1, $MOVBLOCK_ENUM); +for my $el (get_block_cell()){ + printf("%s\n", $el); +} + +shade_mvmt($m1, $MOVBLOCK_ENUM); disp_board();