I found these two articles:
1. Check if a point is inside a polygon: https://www.geeksforgeeks.org/how-to-check-if-a-given-point-lies-inside-a-polygon/
2. Which is based on the algorythm of determinig of the intersection of two segments: https://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/
We treat the objects in the game as points. For example we can say, that if the center of an object is looped then the object itself is looped.
We can determine if a new loop is created. Only in this case we have to go on. In the video it seems that not only intersections but when two points next to each other also creates a loop:
The coordinates of the head is the same as one of the other point of the snake
Or the coordinates of the head is next to the one of the other point of the snake
We can separate all points of the "snake" which are part of a loop (need to find out how, more than one loops are possible):
These are all points from the head toward the tail till we reach the point determined in #2
The 1st algorithm becames simple them:
An object is in a loop, if there are odd number of snake points (determined in #3) whose x coordinate is bigger then the object's x coordinate and the y coordinate is the same as the object's y coordinate
There are some tough cases like this: