You asked for, let's say, raster algorithm but let's try to generalize this problem.
Let's assume that we always remember the circuit of occupied (red) area and store it in a graph which looks like like circular linked list. Each node has coordinates (x, y)
. So we have something like that:
A2 -- A3 -- A4
/ \
A1 A5
\ /
A7 -------- A6
At the same time we remember one point inside the starting area.
Each round in this game starts somewhere on the circuit, either on existing node or on new node between existing two, and ends when the intersection of the motion vector and circuit is detected. Those nodes are P
and R
. Whole route drawned int this round creates new part of the circuit. Motion vector is a step made by "head" in each tick of time.
Starting node P
splits edge A3 - A4
into two edges A3 - P
and P - A4
which are added to the graph. Edge A3 - A4
is removed from the graph.
Each step of the move adds next edge: P - B1
, B1 - B2
, ... Finaly we exchange edge A6 - A7
with A6 - R
and R - A7
.
After each round graph looks like:
B1 -- B2 -- B3
/ \
A2 -- A3 -- P -- A4 B4
/ \ |
A1 A5 |
\ / B5
A7 ------ R --- A6 /
\ /
B7 --------- B6
Now it's time to walk through the graph and collect visiting nodes into new circuit. This walk is described in a range of polygon union algorithms or here (step 3 & 4).
When we have a new circuit, we can draw it and floodfill starting in the remembered point.