12 __robot_start_on_white=0
13 declare -A __robot_grid
14 declare -A __robot_painted
24 __robot_start_on_white=0
27 declare -g -A __robot_grid
28 declare -g -A __robot_painted
31 get_robot_paint_colour() {
32 get_paint_colour $__robot_cur_x $__robot_cur_y
39 if [ ${__robot_grid[$x,$y]+a} ]; then
40 echo ${__robot_grid[$x,$y]}
42 if [ $x -eq 0 ] && [ $y -eq 0 ] && [ $__start_on_white -eq 1 ]; then
50 set_robot_start_on_white() {
53 __robot_start_on_white=$start
56 set_robot_paint_colour() {
59 __robot_grid[$__robot_cur_x,$__robot_cur_y]=$paint_colour
60 if ! [ ${__robot_painted[$__robot_cur_x,$__robot_cur_y]+a} ]; then
61 __robot_painted[$__robot_cur_x,$__robot_cur_y]=1
65 get_robot_paint_count() {
66 echo ${#__robot_painted[@]}
74 case $__robot_direction in
77 __robot_cur_x=$((__robot_cur_x - 1))
81 __robot_cur_y=$((__robot_cur_y - 1))
85 __robot_cur_x=$((__robot_cur_x + 1))
89 __robot_cur_y=$((__robot_cur_y + 1))
94 case $__robot_direction in
97 __robot_cur_x=$((__robot_cur_x + 1))
101 __robot_cur_y=$((__robot_cur_y - 1))
105 __robot_cur_x=$((__robot_cur_x - 1))
109 __robot_cur_y=$((__robot_cur_y + 1))
116 if [ $__robot_cur_x -lt $__robot_lowest_x ]; then
117 __robot_lowest_x=$__robot_cur_x
120 if [ $__robot_cur_x -gt $__robot_highest_x ]; then
121 __robot_highest_x=$__robot_cur_x
124 if [ $__robot_cur_y -lt $__robot_lowest_y ]; then
125 __robot_lowest_y=$__robot_cur_y
128 if [ $__robot_cur_y -gt $__robot_highest_y ]; then
129 __robot_highest_y=$__robot_cur_y
133 do_robot_paint_and_move() {
136 set_robot_paint_colour $paint_colour
137 do_robot_move $direction
143 for (( y=$__robot_lowest_y; y<=$__robot_highest_y; y++ )); do
144 for (( x=$__robot_lowest_x; x<=$__robot_highest_x; x++ )); do
145 echo -n ${colours[$(get_paint_colour $x $y)]}