# How to calculate area to fill in this Snake/Qix game variant?

I have a game which is a Snake/Qix variant.

The player controls a line which is moving on an island. Player has possibility to leave the island in order to connect that island to itself. Once the connection is made, the new area formed by the connection becomes part of the island (see picture: red line is the path the snake has made while outside the island, dark red pixels are the area/island).

I am trying to find a algorithm (even bruteforce) how to fill the new area (in other words how to do transition between first and second line on the picture).

What I have in mind is to run a path finding algorithm between the enter/exit points. If there is a path, it means the snake connect the island to itself. The path (in green) and red line together forms a closed polygon which can then be filled (how ?)

As it is now, the data is simply defined a 2D array of pixels (eg : 0 = empty, 1 = island, 2 = player snake)

• A simple flood fill algorithm will do the trick here. All you have to do is start at one of the inside pixels, and flood fill the rest. Aug 25, 2016 at 12:07
• The problem is to find which side is the "inside". If you flood fill the wrong side you will fill the whole board. Aug 25, 2016 at 12:12