bug fix on lists element removal. tiles are now correctly assembled.
This commit is contained in:
@@ -68,8 +68,10 @@ for key in "${!nums[@]}"; do
|
|||||||
RL+=("$flipleft")
|
RL+=("$flipleft")
|
||||||
|
|
||||||
done
|
done
|
||||||
|
#echo BORDERS:
|
||||||
ALL="${T[*]} ${R[*]} ${B[*]} ${L[*]} ${RT[*]} ${RR[*]} ${RB[*]} ${RL[*]}"
|
#print_all_borders
|
||||||
|
#exit 0
|
||||||
|
ALL="${T[*]} ${R[*]} ${B[*]} ${L[*]} ${RT[*]} ${RR[*]} ${RB[*]} ${RL[*]} "
|
||||||
ALLSIZE=${#ALL}
|
ALLSIZE=${#ALL}
|
||||||
|
|
||||||
for ((i=0; i<${#nums[@]}; ++i)); do
|
for ((i=0; i<${#nums[@]}; ++i)); do
|
||||||
@@ -99,27 +101,41 @@ done
|
|||||||
printf "CENTRAL[%d]=%s\n" "${#CENTRAL[@]}" "${CENTRAL[*]}"
|
printf "CENTRAL[%d]=%s\n" "${#CENTRAL[@]}" "${CENTRAL[*]}"
|
||||||
printf "EDGE[%d]=%s\n" "${#EDGE[@]}" "${EDGE[*]}"
|
printf "EDGE[%d]=%s\n" "${#EDGE[@]}" "${EDGE[*]}"
|
||||||
printf "CORNER[%d]=%s\n" "${#CORNER[@]}" "${CORNER[*]}"
|
printf "CORNER[%d]=%s\n" "${#CORNER[@]}" "${CORNER[*]}"
|
||||||
|
for ((i=0; i<${#CORNER[@]}; ++i)); do
|
||||||
|
printf "corner[%d]=%d\n" "$i" "${nums[$i]}"
|
||||||
|
done
|
||||||
|
|
||||||
|
#printf "ALL=%s\n" "$ALL"
|
||||||
|
printf "ALLSIZE=%d\n" "$ALLSIZE"
|
||||||
printf "%s : count=%d\n" "$CMD" "$count"
|
printf "%s : count=%d\n" "$CMD" "$count"
|
||||||
|
|
||||||
for ((row=0; row<SQUARE; ++row)); do
|
for ((row=0; row<SQUARE; ++row)); do
|
||||||
echo ZOBI
|
|
||||||
for ((col=0; col<SQUARE; ++col)); do
|
for ((col=0; col<SQUARE; ++col)); do
|
||||||
for k in ${!FINAL[@]}; do
|
for k in "${!FINAL[@]}"; do
|
||||||
printf "final[%s]=%d\n" "$k" "${FINAL[$k]}"
|
printf "final[%s]=%d\n" "$k" "${FINAL[$k]}"
|
||||||
done
|
done
|
||||||
|
found=0
|
||||||
printf "square(%d,%d)\n" "$row" "$col"
|
printf "square(%d,%d)\n" "$row" "$col"
|
||||||
################################## 1st tile (top left)
|
################################## 1st tile (top left)
|
||||||
if ((row==0 && col==0)); then
|
if ((row==0 && col==0)); then
|
||||||
# Choose one corner for top-left, find the correct orientation
|
# Choose one corner for top-left, find the correct orientation
|
||||||
i=${CORNER[0]}
|
i=${CORNER[0]}
|
||||||
|
printf "corner[0]=%d\n" "${nums[$i]}"
|
||||||
unset "CORNER[0]"
|
unset "CORNER[0]"
|
||||||
CORNER=("${CORNER[@]}")
|
CORNER=("${CORNER[@]}")
|
||||||
|
|
||||||
printf "corner[0]=%d\n" "${nums[$i]}"
|
|
||||||
print_tile "$i"; echo
|
print_tile "$i"; echo
|
||||||
|
t=${L[$i]}
|
||||||
|
S=${ALL//$t}
|
||||||
|
printf "left matches=%d\n" $((ALLSIZE-${#S}))
|
||||||
|
t=${T[$i]}
|
||||||
|
S=${ALL//$t}
|
||||||
|
printf "top matches=%d\n" $((ALLSIZE-${#S}))
|
||||||
|
|
||||||
t=${B[$i]}
|
t=${B[$i]}
|
||||||
S=${ALL//$t}
|
S=${ALL//$t}
|
||||||
# flip vertical if bottom is a corner side
|
# flip vertical if bottom is a corner side
|
||||||
|
printf "bottom matches=%d\n" $((ALLSIZE-${#S}))
|
||||||
if (( ALLSIZE-${#S} == 10 )); then
|
if (( ALLSIZE-${#S} == 10 )); then
|
||||||
echo FLIP_V
|
echo FLIP_V
|
||||||
flip_v "$i"
|
flip_v "$i"
|
||||||
@@ -127,7 +143,8 @@ for ((row=0; row<SQUARE; ++row)); do
|
|||||||
print_tile "$i"; echo
|
print_tile "$i"; echo
|
||||||
t=${R[$i]}
|
t=${R[$i]}
|
||||||
S=${ALL//$t}
|
S=${ALL//$t}
|
||||||
# flip horizontal if bottom is a corner side
|
# flip horizontal if right is a corner side
|
||||||
|
printf "right matches=%d\n" $((ALLSIZE-${#S}))
|
||||||
if (( ALLSIZE-${#S} == 10 )); then
|
if (( ALLSIZE-${#S} == 10 )); then
|
||||||
echo FLIP_H
|
echo FLIP_H
|
||||||
flip_h "$i"
|
flip_h "$i"
|
||||||
@@ -145,8 +162,9 @@ for ((row=0; row<SQUARE; ++row)); do
|
|||||||
list=("${CORNER[@]}")
|
list=("${CORNER[@]}")
|
||||||
fi
|
fi
|
||||||
l=${FINAL[0,$((col-1))]}
|
l=${FINAL[0,$((col-1))]}
|
||||||
printf "FINAL[0,%d]=%d\n" "$((col-1))" "${FINAL[0,$((col-1))]}"
|
#printf "FINAL[0,%d]=%d\n" "$((col-1))" "${FINAL[0,$((col-1))]}"
|
||||||
right right "${strings[$l]}"
|
right right "${strings[$l]}"
|
||||||
|
index=0
|
||||||
for j in "${list[@]}"; do
|
for j in "${list[@]}"; do
|
||||||
SIDES="${T[$j]} ${R[$j]} ${B[$j]} ${L[$j]} ${RT[$j]} ${RR[$j]} ${RB[$j]} ${RL[$j]}"
|
SIDES="${T[$j]} ${R[$j]} ${B[$j]} ${L[$j]} ${RT[$j]} ${RR[$j]} ${RB[$j]} ${RL[$j]}"
|
||||||
LENGTH=${#SIDES}
|
LENGTH=${#SIDES}
|
||||||
@@ -154,22 +172,32 @@ for ((row=0; row<SQUARE; ++row)); do
|
|||||||
# 10 is line size
|
# 10 is line size
|
||||||
((c = (LENGTH-${#S})/10))
|
((c = (LENGTH-${#S})/10))
|
||||||
if ((c > 0)); then
|
if ((c > 0)); then
|
||||||
echo "border tile match: ${nums[$j]}"
|
echo "border tile match: idx=$index $j [${nums[$j]}]"
|
||||||
print_tile "$j"
|
print_tile "$j"
|
||||||
FINAL[$row,$col]="$j"
|
FINAL[$row,$col]="$j"
|
||||||
final+=("${nums[$j]}")
|
final+=("${nums[$j]}")
|
||||||
echo "c=$c"
|
echo "c=$c"
|
||||||
attach_left "$right" "$j"
|
attach_left "$right" "$j"
|
||||||
if ((col < SQUARE-1)); then
|
if ((col < SQUARE-1)); then
|
||||||
unset "EDGE[$j]"
|
unset "EDGE[$index]"
|
||||||
EDGE=("${EDGE[@]}")
|
EDGE=("${EDGE[@]}")
|
||||||
|
printf "after removing EDGE $j\n"
|
||||||
|
printf "EDGE[%d]=%s\n" "${#EDGE[@]}" "${EDGE[*]}"
|
||||||
else
|
else
|
||||||
unset "CORNER[$j]"
|
unset "CORNER[$index]"
|
||||||
CORNER=("${CORNER[@]}")
|
CORNER=("${CORNER[@]}")
|
||||||
|
printf "after removing CORNER $j\n"
|
||||||
|
printf "CORNER[%d]=%s\n" "${#CORNER[@]}" "${CORNER[*]}"
|
||||||
fi
|
fi
|
||||||
|
found=1
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
((index++))
|
||||||
done
|
done
|
||||||
|
if ((found==0)); then
|
||||||
|
printf "NOT FOUND\n"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
################################## 1st and last col
|
################################## 1st and last col
|
||||||
@@ -185,6 +213,7 @@ for ((row=0; row<SQUARE; ++row)); do
|
|||||||
print_tile "$j"
|
print_tile "$j"
|
||||||
bottom bottom "${strings[$l]}"
|
bottom bottom "${strings[$l]}"
|
||||||
printf "UPPER bottom line: %s\n" "$bottom"
|
printf "UPPER bottom line: %s\n" "$bottom"
|
||||||
|
index=0
|
||||||
for j in "${list[@]}"; do
|
for j in "${list[@]}"; do
|
||||||
printf "looking for tile %d [%d]\n" "$j" "${nums[$j]}"
|
printf "looking for tile %d [%d]\n" "$j" "${nums[$j]}"
|
||||||
SIDES="${T[$j]} ${R[$j]} ${B[$j]} ${L[$j]} ${RT[$j]} ${RR[$j]} ${RB[$j]} ${RL[$j]}"
|
SIDES="${T[$j]} ${R[$j]} ${B[$j]} ${L[$j]} ${RT[$j]} ${RR[$j]} ${RB[$j]} ${RL[$j]}"
|
||||||
@@ -200,15 +229,21 @@ for ((row=0; row<SQUARE; ++row)); do
|
|||||||
echo "c=$c"
|
echo "c=$c"
|
||||||
attach_top "$bottom" "$j"
|
attach_top "$bottom" "$j"
|
||||||
if ((row < SQUARE-1)); then
|
if ((row < SQUARE-1)); then
|
||||||
unset "EDGE[$j]"
|
unset "EDGE[$index]"
|
||||||
EDGE=("${EDGE[@]}")
|
EDGE=("${EDGE[@]}")
|
||||||
else
|
else
|
||||||
unset "CORNER[$j]"
|
unset "CORNER[$index]"
|
||||||
CORNER=("${CORNER[@]}")
|
CORNER=("${CORNER[@]}")
|
||||||
fi
|
fi
|
||||||
|
found=1
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
((index++))
|
||||||
done
|
done
|
||||||
|
if ((found==0)); then
|
||||||
|
printf "NOT FOUND\n"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
################################## rest of last row
|
################################## rest of last row
|
||||||
@@ -216,6 +251,7 @@ for ((row=0; row<SQUARE; ++row)); do
|
|||||||
l=${FINAL[$((row-1)),$col]}
|
l=${FINAL[$((row-1)),$col]}
|
||||||
printf "FINAL[%d,%d]=%d\n" "$((row-1))" "$col" "${FINAL[$((row-1)),$col]}"
|
printf "FINAL[%d,%d]=%d\n" "$((row-1))" "$col" "${FINAL[$((row-1)),$col]}"
|
||||||
bottom bottom "${strings[$l]}"
|
bottom bottom "${strings[$l]}"
|
||||||
|
index=0
|
||||||
for j in "${EDGE[@]}"; do
|
for j in "${EDGE[@]}"; do
|
||||||
SIDES="${T[$j]} ${R[$j]} ${B[$j]} ${L[$j]} ${RT[$j]} ${RR[$j]} ${RB[$j]} ${RL[$j]}"
|
SIDES="${T[$j]} ${R[$j]} ${B[$j]} ${L[$j]} ${RT[$j]} ${RR[$j]} ${RB[$j]} ${RL[$j]}"
|
||||||
LENGTH=${#SIDES}
|
LENGTH=${#SIDES}
|
||||||
@@ -229,17 +265,24 @@ for ((row=0; row<SQUARE; ++row)); do
|
|||||||
final+=("${nums[$j]}")
|
final+=("${nums[$j]}")
|
||||||
echo "c=$c"
|
echo "c=$c"
|
||||||
attach_top "$bottom" "$j"
|
attach_top "$bottom" "$j"
|
||||||
unset "EDGE[$j]"
|
unset "EDGE[$index]"
|
||||||
EDGE=("${EDGE[@]}")
|
EDGE=("${EDGE[@]}")
|
||||||
|
found=1
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
((index++))
|
||||||
done
|
done
|
||||||
|
if ((found==0)); then
|
||||||
|
printf "NOT FOUND\n"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
################################## central tiles
|
################################## central tiles
|
||||||
l=${FINAL[$((row-1)),$col]}
|
l=${FINAL[$((row-1)),$col]}
|
||||||
printf "FINAL[%d,%d]=%d\n" "$((col-1))" "${FINAL[$,$((col-1))]}"
|
printf "FINAL[%d,%d]=%d\n" "$((col-1))" "${FINAL[$,$((col-1))]}"
|
||||||
bottom bottom "${strings[$l]}"
|
bottom bottom "${strings[$l]}"
|
||||||
|
index=0
|
||||||
for j in "${CENTRAL[@]}"; do
|
for j in "${CENTRAL[@]}"; do
|
||||||
SIDES="${T[$j]} ${R[$j]} ${B[$j]} ${L[$j]} ${RT[$j]} ${RR[$j]} ${RB[$j]} ${RL[$j]}"
|
SIDES="${T[$j]} ${R[$j]} ${B[$j]} ${L[$j]} ${RT[$j]} ${RR[$j]} ${RB[$j]} ${RL[$j]}"
|
||||||
LENGTH=${#SIDES}
|
LENGTH=${#SIDES}
|
||||||
@@ -253,13 +296,18 @@ for ((row=0; row<SQUARE; ++row)); do
|
|||||||
final+=("${nums[$j]}")
|
final+=("${nums[$j]}")
|
||||||
echo "c=$c"
|
echo "c=$c"
|
||||||
attach_top "$bottom" "$j"
|
attach_top "$bottom" "$j"
|
||||||
unset "CENTRAL[$j]"
|
unset "CENTRAL[$index]"
|
||||||
CENTRAL=("${CENTRAL[@]}")
|
CENTRAL=("${CENTRAL[@]}")
|
||||||
|
found=1
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
((index++))
|
||||||
done
|
done
|
||||||
|
if ((found==0)); then
|
||||||
|
printf "NOT FOUND\n"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
continue
|
continue
|
||||||
|
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -274,6 +322,20 @@ done
|
|||||||
print_final
|
print_final
|
||||||
trim_borders
|
trim_borders
|
||||||
print_final
|
print_final
|
||||||
|
|
||||||
|
|
||||||
|
# dragon:
|
||||||
|
# 01234567890123456789
|
||||||
|
# #
|
||||||
|
# # ## ## ###
|
||||||
|
# # # # # # #
|
||||||
|
for ((r=0; r<SQUARE-2; ++r)); do
|
||||||
|
for ((c=18; c<SQUARE-1; ++c)); do
|
||||||
|
:
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
printf "%s \n" "${final[@]}"
|
printf "%s \n" "${final[@]}"
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
@@ -158,7 +158,20 @@ flip() {
|
|||||||
_r+=${str:$i:1}
|
_r+=${str:$i:1}
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
print_all_borders() {
|
||||||
|
local k str
|
||||||
|
local -i i
|
||||||
|
for ((i=0; i<${#strings[@]}; ++i)); do
|
||||||
|
top str "${strings[$i]}"
|
||||||
|
printf "%s\n" "$str"
|
||||||
|
right str "${strings[$i]}"
|
||||||
|
printf "%s\n" "$str"
|
||||||
|
bottom str "${strings[$i]}"
|
||||||
|
printf "%s\n" "$str"
|
||||||
|
left str "${strings[$i]}"
|
||||||
|
printf "%s\n" "$str"
|
||||||
|
done
|
||||||
|
}
|
||||||
# transform $2 tile to match $1 on left
|
# transform $2 tile to match $1 on left
|
||||||
attach_left() {
|
attach_left() {
|
||||||
local _l="$1"
|
local _l="$1"
|
||||||
@@ -183,8 +196,7 @@ attach_left() {
|
|||||||
;;
|
;;
|
||||||
1) # right
|
1) # right
|
||||||
printf "match=right\n"
|
printf "match=right\n"
|
||||||
r180 "$t"
|
flip_h "$t"
|
||||||
flip_v "$t"
|
|
||||||
;;
|
;;
|
||||||
2) # bottom
|
2) # bottom
|
||||||
printf "match=bottom\n"
|
printf "match=bottom\n"
|
||||||
@@ -241,8 +253,7 @@ attach_top() {
|
|||||||
;;
|
;;
|
||||||
2) # bottom
|
2) # bottom
|
||||||
printf "match=bottom\n"
|
printf "match=bottom\n"
|
||||||
r180 "$t"
|
flip_v "$t"
|
||||||
flip_h "$t"
|
|
||||||
;;
|
;;
|
||||||
3) # left
|
3) # left
|
||||||
printf "match=left\n"
|
printf "match=left\n"
|
||||||
|
Reference in New Issue
Block a user