however, they do not return to the previous base when I click the same button.
Maybe you are not clearing the occupied status of the base?
Maybe this is the solution, but how do you specify which bases are connected to the buttons in the code?
There are several ways. Since every button is connected to one or two bases, you can define two instance variables: connectionA, connectionB. Manually configure them for every button. When a button is clicked, pick bases with ID=Button.connectionA or ID=Button.connectionB
But the solution with the overlapping paths is probably easier.