2021-04-03 17:33:59 -04:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2021-04-03 22:38:20 -04:00
|
|
|
use utf8;
|
2021-04-03 17:33:59 -04:00
|
|
|
|
2021-04-04 11:22:37 -04:00
|
|
|
my $X_BOX_CHR = chr(0x2573);
|
|
|
|
my $GRAY_BOX_CHR = chr(0x2591);
|
2021-04-04 10:23:13 -04:00
|
|
|
my $ALT_US = chr(0x2017);
|
|
|
|
my $ALT_PIPE = chr(0x2016);
|
|
|
|
|
2021-04-04 11:22:37 -04:00
|
|
|
my $SHADE_1_CHR = $GRAY_BOX_CHR;
|
|
|
|
my $SHADE_2_CHR = $X_BOX_CHR;
|
|
|
|
|
2021-04-03 20:39:52 -04:00
|
|
|
my $PAD_AXIS = " ";
|
2021-04-03 17:33:59 -04:00
|
|
|
my $PAD_EVEN = " ";
|
|
|
|
my $PAD_ODD = " ";
|
|
|
|
|
|
|
|
my $HEX_1 = '-/--\-';
|
|
|
|
my $HEX_2 = '| __ |';
|
|
|
|
my $HEX_3 = '| |';
|
|
|
|
|
2021-04-04 11:22:37 -04:00
|
|
|
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 $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);
|
2021-04-03 22:38:20 -04:00
|
|
|
|
2021-04-04 11:22:37 -04:00
|
|
|
my $HL_1 = "|____ ";
|
|
|
|
my $HL_2 = $ALT_PIPE.$ALT_US.$ALT_US.$ALT_US.$ALT_US." ";
|
2021-04-03 22:38:20 -04:00
|
|
|
|
2021-04-03 20:39:52 -04:00
|
|
|
my $SUB_CHR = "_";
|
2021-04-04 10:23:13 -04:00
|
|
|
my $ALT_SUB_CHR = "=";
|
|
|
|
|
|
|
|
my $BLANK_CELL_CHR = $ALT_US;
|
2021-04-03 20:39:52 -04:00
|
|
|
|
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
|
2021-04-03 21:20:45 -04:00
|
|
|
my $MG_A = "A"; # Apprentice
|
|
|
|
my $MG_I = "I"; # Iron Maiden
|
|
|
|
my $MG_N = "N"; # Nekomata
|
|
|
|
my $MG_IT = "It"; # Ittan-Momen
|
|
|
|
my $MG_H = "H"; # Harpy
|
|
|
|
my $MG_S = "S"; # Slime
|
|
|
|
my $MG_RC = "Rc"; # Redcap
|
2021-04-04 11:22:37 -04:00
|
|
|
my $MG_HS = "Hs"; # Holstaur
|
|
|
|
my $MG_RO = "Ro"; # Red Oni
|
2021-04-03 21:20:45 -04:00
|
|
|
my $MG_B = "B"; # Blue Oni
|
|
|
|
my $MG_P = "P"; # Preistess
|
|
|
|
my $MG_IM = "Im"; # Imp
|
|
|
|
my $MG_F = "F"; # False Angel
|
|
|
|
my $MG_QS = "Qs"; # Queen slime
|
|
|
|
my $MG_AU = "Au"; # Automaton
|
|
|
|
my $MG_SY = "Sy"; # Sylph
|
|
|
|
my $MG_Q = "Q"; # Queen
|
2021-04-03 17:33:59 -04:00
|
|
|
|
2021-04-03 21:45:03 -04:00
|
|
|
# Players
|
|
|
|
my $P1 = "P1";
|
|
|
|
my $P2 = "P2";
|
|
|
|
|
|
|
|
my $DIV = ":";
|
|
|
|
|
2021-04-03 17:33:59 -04:00
|
|
|
my %AXIS = (
|
|
|
|
"A" => 1,
|
|
|
|
"B" => 2,
|
|
|
|
"C" => 3,
|
|
|
|
"D" => 4,
|
|
|
|
"E" => 5,
|
|
|
|
"F" => 6,
|
|
|
|
"G" => 7,
|
|
|
|
"H" => 8,
|
|
|
|
"I" => 9,
|
|
|
|
"J" => 10,
|
|
|
|
"K" => 11
|
|
|
|
);
|
2021-04-03 20:39:52 -04:00
|
|
|
my %AXIS_RV = map {
|
|
|
|
$AXIS{$_} => $_
|
|
|
|
} keys(%AXIS);
|
|
|
|
|
2021-04-03 17:33:59 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# /--\ +1
|
|
|
|
# | __ |
|
|
|
|
# | |+1
|
|
|
|
# \--/
|
|
|
|
# -1 -1
|
|
|
|
#
|
|
|
|
|
2021-04-04 01:24:38 -04:00
|
|
|
# ODD
|
|
|
|
# UP: 0, +1
|
|
|
|
# DOWN: -1, -1
|
|
|
|
|
|
|
|
# EVEN
|
|
|
|
# UP: +1, +1
|
|
|
|
# DOWN: +0, -1
|
|
|
|
|
|
|
|
# [Row move, Diag move]
|
2021-04-03 17:33:59 -04:00
|
|
|
|
|
|
|
my %MOVE = (
|
|
|
|
$MG_A => [
|
2021-04-04 02:07:03 -04:00
|
|
|
[-1, 1], [ 0, 1]
|
2021-04-03 17:33:59 -04:00
|
|
|
],
|
|
|
|
$MG_Q => [
|
2021-04-04 02:07:03 -04:00
|
|
|
[ 0, 1], [ 1, 0], [-1, 0], [ 0,-1],
|
2021-04-03 17:33:59 -04:00
|
|
|
],
|
|
|
|
$MG_I => [
|
|
|
|
[0,0]
|
|
|
|
],
|
|
|
|
$MG_IT => [
|
2021-04-04 02:07:03 -04:00
|
|
|
[ 0,-1], [ 1,-1]
|
2021-04-03 17:33:59 -04:00
|
|
|
],
|
|
|
|
$MG_N => [
|
|
|
|
[-1, 2],
|
|
|
|
[ 1,-2]
|
|
|
|
],
|
|
|
|
$MG_H => [
|
2021-04-04 02:07:03 -04:00
|
|
|
[-3, 2], [-1,-2], [ 1, 2], [ 3,-2]
|
2021-04-03 17:33:59 -04:00
|
|
|
],
|
|
|
|
$MG_RC => [
|
2021-04-04 11:22:37 -04:00
|
|
|
[-1, 0], [-2, 0], [ 1, 0], [ 2, 0]
|
2021-04-03 17:33:59 -04:00
|
|
|
],
|
|
|
|
$MG_S => [
|
2021-04-04 02:07:03 -04:00
|
|
|
[-1, 1], [-2, 2], [ 0, 1], [ 0, 2],
|
|
|
|
[ 0,-1], [ 0,-2], [ 1,-1], [ 2,-2],
|
2021-04-03 17:33:59 -04:00
|
|
|
],
|
|
|
|
$MG_HS => [
|
2021-04-04 02:07:03 -04:00
|
|
|
[-3, 1], [-2,-1], [ 2, 1], [ 3,-1]
|
2021-04-03 17:33:59 -04:00
|
|
|
],
|
|
|
|
$MG_RO => [
|
2021-04-04 02:07:03 -04:00
|
|
|
[-1, 1], [ 0, 1], [ 1, 1], [ 1,-2]
|
2021-04-03 17:33:59 -04:00
|
|
|
],
|
|
|
|
$MG_B => [
|
2021-04-04 11:22:37 -04:00
|
|
|
[-1, 1], [ 0, 1], [ 0,-2], [ 2,-2]
|
2021-04-03 17:33:59 -04:00
|
|
|
],
|
|
|
|
$MG_P => [
|
2021-04-04 02:07:03 -04:00
|
|
|
[-4, 2], [-2, 1], [-2,-2], [-1,-1],
|
|
|
|
[ 1, 1], [ 2,-1], [ 2, 2], [ 4,-2]
|
2021-04-03 17:33:59 -04:00
|
|
|
],
|
|
|
|
$MG_IM => [
|
2021-04-04 02:07:03 -04:00
|
|
|
[-2, 1], [-1,-1], [-1, 2], [ 1, 1],
|
2021-04-04 11:22:37 -04:00
|
|
|
[ 1,-1], [ 2,-1]
|
2021-04-03 17:33:59 -04:00
|
|
|
],
|
|
|
|
$MG_F => [
|
2021-04-04 02:07:03 -04:00
|
|
|
[-1, 0], [-1, 1], [ 0, 1], [ 0,-1],
|
|
|
|
[ 1, 0], [ 1,-1]
|
2021-04-03 17:33:59 -04:00
|
|
|
],
|
|
|
|
$MG_QS => [
|
2021-04-04 02:07:03 -04:00
|
|
|
[-3, 3], [-2, 2], [-2, 0], [-1, 0],
|
|
|
|
[-1, 1], [ 0, 1], [ 0, 2], [ 0, 3],
|
|
|
|
[ 0,-1], [ 0,-2], [ 0,-3], [ 1, 0],
|
|
|
|
[ 1,-1], [ 2, 0], [ 2,-2], [ 3,-3],
|
2021-04-03 17:33:59 -04:00
|
|
|
],
|
|
|
|
$MG_AU => [
|
2021-04-04 02:07:03 -04:00
|
|
|
[-1, 0], [-1, 1], [ 0, 1], [ 0,-1],
|
|
|
|
[ 1, 0], [ 1,-1]
|
2021-04-03 17:33:59 -04:00
|
|
|
],
|
|
|
|
$MG_SY => [
|
2021-04-04 02:07:03 -04:00
|
|
|
[-4, 4], [-3, 3], [-3, 2], [-1,-2],
|
2021-04-04 11:22:37 -04:00
|
|
|
[ 0,-4], [ 0,-3], [ 0, 3], [ 0, 4],
|
2021-04-04 02:07:03 -04:00
|
|
|
[ 1, 2], [ 3,-2], [ 3,-3], [ 4,-4]
|
2021-04-03 17:33:59 -04:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
# Special cells
|
2021-04-03 21:45:03 -04:00
|
|
|
my $EMPTY_CELL = "_";
|
2021-04-03 17:33:59 -04:00
|
|
|
|
2021-04-04 10:23:13 -04:00
|
|
|
# Shade enum
|
2021-04-04 11:22:37 -04:00
|
|
|
my $SHADE_3_ENUM = 3;
|
|
|
|
my $SHADE_2_ENUM = 2;
|
|
|
|
my $SHADE_1_ENUM = 1;
|
2021-04-04 10:23:13 -04:00
|
|
|
my $EMPTY_ENUM = 0;
|
|
|
|
|
|
|
|
my %SHADE = (
|
2021-04-04 11:22:37 -04:00
|
|
|
$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],
|
2021-04-04 10:23:13 -04:00
|
|
|
$EMPTY_ENUM => [$HEX_1, $HEX_2, $HEX_3]
|
|
|
|
);
|
|
|
|
|
2021-04-04 11:22:37 -04:00
|
|
|
my %sc = ();
|
2021-04-03 17:33:59 -04:00
|
|
|
my %board;
|
|
|
|
|
2021-04-03 21:45:03 -04:00
|
|
|
# Display pieces
|
|
|
|
#==================================================
|
|
|
|
|
2021-04-04 10:23:13 -04:00
|
|
|
# I hate this function
|
|
|
|
sub f_1($$$){
|
2021-04-03 21:45:03 -04:00
|
|
|
my $p = shift;
|
2021-04-03 22:38:20 -04:00
|
|
|
my $c0 = shift;
|
2021-04-04 10:23:13 -04:00
|
|
|
my $hex = shift;
|
2021-04-03 21:45:03 -04:00
|
|
|
my $s0;
|
|
|
|
|
|
|
|
$p =~ s/($P1|$P2)$DIV//;
|
2021-04-04 11:22:37 -04:00
|
|
|
# $p =~ s/$EMPTY_CELL//;
|
|
|
|
# $p .= "__" if length($p) < 1;
|
2021-04-03 21:45:03 -04:00
|
|
|
$p .= "_" if length($p) < 2;
|
2021-04-04 10:23:13 -04:00
|
|
|
$s0 = $hex;
|
2021-04-04 11:22:37 -04:00
|
|
|
|
2021-04-03 21:45:03 -04:00
|
|
|
$s0 =~ s/$SUB_CHR{1,2}/$p/;
|
2021-04-04 11:22:37 -04:00
|
|
|
|
|
|
|
unless($p eq "__"){
|
|
|
|
substr($s0, 2,2) = $p;
|
2021-04-04 10:23:13 -04:00
|
|
|
}
|
2021-04-04 11:22:37 -04:00
|
|
|
# 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/;
|
|
|
|
# }
|
2021-04-03 22:38:20 -04:00
|
|
|
|
|
|
|
if($c0 % 2 == 0){
|
2021-04-04 10:23:13 -04:00
|
|
|
$s0 =~ s/$SUB_CHR/$BLANK_CELL_CHR/g;
|
2021-04-03 22:38:20 -04:00
|
|
|
}
|
|
|
|
|
2021-04-03 21:45:03 -04:00
|
|
|
return $s0;
|
|
|
|
}
|
2021-04-03 17:33:59 -04:00
|
|
|
|
2021-04-04 10:23:13 -04:00
|
|
|
# Display shade
|
|
|
|
#==================================================
|
|
|
|
|
2021-04-04 11:22:37 -04:00
|
|
|
sub shade_cell($$){
|
2021-04-04 10:23:13 -04:00
|
|
|
my $not = shift;
|
2021-04-04 11:22:37 -04:00
|
|
|
my $en = shift;
|
|
|
|
|
|
|
|
$sc{$not} = $en unless (grep /^$not$/, keys(%sc));
|
2021-04-04 10:23:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub shade_t($){
|
|
|
|
my $not = shift;
|
2021-04-04 11:22:37 -04:00
|
|
|
return $sc{$not} if (grep /^$not$/, keys(%sc));
|
2021-04-04 10:23:13 -04:00
|
|
|
return $EMPTY_ENUM;
|
2021-04-04 11:22:37 -04:00
|
|
|
|
|
|
|
# return $SHADE_1_ENUM if grep /^$not$/, @sc0;
|
|
|
|
# return $SHADE_2_ENUM if grep /^$not$/, @sc1;
|
|
|
|
# return $EMPTY_ENUM;
|
2021-04-04 10:23:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub get_shade_chr($){
|
|
|
|
my $en = shift;
|
|
|
|
return $SHADE{$en};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub shade_lookup($$){
|
|
|
|
my ($r0, $c0) = (shift, shift);
|
|
|
|
my $not;
|
|
|
|
|
|
|
|
$not = cell_index_rev($c0, $r0);
|
|
|
|
return get_shade_chr(shade_t($not));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-03 21:10:13 -04:00
|
|
|
# Display lines
|
|
|
|
#==================================================
|
|
|
|
|
|
|
|
sub disp_1($$){
|
|
|
|
my ($r0, $c0) = (shift, shift);
|
2021-04-04 10:23:13 -04:00
|
|
|
my $hex;
|
|
|
|
|
|
|
|
$hex = shade_lookup($r0, $c0)->[0];
|
|
|
|
|
|
|
|
return $hex;
|
|
|
|
# return $HEX_1;
|
2021-04-03 17:33:59 -04:00
|
|
|
}
|
|
|
|
|
2021-04-03 21:10:13 -04:00
|
|
|
sub disp_2($$){
|
|
|
|
my ($r0, $c0) = (shift, shift);
|
2021-04-03 21:45:03 -04:00
|
|
|
my $p;
|
2021-04-03 22:06:10 -04:00
|
|
|
my $not;
|
2021-04-04 10:23:13 -04:00
|
|
|
my $hex;
|
2021-04-03 22:06:10 -04:00
|
|
|
|
2021-04-04 10:23:13 -04:00
|
|
|
$hex = shade_lookup($r0, $c0)->[1];
|
2021-04-03 22:06:10 -04:00
|
|
|
$not = cell_index_rev($c0, $r0);
|
|
|
|
|
|
|
|
$p = $board{$not};
|
2021-04-03 21:45:03 -04:00
|
|
|
|
2021-04-04 10:23:13 -04:00
|
|
|
return f_1($p, $c0, $hex);
|
2021-04-03 21:45:03 -04:00
|
|
|
# my ($r0, $c0) = (shift, shift);
|
|
|
|
# return $HEX_2;
|
2021-04-03 17:33:59 -04:00
|
|
|
}
|
|
|
|
|
2021-04-03 21:10:13 -04:00
|
|
|
sub disp_3($$){
|
|
|
|
my ($r0, $c0) = (shift, shift);
|
2021-04-04 10:23:13 -04:00
|
|
|
my $hex;
|
|
|
|
|
|
|
|
$hex = shade_lookup($r0, $c0)->[2];
|
|
|
|
|
|
|
|
return $hex;
|
2021-04-03 17:33:59 -04:00
|
|
|
}
|
|
|
|
|
2021-04-03 20:41:03 -04:00
|
|
|
sub disp_y_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);
|
|
|
|
}
|
|
|
|
|
2021-04-03 21:10:13 -04:00
|
|
|
# Display cell
|
|
|
|
#==================================================
|
|
|
|
|
2021-04-03 17:33:59 -04:00
|
|
|
sub add_cell($$$$$){
|
|
|
|
my ($s0, $s1, $s2, $r0, $c0) = @_;
|
2021-04-03 22:38:20 -04:00
|
|
|
|
2021-04-03 21:10:13 -04:00
|
|
|
$s0 .= disp_1($r0, $c0);
|
|
|
|
$s1 .= disp_2($r0, $c0);
|
|
|
|
$s2 .= disp_3($r0, $c0);
|
2021-04-03 17:33:59 -04:00
|
|
|
|
|
|
|
return ($s0, $s1, $s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub disp_0($){
|
|
|
|
my $r0;
|
|
|
|
|
|
|
|
my ($s0, $s1, $s2);
|
|
|
|
|
|
|
|
$r0 = shift;
|
|
|
|
|
2021-04-03 21:10:13 -04:00
|
|
|
# Append the y axis
|
2021-04-03 20:41:03 -04:00
|
|
|
($s0, $s1, $s2) = disp_y_axis($s0, $s1, $s2, $r0);
|
2021-04-03 21:10:13 -04:00
|
|
|
|
|
|
|
# Iterate through the cells
|
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";
|
|
|
|
}
|
|
|
|
|
2021-04-03 21:10:13 -04:00
|
|
|
# Display row
|
|
|
|
#==================================================
|
|
|
|
|
2021-04-03 17:33:59 -04:00
|
|
|
sub disp_row($){
|
2021-04-03 18:18:24 -04:00
|
|
|
my $row;
|
|
|
|
my $r0;
|
|
|
|
|
|
|
|
$r0 = shift;
|
|
|
|
|
|
|
|
$row = disp_0($r0);
|
2021-04-03 21:10:13 -04:00
|
|
|
|
|
|
|
# Handle trailing characters
|
2021-04-03 18:18:24 -04:00
|
|
|
if($r0 % 2 == 1){
|
2021-04-03 18:49:42 -04:00
|
|
|
# Trim the start of the first line
|
|
|
|
$row =~ s/$TRAIL_1/ /;
|
2021-04-03 18:18:24 -04:00
|
|
|
# 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
|
|
|
}
|
|
|
|
|
2021-04-03 20:39:52 -04:00
|
|
|
sub disp_trailing_row(){
|
|
|
|
my $s0;
|
|
|
|
my $s1;
|
|
|
|
|
|
|
|
$s0 = $PAD_EVEN.$PREF_1;
|
|
|
|
|
|
|
|
# Clear some chars from
|
|
|
|
# our hex patterns
|
|
|
|
$s1 = $HEX_1;
|
|
|
|
substr($s1, 2,2) = " ";
|
|
|
|
|
|
|
|
# Append hex pattern to
|
|
|
|
# trailing row
|
|
|
|
for my $i (1..11){
|
|
|
|
$s0 .= $s1;
|
|
|
|
}
|
|
|
|
# Clear one last pair of
|
|
|
|
# chrs
|
|
|
|
substr($s0, -2,2) = " ";
|
|
|
|
$s0 .= "\n";
|
|
|
|
|
|
|
|
return $s0;
|
|
|
|
}
|
|
|
|
|
2021-04-03 21:10:13 -04:00
|
|
|
sub disp_x_axis(){
|
|
|
|
my $s0;
|
|
|
|
|
|
|
|
$s0 = $PAD_AXIS;
|
|
|
|
$s0 .= join(
|
|
|
|
$PAD_AXIS, map{
|
|
|
|
$AXIS_RV{$_}
|
|
|
|
}(1..11));
|
|
|
|
$s0 .= "\n";
|
|
|
|
|
2021-04-03 22:38:20 -04:00
|
|
|
$s0 .= $PAD_AXIS;
|
|
|
|
$s0 .= join(
|
|
|
|
"", map{
|
|
|
|
$_ % 2 == 1 ? $HL_1 : $HL_2
|
|
|
|
}(1..11));
|
|
|
|
$s0 .= "\n";
|
|
|
|
|
2021-04-03 21:10:13 -04:00
|
|
|
return $s0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Display board
|
|
|
|
#==================================================
|
|
|
|
|
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 20:39:52 -04:00
|
|
|
$b .= disp_trailing_row();
|
2021-04-03 20:41:03 -04:00
|
|
|
$b .= disp_x_axis();
|
2021-04-03 18:18:24 -04:00
|
|
|
$b =~ s/$TRAIL_1$TRAIL_3\n/\n/m;
|
2021-04-03 18:49:42 -04:00
|
|
|
|
|
|
|
for my $i (1..11-1){
|
|
|
|
substr($b, 2+6*$i, 2) = " ";
|
|
|
|
}
|
2021-04-03 18:18:24 -04:00
|
|
|
printf("%s", $b);
|
|
|
|
}
|
2021-04-03 17:33:59 -04:00
|
|
|
|
2021-04-04 01:24:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-04 10:23:13 -04:00
|
|
|
|
2021-04-03 22:06:10 -04:00
|
|
|
sub cell_index_rev($$){
|
|
|
|
return $AXIS_RV{$_[0]}.$_[1];
|
|
|
|
}
|
|
|
|
|
2021-04-03 17:33:59 -04:00
|
|
|
sub cell_index($){
|
|
|
|
my ($chr1, $chr2) = (split(//, $_[0]));
|
|
|
|
return ($AXIS{$chr1}, $chr2);
|
|
|
|
}
|
|
|
|
|
2021-04-04 01:24:38 -04:00
|
|
|
sub apply_shift($$){
|
|
|
|
my ($not, $my_shift) = (shift, shift);
|
|
|
|
my $r0;
|
|
|
|
my $c0;
|
|
|
|
|
|
|
|
($r0, $c0) = cell_index($not);
|
|
|
|
|
|
|
|
$r0 += $my_shift->[0];
|
|
|
|
$c0 += $my_shift->[1];
|
|
|
|
die "cell index [$r0, $c0]: out of bound exception" if $r0 > 11 or $c0 > 11 or $r0 < 1 or $c0 < 1;
|
|
|
|
return cell_index_rev($r0, $c0);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub calc_move($$){
|
|
|
|
my ($not, $mov) = (shift, shift);
|
|
|
|
my $r0;
|
|
|
|
my $c0;
|
|
|
|
|
|
|
|
my $x_shift;
|
|
|
|
my $y_shift;
|
|
|
|
|
|
|
|
my $n0;
|
|
|
|
my $ni;
|
|
|
|
|
2021-04-04 02:07:03 -04:00
|
|
|
($c0, $r0) = cell_index($not);
|
2021-04-04 01:24:38 -04:00
|
|
|
|
2021-04-04 02:07:03 -04:00
|
|
|
# get y_shift
|
2021-04-04 01:24:38 -04:00
|
|
|
$y_shift = $mov->[1];
|
|
|
|
|
2021-04-04 02:07:03 -04:00
|
|
|
# get x_shift
|
2021-04-04 01:24:38 -04:00
|
|
|
$x_shift = $mov->[0];
|
|
|
|
|
2021-04-04 02:07:03 -04:00
|
|
|
# make x_shift adjustment
|
2021-04-04 11:22:37 -04:00
|
|
|
|
|
|
|
$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;
|
2021-04-04 01:24:38 -04:00
|
|
|
$x_shift += int(($y_shift + ($n0 * $ni)) / 2);
|
|
|
|
|
|
|
|
return apply_shift($not, [$x_shift, $y_shift]);
|
|
|
|
}
|
|
|
|
|
2021-04-03 22:38:20 -04:00
|
|
|
|
|
|
|
# Main starts here!
|
|
|
|
binmode(STDOUT, ":utf8");
|
|
|
|
|
2021-04-03 21:48:20 -04:00
|
|
|
# Creates a hash of the the form
|
|
|
|
# $board{cell_notation} = piece_enum
|
2021-04-03 17:33:59 -04:00
|
|
|
%board = map {
|
|
|
|
$_ => $EMPTY_CELL
|
|
|
|
} map {
|
|
|
|
my $l0;
|
|
|
|
$l0 = $_;
|
|
|
|
(map {$l0.$_} ("1".."11"))
|
2021-04-03 21:45:03 -04:00
|
|
|
} map {
|
2021-04-03 20:39:52 -04:00
|
|
|
$AXIS_RV{$_}
|
|
|
|
}(1...11);
|
2021-04-03 17:33:59 -04:00
|
|
|
|
2021-04-04 02:07:03 -04:00
|
|
|
my $m1 = "E6";
|
2021-04-04 11:22:37 -04:00
|
|
|
my $c1 = $MG_SY;
|
2021-04-03 21:45:03 -04:00
|
|
|
|
2021-04-04 01:31:12 -04:00
|
|
|
$board{$m1} = $P1.$DIV.$c1;
|
2021-04-04 11:22:37 -04:00
|
|
|
for my $mv (@{$MOVE{$c1}}){
|
|
|
|
shade_cell(calc_move($m1, $mv), $SHADE_1_ENUM);
|
|
|
|
}
|
2021-04-03 21:45:03 -04:00
|
|
|
|
2021-04-03 22:06:10 -04:00
|
|
|
disp_board();
|
2021-04-03 17:33:59 -04:00
|
|
|
|
2021-04-04 11:22:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|