cur_y=$((cur_y+$minstep_y))
debug_line "Step: $cur_x,$cur_y"
if [ $cur_x -eq $vector1_x ] && [ $cur_y -eq $vector1_y ]; then
- debug_line echo "Collision!"
+ debug_line "Collision!"
return 0
fi
done
# we check for if the first asteroid is blocked viewing the second asteroid
# by the third asteroid, if not we add 1 to it's total
-for asteroid in ${!asteroids[@]}; do
-#for asteroid in 9,0; do
+asteroid_loop=("${!asteroids[@]}")
+index=0
+start_count=${#asteroids[@]}
+for asteroid in ${asteroid_loop[@]}; do
ast1_x=${asteroid%,*}
ast1_y=${asteroid#*,}
- for asteroid2 in ${!asteroids[@]}; do
- #for asteroid2 in 4,5; do
+ cur_count=${#asteroid_loop[@]}
+ percent=$((100-(100*$cur_count / $start_count)))
+ printf '\r%02d%% complete' $percent
+ for asteroid2 in ${asteroid_loop[@]}; do
if [ $asteroid2 == $asteroid ]; then
continue
fi
fi
if ! [ ${cansee[$asteroid,$asteroid2]+a} ]; then # we already calculated this backwards
- for asteroid3 in ${!asteroids[@]}; do
+ for asteroid3 in "${!asteroids[@]}"; do
if [ $asteroid == $asteroid3 ] || [ $asteroid2 == $asteroid3 ]; then
continue
fi
fi
# nothing blocked the view of asteroid2 from asteroid1
debug_line "Apparently $asteroid can set $asteroid2"
- asteroids[$asteroid]=$((asteroids[$asteroid]+1))
+ asteroids[$asteroid]=$((${asteroids[$asteroid]}+1))
+ asteroids[$asteroid2]=$((${asteroids[$asteroid2]}+1))
cansee[$asteroid2,$asteroid]=1 # don't bother doing the expensive calculations on the return path
done
+ unset asteroid_loop[$index]
+ index=$((index+1))
done
+echo -n $'\r'" "$'\r'
best_ast=
best_count=0