-echo
-echo -n "Progress: 0%"
-
-# bad implementation of djikstra's algorithm
-while [ "${tentative[$max_x,$max_y]+abc}" ]; do
- echo -n -e "\rProgress: "
- printf "%2d" $((100 - ((${#tentative[@]}*100) / $total_points)))
- echo -n "%"
- # where we are, we have the lowest_cost for this space, so
- lowest_distance[$cur_x,$cur_y]="${tentative["$cur_x,$cur_y"]}"
- unset tentative[$cur_x,$cur_y]
- # now check to the left / right / up / down from our current node
- # and give them tentative values
- # lets do the calcs for the left
- test_x=$((cur_x-1))
- if [ "${tentative[$test_x,$cur_y]+abc}" ]; then
- new_cost=${lowest_distance[$cur_x,$cur_y]}
- ((new_cost+=${map[$test_x,$cur_y]}))
- if [ $new_cost -lt ${tentative[$test_x,$cur_y]} ] || [ "${tentative[$test_x,$cur_y]}" -eq -1 ]; then
- tentative[$test_x,$cur_y]=$new_cost
- fi
- fi
- # and the right
- test_x=$((cur_x+1))
- if [ "${tentative[$test_x,$cur_y]+abc}" ]; then
- new_cost=${lowest_distance[$cur_x,$cur_y]}
- ((new_cost+=${map[$test_x,$cur_y]}))
- if [ $new_cost -lt ${tentative[$test_x,$cur_y]} ] || [ "${tentative[$test_x,$cur_y]}" -eq -1 ]; then
- tentative[$test_x,$cur_y]=$new_cost
- fi
- fi
- # above
- test_y=$((cur_y-1))
- if [ "${tentative[$cur_x,$test_y]+abc}" ]; then
- new_cost=${lowest_distance[$cur_x,$cur_y]}
- ((new_cost+=${map[$cur_x,$test_y]}))
- if [ $new_cost -lt ${tentative[$cur_x,$test_y]} ] || [ "${tentative[$cur_x,$test_y]}" -eq -1 ]; then
- tentative[$cur_x,$test_y]=$new_cost
- fi
- fi
- # below
- test_y=$((cur_y+1))
- if [ "${tentative[$cur_x,$test_y]+abc}" ]; then
- new_cost=${lowest_distance[$cur_x,$cur_y]}
- ((new_cost+=${map[$cur_x,$test_y]}))
- if [ $new_cost -lt ${tentative[$cur_x,$test_y]} ] || [ "${tentative[$cur_x,$test_y]}" -eq -1 ]; then
- tentative[$cur_x,$test_y]=$new_cost
- fi
- fi