2021-04-03 17:33:59 -04:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
|
|
|
|
my $PAD_EVEN = " ";
|
|
|
|
my $PAD_ODD = " ";
|
|
|
|
|
|
|
|
my $HEX_1 = '-/--\-';
|
|
|
|
my $HEX_2 = '| __ |';
|
|
|
|
my $HEX_3 = '| |';
|
|
|
|
|
2021-04-03 18:18:24 -04:00
|
|
|
my $PREF_1 = substr($HEX_1, -2, 2);
|
2021-04-03 17:33:59 -04:00
|
|
|
my $PREF_2 = ' ';
|
|
|
|
my $PREF_3 = ' ';
|
|
|
|
|
2021-04-03 18:18:24 -04:00
|
|
|
my $TRAIL_1 = substr($HEX_1, 0, 1);
|
|
|
|
my $TRAIL_2 = substr($HEX_1, -1, 1);
|
|
|
|
my $TRAIL_3 = substr($HEX_1, 0, 2);
|
|
|
|
|
2021-04-03 17:33:59 -04:00
|
|
|
# Pieces
|
|
|
|
my $MG_A = 0; # Apprentice
|
|
|
|
my $MG_I = 1; # Iron Maiden
|
|
|
|
my $MG_N = 2; # Nekomata
|
|
|
|
my $MG_IT = 3; # Ittan-Momen
|
|
|
|
my $MG_H = 4; # Harpy
|
|
|
|
my $MG_S = 5; # Slime
|
|
|
|
my $MG_RC = 6; # Redcap
|
|
|
|
my $MG_RO = 7; # Red Oni
|
|
|
|
my $MG_HS = 8; # Holstaur
|
|
|
|
my $MG_B = 9; # Blue Oni
|
|
|
|
my $MG_P = 10; # Preistess
|
|
|
|
my $MG_IM = 11; # Imp
|
|
|
|
my $MG_F = 12; # False Angel
|
|
|
|
my $MG_QS = 13; # Queen slime
|
|
|
|
my $MG_AU = 14; # Automaton
|
|
|
|
my $MG_SY = 15; # Sylph
|
|
|
|
my $MG_Q = 16; # Queen
|
|
|
|
|
|
|
|
my %AXIS = (
|
|
|
|
"A" => 1,
|
|
|
|
"B" => 2,
|
|
|
|
"C" => 3,
|
|
|
|
"D" => 4,
|
|
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1],
|
|
|
|
[ 1, 0],
|
|
|
|
[ 1,-1]
|
|
|
|
],
|
|
|
|
$MG_SY => [
|
|
|
|
[-4, 4],
|
|
|
|
[-3, 3],
|
|
|
|
[-3, 2],
|
|
|
|
[-1,-2],
|
|
|
|
[ 0,-2],
|
|
|
|
[ 0,-3],
|
|
|
|
[ 0, 3],
|
|
|
|
[ 0, 4],
|
|
|
|
[ 1, 2],
|
|
|
|
[ 3,-2],
|
|
|
|
[ 3,-3],
|
|
|
|
[ 4,-4]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
# Special cells
|
|
|
|
my $EMPTY_CELL = 900;
|
|
|
|
|
|
|
|
my %board;
|
|
|
|
|
|
|
|
|
|
|
|
sub disp_1(){
|
|
|
|
return $HEX_1
|
|
|
|
}
|
|
|
|
|
|
|
|
sub disp_2(){
|
|
|
|
return $HEX_2
|
|
|
|
}
|
|
|
|
|
|
|
|
sub disp_3(){
|
|
|
|
return $HEX_3;
|
|
|
|
}
|
|
|
|
|
2021-04-03 18:18:24 -04:00
|
|
|
sub disp_x_axis($$$$){
|
2021-04-03 17:33:59 -04:00
|
|
|
my ($s0, $s1, $s2, $r0) = @_;
|
|
|
|
my $n0;
|
|
|
|
|
|
|
|
$n0 = length($r0);
|
|
|
|
|
|
|
|
$s0 = $r0 % 2 == 1 ? $PAD_ODD : $PAD_EVEN.$PREF_1;
|
|
|
|
$s1 = $r0 % 2 == 1 ? $PAD_ODD : $PAD_EVEN.$PREF_2;
|
|
|
|
$s1 =~ s/^ {$n0}/$r0/;
|
|
|
|
$s2 = $r0 % 2 == 1 ? $PAD_ODD : $PAD_EVEN.$PREF_3;
|
|
|
|
|
|
|
|
return ($s0, $s1, $s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub add_cell($$$$$){
|
|
|
|
my ($s0, $s1, $s2, $r0, $c0) = @_;
|
|
|
|
|
|
|
|
$s0 .= disp_1();
|
|
|
|
$s1 .= disp_2();
|
|
|
|
$s2 .= disp_3();
|
|
|
|
|
|
|
|
return ($s0, $s1, $s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub disp_0($){
|
|
|
|
my $r0;
|
|
|
|
|
|
|
|
my ($s0, $s1, $s2);
|
|
|
|
|
|
|
|
$r0 = shift;
|
|
|
|
|
2021-04-03 18:18:24 -04:00
|
|
|
($s0, $s1, $s2) = disp_x_axis($s0, $s1, $s2, $r0);
|
2021-04-03 17:33:59 -04:00
|
|
|
for my $i (1..11){
|
|
|
|
($s0, $s1, $s2) = add_cell($s0, $s1, $s2, $r0, $i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $s0."\n".$s1."\n".$s2."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub disp_row($){
|
2021-04-03 18:18:24 -04:00
|
|
|
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;
|
2021-04-03 17:33:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub disp_board(){
|
2021-04-03 18:18:24 -04:00
|
|
|
my $b;
|
|
|
|
|
2021-04-03 17:33:59 -04:00
|
|
|
for my $i (map {11-$_+1} (1..11)) {
|
2021-04-03 18:18:24 -04:00
|
|
|
$b .= disp_row($i);
|
2021-04-03 17:33:59 -04:00
|
|
|
}
|
2021-04-03 18:18:24 -04:00
|
|
|
$b =~ s/$TRAIL_1$TRAIL_3\n/\n/m;
|
|
|
|
printf("%s", $b);
|
2021-04-03 17:33:59 -04:00
|
|
|
|
2021-04-03 18:18:24 -04:00
|
|
|
}
|
2021-04-03 17:33:59 -04:00
|
|
|
|
|
|
|
sub cell_index($){
|
|
|
|
my ($chr1, $chr2) = (split(//, $_[0]));
|
|
|
|
return ($AXIS{$chr1}, $chr2);
|
|
|
|
}
|
|
|
|
|
|
|
|
%board = map {
|
|
|
|
$_ => $EMPTY_CELL
|
|
|
|
} map {
|
|
|
|
my $l0;
|
|
|
|
$l0 = $_;
|
|
|
|
(map {$l0.$_} ("1".."11"))
|
|
|
|
} ("A".."K");
|
|
|
|
|
2021-04-03 18:18:24 -04:00
|
|
|
disp_board();
|
2021-04-03 17:33:59 -04:00
|
|
|
|
|
|
|
# disp_0("C1");
|
|
|
|
# printf(">>%s, %s\n", cell_index("C1"));
|