# generate a random building at a random position r_or_u = randrange(0, 2) if r_or_u == 0: building_type = randrange( 0, my_plan.number_of_residential_projects) else: building_type = randrange( my_plan.number_of_residential_projects, my_plan.number_of_building_projects) # get the real id of the project we have selected building_type = list(my_plan.building_projects)[building_type] row, column = free_cells.pop() # and try to place it on the plan if my_plan.canPlaceBuilding(building_type, row, column): building = my_plan.createBuilding(building_type, row, column) potential = my_plan.calcPotential(building) if potential > 0 or randrange(0, threshold) == 0 or cpt == 0: my_plan.placeBuilding(building) nb_cells += building.project.nb_cells cpt += 1 else: retry.append((row, column)) else: retry.append((row, column)) i += 1 # display progress... if i % step == 0 and i >= step: percent = 100 * nb_cells / (my_plan.nb_rows * my_plan.nb_columns) print(cpt, "(", percent, "%)") free_cells = retry