lpst.pl - get_block_cell() returns all cells being blocked by pieces in play

This commit is contained in:
gashapwn 2021-04-05 02:59:24 +00:00
parent e48b5573f9
commit 700e0364b3

61
lpst.pl
View File

@ -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();