for (int i = 0; i < getNumPlanets(); i++)
{
// find a random position
int randRow;
int randCol;
BoardPosition position;
// find an unoccupied position to place the new planet
do {
randRow = (int)(Math.random() * getNumRows())+1;
randCol = (int)(Math.random() * getNumCols())+1;
position = this.getPosition(randRow, randCol);
} while (position.isOccupied());
// initial ships and production factor
int production = (int)( 1 + Math.max(0, GameContext.random().nextGaussian()) * options.getPlanetProductionRate());
int initialFleet = (int)( 1 + Math.max(0, GameContext.random().nextGaussian()) * options.getInitialFleetSize());
Planet planet = new Planet(PLANET_NAMES[i], initialFleet,
production, position.getLocation());
position.setPiece(planet);
// substitute in the players home planets that have already been created.
for (Player p : players) {
GalacticPlayer newVar = (GalacticPlayer) p;
if (planet.getName() == newVar.getHomePlanet().getName()) {
Planet home = newVar.getHomePlanet();
position.setPiece(home); // replace
home.setLocation(position.getLocation());
}
}
// add the planet to our list
planets_.add((Planet)position.getPiece());
hmPlanets_.put(planet.getName(), (Planet)position.getPiece());
}
}