diff --git a/.gitignore b/.gitignore index e4e5f6c..2328aa9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -*~ \ No newline at end of file +*~ +p[0-9].pl +p[0-9][0-9].pl \ No newline at end of file diff --git a/lpst.pl b/lpst.pl index f3542f0..e102a83 100644 --- a/lpst.pl +++ b/lpst.pl @@ -11,10 +11,14 @@ my $HEX_1 = '-/--\-'; my $HEX_2 = '| __ |'; my $HEX_3 = '| |'; -my $PREF_1 = '\-'; +my $PREF_1 = substr($HEX_1, -2, 2); my $PREF_2 = ' '; my $PREF_3 = ' '; +my $TRAIL_1 = substr($HEX_1, 0, 1); +my $TRAIL_2 = substr($HEX_1, -1, 1); +my $TRAIL_3 = substr($HEX_1, 0, 2); + # Pieces my $MG_A = 0; # Apprentice my $MG_I = 1; # Iron Maiden @@ -207,7 +211,7 @@ sub disp_3(){ return $HEX_3; } -sub add_pad($$$$){ +sub disp_x_axis($$$$){ my ($s0, $s1, $s2, $r0) = @_; my $n0; @@ -238,7 +242,7 @@ sub disp_0($){ $r0 = shift; - ($s0, $s1, $s2) = add_pad($s0, $s1, $s2, $r0); + ($s0, $s1, $s2) = disp_x_axis($s0, $s1, $s2, $r0); for my $i (1..11){ ($s0, $s1, $s2) = add_cell($s0, $s1, $s2, $r0, $i); } @@ -247,15 +251,35 @@ sub disp_0($){ } sub disp_row($){ - return disp_0(shift); + my $row; + my $r0; + + $r0 = shift; + + $row = disp_0($r0); + # Trim the start of the first line + $row =~ s/$TRAIL_1/ /; + if($r0 % 2 == 1){ + # Trim the end of the first line + $row =~ s/\n/$TRAIL_3\n/ + }else{ + # Trim the end of the last line + $row =~ s/$TRAIL_2\n/ \n/m; + } + + return $row; } sub disp_board(){ + my $b; + for my $i (map {11-$_+1} (1..11)) { - printf("%s", disp_row($i)); + $b .= disp_row($i); } -} + $b =~ s/$TRAIL_1$TRAIL_3\n/\n/m; + printf("%s", $b); +} sub cell_index($){ my ($chr1, $chr2) = (split(//, $_[0])); @@ -270,8 +294,7 @@ sub cell_index($){ (map {$l0.$_} ("1".."11")) } ("A".."K"); -disp_board() +disp_board(); # disp_0("C1"); - # printf(">>%s, %s\n", cell_index("C1"));