UPDATE:First step is finished: i can now create a randomly placed base. No single base is ever the same (give or take the remote possibility that you are a jackpot-winner each time you play the lottery, bcoz then of course, the chances of getting the same base when you reload are about 1,000,000,000 to 1 only; instead of the usual 7 quadrillion to 1 odds
)
Anyway: my code can accept a random spread number which -in theory- can build the base (and connect it with tubes), using the ENTIRE map. Not that this will ever happen.
It does need some work still, as it does not yet take in account to stay at least a few tiles away from mining beacons to leave
some space open for a mine to be built on top of it. At the moment, chances are that for example a residence is built right next to a beacon (i don't know if op2 allows it to be built right op top, but my code sure allows it atm).
On top of that, the tubing has been improved, as i've stated above, but not yet as perfect as a pro-human-player can of course. And each building only has 1 active tube connection, unless it is directly bordering other buildings. But it does try to connect to the closest tube or building it can find.
One more thing that needs attention: placing the tokamak and other potentially hazardous buildings a few tiles away from any other building.
[EDIT]: Updated the code so it will now refuse to build "dangerous" structures, such as tokamaks & adv.lab to close to other buildings. Also the areas around beacons can be kept free of buildings.
An example of running the same script 3 times (pressing 'restart mission' a couple times):