From 9ae3b54c417ae06d5cc47cd93530503f8a01252b Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Tue, 6 Oct 2020 02:02:28 +0200 Subject: [PATCH] move function --- main.py | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/main.py b/main.py index 466938a..73a418c 100644 --- a/main.py +++ b/main.py @@ -142,10 +142,10 @@ def develop_society(): for i in range(4): if decision[0][0] == "build_residence": # build housing queue_timeout = 5 - #return build("ModernApartments") if len(state.residences) < len(state.available_residence_buildings): return build(state.available_residence_buildings[len(state.residences)].building_name) - + else: + calculate_residence_score() if decision[0][0] == "build_utility": # build utilities return build("WindTurbine") @@ -198,6 +198,7 @@ def something_needs_attention(): else: return False + def chart_map(): global state for x in range(len(state.map) - 1): @@ -207,6 +208,28 @@ def chart_map(): optimize_available_tiles() +def optimize_available_tiles(): + global average_x, average_y, score_list + average_x = 0 + average_y = 0 + score_list = [] + for tile in available_tiles: # calc average coordinates + average_x += tile[0] + average_y += tile[1] + average_x /= len(available_tiles) + average_y /= len(available_tiles) + for tile in available_tiles: + tile_score = abs(tile[0] - average_x) + abs(tile[1] - average_y) + score_list.append((tile_score, tile)) + + def sort_key(e): + return e[0] + score_list.sort(key=sort_key) + for i in range(len(score_list)): + available_tiles[i] = score_list[i][1] + print("average x,y: " + str(average_x) + ", " + str(average_y)) + + def adjust_energy(current_building): global rounds_between_energy, EMA_temp, state blueprint = game_layer.get_residence_blueprint(current_building.building_name) @@ -233,28 +256,6 @@ def adjust_energy(current_building): return False -def optimize_available_tiles(): - global average_x, average_y, score_list - average_x = 0 - average_y = 0 - score_list = [] - for tile in available_tiles: # calc average coordinates - average_x += tile[0] - average_y += tile[1] - average_x /= len(available_tiles) - average_y /= len(available_tiles) - for tile in available_tiles: - tile_score = abs(tile[0] - average_x) + abs(tile[1] - average_y) - score_list.append((tile_score, tile)) - - def sort_key(e): - return e[0] - score_list.sort(key=sort_key) - for i in range(len(score_list)): - available_tiles[i] = score_list[i][1] - print("average x,y: " + str(average_x) + ", " + str(average_y)) - - def build(structure): global building_under_construction, rounds_between_energy, state # print("Building " + structure)