I dont know really much about the librarys that you have used (I'm using Linux, and some of the librarys are Windows only I think), but I've got a tip that will make it much easier to find the problem.
You should find out if the int end is just changed because of an event or it is something else.
Just put under the: if(position[position_counter][0]>470||position[position_counter][1]>470||position[position_counter][0]<10||position[position_counter][1]<10)
in line 80 an cout << "end\n";
Also it would be better to use a bool instead of an int.
btw. I'm currently installing a compiler on my windows partition (with some problems)
so I will take a closer look on it (well that is if I get it to compile anything)