lpst.pl - added a second and third shade. refactored shades to use a hash

This commit is contained in:
gashapwn 2021-04-04 15:22:37 +00:00
parent b2165befe6
commit c8e8946a5b

107
lpst.pl
View File

@ -5,11 +5,14 @@ use strict;
use utf8;
my $XBOX_CHR = chr(0x2573);
my $SHADE_CHR = chr(0x2591);
my $X_BOX_CHR = chr(0x2573);
my $GRAY_BOX_CHR = chr(0x2591);
my $ALT_US = chr(0x2017);
my $ALT_PIPE = chr(0x2016);
my $SHADE_1_CHR = $GRAY_BOX_CHR;
my $SHADE_2_CHR = $X_BOX_CHR;
my $PAD_AXIS = " ";
my $PAD_EVEN = " ";
my $PAD_ODD = " ";
@ -18,15 +21,20 @@ my $HEX_1 = '-/--\-';
my $HEX_2 = '| __ |';
my $HEX_3 = '| |';
my $HEX_S_1 = '-/--\-';
my $HEX_S_2 = sprintf("|%s==%s|", $SHADE_CHR, $SHADE_CHR);
my $HEX_S_3 = sprintf("|%s%s%s%s|", $SHADE_CHR, $SHADE_CHR, $SHADE_CHR, $SHADE_CHR);
# my $HEX_S_1 = '-/--\-';
# my $HEX_S_2 = '|'.$SHADE_CHR.'__'.$SHADE_CHR.'|';
# my $HEX_S_3 = '|'.$SHADE_CHR.$SHADE_CHR.$SHADE_CHR.$SHADE_CHR.'|';
my $HEX_S1_1 = '-/--\-';
my $HEX_S1_2 = sprintf("|%s%s%s%s|", $SHADE_1_CHR, $SHADE_1_CHR, $SHADE_1_CHR, $SHADE_1_CHR);
my $HEX_S1_3 = sprintf("|%s%s%s%s|", $SHADE_1_CHR, $SHADE_1_CHR, $SHADE_1_CHR, $SHADE_1_CHR);
my $HL_1 = "|_____";
my $HL_2 = $ALT_PIPE.$ALT_US.$ALT_US.$ALT_US.$ALT_US.$ALT_US;
my $HEX_S2_1 = '-/--\-';
my $HEX_S2_2 = sprintf("|%s%s%s%s|", $SHADE_2_CHR, $SHADE_2_CHR, $SHADE_2_CHR, $SHADE_2_CHR);
my $HEX_S2_3 = sprintf("|%s%s%s%s|", $SHADE_2_CHR, $SHADE_2_CHR, $SHADE_2_CHR, $SHADE_2_CHR);
my $HEX_S3_1 = '-/--\-';
my $HEX_S3_2 = sprintf("|%s%s%s%s|", $SHADE_2_CHR, $SHADE_2_CHR, $SHADE_1_CHR, $SHADE_1_CHR);
my $HEX_S3_3 = sprintf("|%s%s%s%s|", $SHADE_2_CHR, $SHADE_2_CHR, $SHADE_1_CHR, $SHADE_1_CHR);
my $HL_1 = "|____ ";
my $HL_2 = $ALT_PIPE.$ALT_US.$ALT_US.$ALT_US.$ALT_US." ";
my $SUB_CHR = "_";
my $ALT_SUB_CHR = "=";
@ -49,8 +57,8 @@ my $MG_IT = "It"; # Ittan-Momen
my $MG_H = "H"; # Harpy
my $MG_S = "S"; # Slime
my $MG_RC = "Rc"; # Redcap
my $MG_RO = "Hs"; # Red Oni
my $MG_HS = "Ro"; # Holstaur
my $MG_HS = "Hs"; # Holstaur
my $MG_RO = "Ro"; # Red Oni
my $MG_B = "B"; # Blue Oni
my $MG_P = "P"; # Preistess
my $MG_IM = "Im"; # Imp
@ -123,7 +131,7 @@ my %MOVE = (
[-3, 2], [-1,-2], [ 1, 2], [ 3,-2]
],
$MG_RC => [
[-1, 0], [-2, 0], [ 0, 1], [ 0, 2]
[-1, 0], [-2, 0], [ 1, 0], [ 2, 0]
],
$MG_S => [
[-1, 1], [-2, 2], [ 0, 1], [ 0, 2],
@ -136,7 +144,7 @@ my %MOVE = (
[-1, 1], [ 0, 1], [ 1, 1], [ 1,-2]
],
$MG_B => [
[-1, 1], [ 0, 1], [ 0,-2], [ 1,-2]
[-1, 1], [ 0, 1], [ 0,-2], [ 2,-2]
],
$MG_P => [
[-4, 2], [-2, 1], [-2,-2], [-1,-1],
@ -144,7 +152,7 @@ my %MOVE = (
],
$MG_IM => [
[-2, 1], [-1,-1], [-1, 2], [ 1, 1],
[ 1,-1], [ 1,-2], [ 2,-1]
[ 1,-1], [ 2,-1]
],
$MG_F => [
[-1, 0], [-1, 1], [ 0, 1], [ 0,-1],
@ -162,7 +170,7 @@ my %MOVE = (
],
$MG_SY => [
[-4, 4], [-3, 3], [-3, 2], [-1,-2],
[ 0,-2], [ 0,-3], [ 0, 3], [ 0, 4],
[ 0,-4], [ 0,-3], [ 0, 3], [ 0, 4],
[ 1, 2], [ 3,-2], [ 3,-3], [ 4,-4]
]
);
@ -171,15 +179,19 @@ my %MOVE = (
my $EMPTY_CELL = "_";
# Shade enum
my $SHADED_ENUM = 1;
my $SHADE_3_ENUM = 3;
my $SHADE_2_ENUM = 2;
my $SHADE_1_ENUM = 1;
my $EMPTY_ENUM = 0;
my %SHADE = (
$SHADED_ENUM => [$HEX_S_1, $HEX_S_2, $HEX_S_3],
$SHADE_1_ENUM => [$HEX_S1_1, $HEX_S1_2, $HEX_S1_3],
$SHADE_2_ENUM => [$HEX_S2_1, $HEX_S2_2, $HEX_S2_3],
$SHADE_3_ENUM => [$HEX_S3_1, $HEX_S3_2, $HEX_S3_3],
$EMPTY_ENUM => [$HEX_1, $HEX_2, $HEX_3]
);
my @sc0 = ();
my %sc = ();
my %board;
# Display pieces
@ -193,17 +205,22 @@ sub f_1($$$){
my $s0;
$p =~ s/($P1|$P2)$DIV//;
$p =~ s/$EMPTY_CELL//;
$p .= "__" if length($p) < 1;
# $p =~ s/$EMPTY_CELL//;
# $p .= "__" if length($p) < 1;
$p .= "_" if length($p) < 2;
$s0 = $hex;
$s0 =~ s/$SUB_CHR{1,2}/$p/;
if ($p eq "__"){
$s0 =~ s/$ALT_SUB_CHR{1,2}/$SHADE_CHR$SHADE_CHR/;
}else{
$p =~ s/_/$SHADE_CHR/;
$s0 =~ s/$ALT_SUB_CHR{1,2}/$p/;
unless($p eq "__"){
substr($s0, 2,2) = $p;
}
# if ($p eq "__"){
# $s0 =~ s/$ALT_SUB_CHR{1,2}/$SHADE_1_CHR$SHADE_1_CHR/;
# }else{
# # $p =~ s/_/$SHADE_1_CHR/;
# $s0 =~ s/$ALT_SUB_CHR{1,2}/$p/;
# }
if($c0 % 2 == 0){
$s0 =~ s/$SUB_CHR/$BLANK_CELL_CHR/g;
@ -215,15 +232,21 @@ sub f_1($$$){
# Display shade
#==================================================
sub shade_cell($){
sub shade_cell($$){
my $not = shift;
push(@sc0, $not) unless shade_t($not);
my $en = shift;
$sc{$not} = $en unless (grep /^$not$/, keys(%sc));
}
sub shade_t($){
my $not = shift;
return $SHADED_ENUM if grep /^$not$/, @sc0;
return $sc{$not} if (grep /^$not$/, keys(%sc));
return $EMPTY_ENUM;
# return $SHADE_1_ENUM if grep /^$not$/, @sc0;
# return $SHADE_2_ENUM if grep /^$not$/, @sc1;
# return $EMPTY_ENUM;
}
sub get_shade_chr($){
@ -304,11 +327,6 @@ sub add_cell($$$$$){
$s1 .= disp_2($r0, $c0);
$s2 .= disp_3($r0, $c0);
# if($c0 % 2 == 0){
# $s0 =~ s/ /$SHADE_CHR/g;
# $s1 =~ s/ /$SHADE_CHR/g;
# $s2 =~ s/ /$SHADE_CHR/g;
# }
return ($s0, $s1, $s2);
}
@ -471,9 +489,13 @@ sub calc_move($$){
$x_shift = $mov->[0];
# make x_shift adjustment
$ni = $y_shift != 0 ? ($y_shift / ($y_shift * -1)) : -1;
$ni *= -1;
$n0 = ($r0 + 1) % 2;
$ni = $y_shift != 0 ? ($y_shift / abs($y_shift)) : 1;
# $ni *= -1;
# moving down: $ni == -1 want value of 0
# moving up: $ni == +1 want value of 1
$n0 = ($r0 + (($ni + 1)/2) ) % 2;
$x_shift += int(($y_shift + ($n0 * $ni)) / 2);
return apply_shift($not, [$x_shift, $y_shift]);
@ -496,12 +518,15 @@ binmode(STDOUT, ":utf8");
}(1...11);
my $m1 = "E6";
my $c1 = $MG_A;
my $c1 = $MG_SY;
$board{$m1} = $P1.$DIV.$c1;
# for my $mv (@{$MOVE{$c1}}){
# printf("%s\n", calc_move($m1, $mv));
# }
for my $mv (@{$MOVE{$c1}}){
shade_cell(calc_move($m1, $mv), $SHADE_1_ENUM);
}
disp_board();