It involved thousands of ships in more than 100 convoy battles and perhaps 1,000 single-ship encounters, in a theatre covering millions of square miles of ocean. The situation changed constantly, with one side or the other gaining advantage, as participating countries surrendered, joined and even changed sides in the war, and as new weapons, tactics, counter-measures and equipment were developed by both sides. The Allies gradually gained the upper hand, overcoming German surface raiders by the end of 1942 and defeating the U-boats by mid-1943, though losses due to U-boats continued until the war's end.