add tools for tile manipulation, first code for part 2

This commit is contained in:
2021-07-27 12:25:43 +02:00
parent 150e4ba2a7
commit f4348d3faf
2 changed files with 313 additions and 18 deletions

View File

@@ -6,8 +6,11 @@ CMD=${0##*/}
set -o noglob
shopt -s extglob
source tile.bash
#declare -A strings
declare -a strings T R B L RT RR RB RL nums
declare -A final
declare -a CORNER EDGE CENTRAL
declare -i count=-1 res=1
@@ -26,28 +29,67 @@ while read -r line; do
done
((count--))
#test start
# key=1
# str=(${strings[$key]})
# top1="${str[0]}"
# bottom1="${str[9]}"
# declare top bottom left right
# unset left1 right1
# for ((i=0; i<10; ++i)); do
# left1+=${str[$i]:0:1}
# right1+=${str[$i]: -1:1}
# done
# top top ${str[@]}
# bottom bottom ${str[@]}
# right right ${str[@]}
# left left ${str[@]}
# print_tile 1
# printf "T=%s\n" "$top1"
# printf "T=%s\n" "$top"
# echo
# printf "R=%s\n" "$right1"
# printf "R=%s\n" "$right"
# echo
# printf "B=%s\n" "$bottom1"
# printf "B=%s\n" "$bottom"
# echo
# printf "L=%s\n" "$left1"
# printf "L=%s\n" "$left"
# echo
# for ((i=9; i>=0; --i)); do
# fliptop1+=${top:$i:1}
# flipbottom1+=${bottom:$i:1}
# done
# flip fliptop $top
# flip flibottom $bottom
# printf "T=%s\n" "$fliptop1"
# printf "T=%s\n" "$fliptop"
# echo
# exit 0
#test end
declare top bottom left right
declare fliptop flipbottom flipleft flipright
for key in "${!nums[@]}"; do
# shellcheck disable=SC2206
str=(${strings[$key]})
top="${str[0]}"
bottom="${str[9]}"
top top "${str[@]}"
right right "${str[@]}"
bottom bottom "${str[@]}"
left left "${str[@]}"
flip fliptop "$top"
flip flipright "$right"
flip flipbottom "$bottom"
flip flipleft "$left"
T+=("$top")
B+=("$bottom")
# find out right and bottom
unset left right
for ((i=0; i<10; ++i)); do
left+=${str[$i]:0:1}
right+=${str[$i]: -1:1}
done
R+=("$right")
L+=("$left")
unset fliptop flipbottom flipleft flipright
for ((i=9; i>=0; --i)); do
fliptop+=${top:$i:1}
flipbottom+=${bottom:$i:1}
flipleft+=${left:$i:1}
flipright+=${right:$i:1}
done
RT+=("$fliptop")
RR+=("$flipright")
RB+=("$flipbottom")
@@ -71,22 +113,152 @@ for ((i=0; i<${#nums[@]}; ++i)); do
#printf "%s: %d\n" "${nums[$i]}" "$count"
case "$count" in
6)
CORNER+=(${nums[$i]})
CORNER+=("$i")
((res*=${nums[$i]}))
;;
7)
EDGE+=(${nums[$i]})
EDGE+=("$i")
;;
8)
CENTRAL+=(${nums[$i]})
CENTRAL+=("$i")
;;
esac
done
printf "CENTRAL[%d]=%s\n" "${#CENTRAL[@]}" "${CENTRAL[*]}"
printf "EDGE[%d]=%s\n" "${#EDGE[@]}" "${EDGE[*]}"
printf "CORNER[%d]=%s\n" "${#CORNER[@]}" "${CORNER[*]}"
printf "%s : res=%d\n" "$CMD" "$res"
i=${CORNER[0]}
printf "corner=%d=%d\n" "$i" "${nums[$i]}"
printf "origin:\n"
print_tile "$i"
flip_h "$i"
printf "horizontal flip:\n"
print_tile "$i"
flip_h "$i"
flip_v "$i"
printf "vertical flip:\n"
print_tile "$i"
flip_v "$i"
printf "origin:\n"
print_tile "$i"
declare l="" r=""
rightcol r "${strings[$i]}"
printf "right=%s\n" "$r"
printf "origin:\n"
print_tile "$i"
r=""; l=""
leftcol l "${strings[$i]}"
printf "left =%s\n" "$l"
printf "origin:\n"
print_tile "$i"
exit 0
# Choose one corner for top-left, find the correct flip
i=${CORNER[0]}
printf "corner[0]=%d\n" "${nums[$i]}"
print_tile "$i"; echo
t=${B[$i]}
S=${ALL//$t}
# flip vertical if bottom is a corner side
if (( ALLSIZE-${#S} == 10)); then
echo FLIP_V
flip_v "$i"
fi
print_tile "$i"; echo
i=${CORNER[0]}
t=${R[$i]}
S=${ALL//$t}
if (( ALLSIZE-${#S} == 10)); then
echo FLIP_H
flip_h "$i"
fi
print_tile "$i"
final[0,0]="${strings[$i]}"
unset strings[$i]
# find next tile
#for i in ${EDGE[@]}; do
#done
exit 0
printf "corner[0]=%d\n" "${nums[$i]}"
printf "origin:\n"
print_tile "$i"
flip_h "$i"
printf "horizontal flip:\n"
print_tile "$i"
flip_h "$i"
flip_v "$i"
printf "vertical flip:\n"
print_tile "$i"
flip_v "$i"
printf "origin:\n"
print_tile "$i"
r90 "$i"
printf "r90:\n"
print_tile "$i"
#for i in "${CORNER[@]}"; do
t=${T[$i]}; S=${ALL//$t}; ((count=(ALLSIZE-${#S})/10))
printf "T %s: %d\n" "$t" "$count"
t=${R[$i]}; S=${ALL//$t}; ((count=(ALLSIZE-${#S})/10))
printf "R %s: %d\n" "$t" "$count"
t=${B[$i]}; S=${ALL//$t}; ((count=(ALLSIZE-${#S})/10))
printf "B %s: %d\n" "$t" "$count"
t=${L[$i]}; S=${ALL//$t}; ((count=(ALLSIZE-${#S})/10))
printf "L %s: %d\n" "$t" "$count"
t=${RT[$i]}; S=${ALL//$t}; ((count=(ALLSIZE-${#S})/10))
printf "RT %s: %d\n" "$t" "$count"
t=${RR[$i]}; S=${ALL//$t}; ((count=(ALLSIZE-${#S})/10))
printf "RR %s: %d\n" "$t" "$count"
t=${RB[$i]}; S=${ALL//$t}; ((count=(ALLSIZE-${#S})/10))
printf "RB %s: %d\n" "$t" "$count"
t=${RL[$i]}; S=${ALL//$t}; ((count=(ALLSIZE-${#S})/10))
printf "RL %s: %d\n" "$t" "$count"
exit 0
for t in ${T[$i]} ${R[$i]} ${B[$i]} ${L[$i]} \
${RT[$i]} ${RR[$i]} ${RB[$i]} ${RL[$i]}; do
S=${ALL//$t}
((count=(ALLSIZE-${#S})/10))
printf "%s: %d\n" "$t" "$count"
done
echo
#done
exit 0
r90 "$i"
printf "r90:\n"
print_tile "$i"
r90 "$i"
r90 "$i"
r90 "$i"
printf "origin:\n"
print_tile "$i"
r180 "$i"
printf "r180:\n"
print_tile "$i"
r180 "$i"
printf "origin:\n"
print_tile "$i"
r270 "$i"
printf "r270:\n"
print_tile "$i"
r90 "$i"
printf "origin:\n"
print_tile "$i"