Most of part 2
[advent-of-code-2019.git] / day11 / run2.sh
diff --git a/day11/run2.sh b/day11/run2.sh
new file mode 100755 (executable)
index 0000000..9520560
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+set -u
+set -e
+
+exec 3<input.txt
+
+OLDIFS=$IFS
+IFS=","
+read -u 3 -a data
+IFS=$OLDIFS
+
+base_dir=$(dirname $(readlink -f $BASH_SOURCE))
+. computer.sh
+. robot.sh
+
+# start the computer as a coproc
+coproc computer (run_program data)
+
+while ( kill -0 $computer_PID >/dev/null 2>&1 ); do
+    get_robot_paint_colour >&${computer[1]}
+    read -u ${computer[0]} direction
+    read -u ${computer[0]} colour
+    do_robot_paint_and_move $direction $colour
+    sleep 0.1
+done
+
+# just incase the spinner is still about
+echo -n $'\r'"                "$'\r'
+
+# we've done all the painting, now lets display it
+draw_panel
+
+echo
+echo "Painted: $(get_robot_paint_count) panels at least once"