From 38451297a55c6e7c22c882b2c3683ca64190e01d Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sat, 3 Oct 2020 20:06:28 +0200 Subject: [PATCH 01/61] map functions and exception fix --- main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index c1fc79a..8852750 100644 --- a/main.py +++ b/main.py @@ -23,10 +23,12 @@ def main(): game_layer.start_game() # exit game after timeout start_time = time.time() + chartMap() + optimizeAvailableTiles() while game_layer.game_state.turn < game_layer.game_state.max_turns: try: take_turn() - except: + except Exception: print(traceback.format_exc()) game_layer.end_game() exit() @@ -135,6 +137,7 @@ def chartMap(): for y in range(len(state.map) - 1): if state.map[x][y] == 0: availableTiles.append((x, y)) - +def optimizeAvailableTiles(): + pass if __name__ == "__main__": main() From 5672c340aefea63a68850131a4040b94aad22ae0 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sat, 3 Oct 2020 22:59:47 +0200 Subject: [PATCH 02/61] 70s timeout --- main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.py b/main.py index 8852750..68fd25d 100644 --- a/main.py +++ b/main.py @@ -12,11 +12,10 @@ map_name = "training1" # TODO: You map choice here. If left empty, the map "tra game_layer = GameLayer(api_key) state = game_layer.game_state usePrebuiltStrategy = False -timeUntilRunEnds = 30 +timeUntilRunEnds = 70 def main(): - #game_layer.force_end_game() game_layer.new_game(map_name) print("Starting game: " + game_layer.game_state.game_id) From b484d9ef73f34cf801c1d4cd388ffab7a14d8977 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sat, 3 Oct 2020 23:01:43 +0200 Subject: [PATCH 03/61] adjust energy function, attention and develop function --- main.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 68fd25d..9f61f77 100644 --- a/main.py +++ b/main.py @@ -81,7 +81,10 @@ def take_turn(): # TODO Implement your artificial intelligence here. # TODO Take one action per turn until the game ends. # TODO The following is a short example of how to use the StarterKit - + if something_needs_attention(): + pass + else: + develop_society() # messages and errors for console log for message in game_layer.game_state.messages: @@ -130,13 +133,39 @@ def take_turn(): for error in game_layer.game_state.errors: print("Error: " + error) + def chartMap(): + state = game_layer.game_state availableTiles = [] for x in range(len(state.map) - 1): for y in range(len(state.map) - 1): if state.map[x][y] == 0: availableTiles.append((x, y)) + + def optimizeAvailableTiles(): pass + + +def adjustEnergy(current_building, target_temp): + current_blueprint = game_layer.get_residence_blueprint(current_building.building_name) + + base_energy_need = current_blueprint.base_energy_need + indoor_temp = current_building.temperature + degrees_per_pop = 0.04 + current_pop = current_building.current_pop + outdoor_temp = game_layer.game_state.current_temp + emissivity = current_blueprint.emissivity + degrees_per_excess_mwh = 0.75 + + effective_energy_in = -1 * (base_energy_need + (indoor_temp + degrees_per_pop * current_pop - (indoor_temp - outdoor_temp) * emissivity - target_temp)/degrees_per_excess_mwh) + game_layer.adjust_energy_level((current_building.X, current_building.Y), effective_energy_in) + +def something_needs_attention(): + pass + +def develop_society(): + pass + if __name__ == "__main__": main() From 6aa69eb842207a62f48568eec08c140a326c87fb Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sun, 4 Oct 2020 03:15:32 +0200 Subject: [PATCH 04/61] global vars --- main.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.py b/main.py index 9f61f77..0929919 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ import time import sys from sys import exit from game_layer import GameLayer +import game_state import traceback api_key = "74e3998d-ed3d-4d46-9ea8-6aab2efd8ae3" @@ -13,6 +14,10 @@ game_layer = GameLayer(api_key) state = game_layer.game_state usePrebuiltStrategy = False timeUntilRunEnds = 70 +utilities = 3 + +building_under_construction = False +availableTiles = [] def main(): From 942dc02331658c7cb562932a1371eb4a4f736000 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sun, 4 Oct 2020 03:16:13 +0200 Subject: [PATCH 05/61] optimize fun --- main.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 0929919..38dd35c 100644 --- a/main.py +++ b/main.py @@ -28,7 +28,6 @@ def main(): # exit game after timeout start_time = time.time() chartMap() - optimizeAvailableTiles() while game_layer.game_state.turn < game_layer.game_state.max_turns: try: take_turn() @@ -90,7 +89,6 @@ def take_turn(): pass else: develop_society() - # messages and errors for console log for message in game_layer.game_state.messages: print(message) @@ -141,14 +139,14 @@ def take_turn(): def chartMap(): state = game_layer.game_state - availableTiles = [] for x in range(len(state.map) - 1): for y in range(len(state.map) - 1): if state.map[x][y] == 0: availableTiles.append((x, y)) - + optimizeAvailableTiles() def optimizeAvailableTiles(): + #hitta #utilities antal bästa platser i mitten av smeten och sätt de först, sätt allt runt dem i ordning så närmast är längst fram i listan pass From 0918549cfbc25e738b472c12c39e674e972bbb54 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sun, 4 Oct 2020 03:17:11 +0200 Subject: [PATCH 06/61] build structure function (working ish?) and develop society to test it --- main.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 38dd35c..321ad1a 100644 --- a/main.py +++ b/main.py @@ -168,7 +168,36 @@ def something_needs_attention(): pass def develop_society(): - pass + #state = game_layer.game_state + if len(game_layer.game_state.residences) < 1: + build("Apartments") + elif False: + pass + else: + game_layer.wait() + +def build(structure): + print("Building " + structure) + state = game_layer.game_state + global building_under_construction + for i in range(len(availableTiles)): + if isinstance(availableTiles[i], tuple): + game_layer.place_foundation(availableTiles[i], structure) + for j in range(len(state.residences)): + building = state.residences[j] + coords_to_check = (building.X, building.Y) + if coords_to_check == availableTiles[i]: + availableTiles[i] = building + building_under_construction = (building.X,building.Y) + return True + for j in range(len(state.utilities)): + building = state.utilities[j] + coords_to_check = (building.X, building.Y) + if coords_to_check == availableTiles[i]: + availableTiles[i] = building + building_under_construction = (building.X,building.Y) + return True + if __name__ == "__main__": main() From b9ea513f50562a5a566b12ee32a52914d47e0903 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sun, 4 Oct 2020 04:58:59 +0200 Subject: [PATCH 07/61] clear all active games --- clearGames.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 clearGames.py diff --git a/clearGames.py b/clearGames.py new file mode 100644 index 0000000..e36f892 --- /dev/null +++ b/clearGames.py @@ -0,0 +1,8 @@ +from game_layer import GameLayer +api_key = "74e3998d-ed3d-4d46-9ea8-6aab2efd8ae3" +game_layer = GameLayer(api_key) +state = game_layer.game_state +game_layer.force_end_game() +game_layer.force_end_game() +game_layer.force_end_game() +game_layer.force_end_game() \ No newline at end of file From 04e5fac1656b4b489f80979a640d18601e8b874a Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sun, 4 Oct 2020 05:00:23 +0200 Subject: [PATCH 08/61] Construction residences work --- main.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 321ad1a..4483549 100644 --- a/main.py +++ b/main.py @@ -16,7 +16,7 @@ usePrebuiltStrategy = False timeUntilRunEnds = 70 utilities = 3 -building_under_construction = False +building_under_construction = None availableTiles = [] @@ -165,12 +165,25 @@ def adjustEnergy(current_building, target_temp): game_layer.adjust_energy_level((current_building.X, current_building.Y), effective_energy_in) def something_needs_attention(): - pass + print("Checking for emergencies") + global building_under_construction + if building_under_construction is not None: + print(building_under_construction) + if game_layer.game_state.residences[building_under_construction[2]].build_progress < 100: # TODO: inte ba kolla residence utan också utility + game_layer.build((building_under_construction[0], building_under_construction[1])) + return True + else: + building_under_construction = None + return False + elif False: + return True + else: + return False def develop_society(): #state = game_layer.game_state - if len(game_layer.game_state.residences) < 1: - build("Apartments") + if len(game_layer.game_state.residences) < 6: + build("ModernApartments") elif False: pass else: @@ -188,14 +201,14 @@ def build(structure): coords_to_check = (building.X, building.Y) if coords_to_check == availableTiles[i]: availableTiles[i] = building - building_under_construction = (building.X,building.Y) + building_under_construction = (building.X, building.Y, j) return True for j in range(len(state.utilities)): building = state.utilities[j] coords_to_check = (building.X, building.Y) if coords_to_check == availableTiles[i]: availableTiles[i] = building - building_under_construction = (building.X,building.Y) + building_under_construction = (building.X, building.Y, j) return True From 8b6eb1abb245159ad4ee26e7d69a2ea8f606b9d6 Mon Sep 17 00:00:00 2001 From: linhara Date: Sun, 4 Oct 2020 12:26:34 +0200 Subject: [PATCH 09/61] linus take turn big --- main.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 5eb8eba..a5dcc8d 100644 --- a/main.py +++ b/main.py @@ -38,36 +38,88 @@ def main(): print("Done with game: " + game_layer.game_state.game_id) print("Final score was: " + str(game_layer.get_score()["finalScore"])) -def linus_take_turn(): +def linus_take_turn(i): freeSpace = [] state = game_layer.game_state - for i in range(len(state.map)-1): - for j in range(len(state.map)-1): - if state.map[i][j] == 0: - freeSpace.append((i,j)) + for x in range(len(state.map)-1): + for y in range(len(state.map)-1): + if state.map[x][y] == 0: + freeSpace.append((x,y)) #print(mylist) + #if (i == 0 or i%5 == 0)and i<26: + # game_layer.place_foundation(freeSpace[(i//5)+2], game_layer.game_state.available_residence_buildings[i//5].building_name) + if (game_layer.game_state.turn == 0): game_layer.place_foundation(freeSpace[2], game_layer.game_state.available_residence_buildings[0].building_name) the_first_residence = state.residences[0] if the_first_residence.build_progress < 100: game_layer.build(freeSpace[2]) - if len(state.residences)==1: - game_layer.place_foundation(freeSpace[3], game_layer.game_state.available_residence_buildings[4].building_name) + if len(state.residences) == 1: + game_layer.place_foundation(freeSpace[3], game_layer.game_state.available_residence_buildings[5].building_name) the_second_residence = state.residences[1] if the_second_residence.build_progress < 100: game_layer.build(freeSpace[3]) + if len(state.residences) == 2: + game_layer.place_foundation(freeSpace[5], game_layer.game_state.available_residence_buildings[0].building_name) + the_third_residence = state.residences[2] + if the_third_residence.build_progress < 100: + game_layer.build(freeSpace[5]) + if len(state.residences) == 3: + game_layer.place_foundation((4,4), game_layer.game_state.available_residence_buildings[4].building_name) + the_fourth_residence = state.residences[3] + if the_fourth_residence.build_progress < 100: + game_layer.build((4,4)) + + if len(state.residences) == 4: + game_layer.place_foundation((4,5), game_layer.game_state.available_residence_buildings[4].building_name) + the_fifth_residence = state.residences[4] + if the_fifth_residence.build_progress < 100: + game_layer.build((4,5)) + + if len(state.residences) == 5: + game_layer.place_foundation((4,6), game_layer.game_state.available_residence_buildings[4].building_name) + the_sixth_residence = state.residences[5] + if (the_sixth_residence.build_progress < 100) and game_layer.game_state.funds > 4000: + game_layer.build((4,6)) + elif the_first_residence.health < 70: game_layer.maintenance(freeSpace[2]) elif the_second_residence.health < 70: game_layer.maintenance(freeSpace[3]) + elif the_third_residence.health < 70: + game_layer.maintenance(freeSpace[5]) + elif the_fourth_residence.health < 70: + game_layer.maintenance((4,4)) + elif the_fifth_residence.health < 70: + game_layer.maintenance((4,5)) + elif the_sixth_residence.health < 70: + game_layer.maintenance((4,6)) elif (the_second_residence.health > 70) and not len(state.utilities) > 0: game_layer.place_foundation(freeSpace[4], game_layer.game_state.available_utility_buildings[2].building_name) elif (state.utilities[0].build_progress < 100): game_layer.build(freeSpace[4]) + + #elif (game_layer.game_state.turn > 35) and not len(state.utilities) > 1: + # game_layer.place_foundation((4,6), game_layer.game_state.available_utility_buildings[1].building_name) + #elif (state.utilities[1].build_progress < 100): + # game_layer.build((4,6)) + + elif (game_layer.game_state.turn % 10 == 0): + adjustEnergy2(the_first_residence, 21) + elif (game_layer.game_state.turn % 5 == 0): + adjustEnergy2(the_second_residence, 21) + elif (game_layer.game_state.turn % 5 == 1): + adjustEnergy2(the_third_residence, 21) + elif (game_layer.game_state.turn % 5 == 2): + adjustEnergy2(the_fourth_residence, 21) + elif (game_layer.game_state.turn % 5 == 3): + adjustEnergy2(the_fifth_residence, 21) + elif (game_layer.game_state.turn % 5 == 4): + adjustEnergy2(the_sixth_residence, 21) else: # messages and errors for console log game_layer.wait() From 849542dd035c6d1e2d6f71c5ea59bdc0c18ce1d0 Mon Sep 17 00:00:00 2001 From: linhara Date: Sun, 4 Oct 2020 13:01:13 +0200 Subject: [PATCH 10/61] linus skit --- main.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index a5dcc8d..ada3548 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,6 @@ from sys import exit from game_layer import GameLayer import traceback -timeUntilRunEnds = 30 api_key = "74e3998d-ed3d-4d46-9ea8-6aab2efd8ae3" # The different map names can be found on considition.com/rules @@ -14,6 +13,7 @@ map_name = "training1" # TODO: You map choice here. If left empty, the map "tra game_layer = GameLayer(api_key) state = game_layer.game_state usePrebuiltStrategy = False +timeUntilRunEnds = 50 def main(): @@ -38,7 +38,7 @@ def main(): print("Done with game: " + game_layer.game_state.game_id) print("Final score was: " + str(game_layer.get_score()["finalScore"])) -def linus_take_turn(i): +def linus_take_turn(): freeSpace = [] state = game_layer.game_state @@ -63,24 +63,24 @@ def linus_take_turn(i): if the_second_residence.build_progress < 100: game_layer.build(freeSpace[3]) if len(state.residences) == 2: - game_layer.place_foundation(freeSpace[5], game_layer.game_state.available_residence_buildings[0].building_name) + game_layer.place_foundation(freeSpace[5], game_layer.game_state.available_residence_buildings[1].building_name) the_third_residence = state.residences[2] if the_third_residence.build_progress < 100: game_layer.build(freeSpace[5]) if len(state.residences) == 3: - game_layer.place_foundation((4,4), game_layer.game_state.available_residence_buildings[4].building_name) + game_layer.place_foundation((4,4), game_layer.game_state.available_residence_buildings[5].building_name) the_fourth_residence = state.residences[3] if the_fourth_residence.build_progress < 100: game_layer.build((4,4)) if len(state.residences) == 4: - game_layer.place_foundation((4,5), game_layer.game_state.available_residence_buildings[4].building_name) + game_layer.place_foundation((4,5), game_layer.game_state.available_residence_buildings[3].building_name) the_fifth_residence = state.residences[4] if the_fifth_residence.build_progress < 100: game_layer.build((4,5)) if len(state.residences) == 5: - game_layer.place_foundation((4,6), game_layer.game_state.available_residence_buildings[4].building_name) + game_layer.place_foundation((4,6), game_layer.game_state.available_residence_buildings[5].building_name) the_sixth_residence = state.residences[5] if (the_sixth_residence.build_progress < 100) and game_layer.game_state.funds > 4000: game_layer.build((4,6)) @@ -109,17 +109,17 @@ def linus_take_turn(i): # game_layer.build((4,6)) elif (game_layer.game_state.turn % 10 == 0): - adjustEnergy2(the_first_residence, 21) + adjustEnergy(the_first_residence, 21) elif (game_layer.game_state.turn % 5 == 0): - adjustEnergy2(the_second_residence, 21) + adjustEnergy(the_second_residence, 21) elif (game_layer.game_state.turn % 5 == 1): - adjustEnergy2(the_third_residence, 21) + adjustEnergy(the_third_residence, 21) elif (game_layer.game_state.turn % 5 == 2): - adjustEnergy2(the_fourth_residence, 21) + adjustEnergy(the_fourth_residence, 21) elif (game_layer.game_state.turn % 5 == 3): - adjustEnergy2(the_fifth_residence, 21) + adjustEnergy(the_fifth_residence, 21) elif (game_layer.game_state.turn % 5 == 4): - adjustEnergy2(the_sixth_residence, 21) + adjustEnergy(the_sixth_residence, 21) else: # messages and errors for console log game_layer.wait() From f4dd5073c6d946a38d1f57c952af23eabaae1e1f Mon Sep 17 00:00:00 2001 From: linhara Date: Sun, 4 Oct 2020 13:02:32 +0200 Subject: [PATCH 11/61] =?UTF-8?q?linus=20n=C3=A4stan=20bra=20adjustEnergy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/main.py b/main.py index ada3548..eb627f9 100644 --- a/main.py +++ b/main.py @@ -189,5 +189,24 @@ def chartMap(): if state.map[x][y] == 0: availableTiles.append((x, y)) +def adjustEnergy(currentBuilding, newTemp): + blueprint = game_layer.get_residence_blueprint(currentBuilding.building_name) + outDoorTemp = game_layer.game_state.current_temp + + effectiveEnergyIn = ((newTemp - currentBuilding.temperature - 0.04 * currentBuilding.current_pop + (currentBuilding.temperature - outDoorTemp)* 2 * blueprint.emissivity) / 0.75) + blueprint.base_energy_need + effectiveEnergyIn /= 1.7 + + if effectiveEnergyIn > blueprint.base_energy_need: + game_layer.adjust_energy_level((currentBuilding.X, currentBuilding.Y), effectiveEnergyIn) + elif effectiveEnergyIn < blueprint.base_energy_need: + game_layer.adjust_energy_level((currentBuilding.X, currentBuilding.Y), blueprint.base_energy_need + 0.01) + else: + print("you did it!") + game_layer.wait() + + + + + if __name__ == "__main__": main() From 0c49a3fb375647883c6159a112e2fb4a21e0cd3e Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sun, 4 Oct 2020 13:53:53 +0200 Subject: [PATCH 12/61] lek med energy formel rounds between energy --- main.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index eb627f9..617efc9 100644 --- a/main.py +++ b/main.py @@ -14,6 +14,8 @@ game_layer = GameLayer(api_key) state = game_layer.game_state usePrebuiltStrategy = False timeUntilRunEnds = 50 +rounds_between_energy = 7 + def main(): @@ -108,18 +110,18 @@ def linus_take_turn(): #elif (state.utilities[1].build_progress < 100): # game_layer.build((4,6)) - elif (game_layer.game_state.turn % 10 == 0): - adjustEnergy(the_first_residence, 21) - elif (game_layer.game_state.turn % 5 == 0): - adjustEnergy(the_second_residence, 21) - elif (game_layer.game_state.turn % 5 == 1): - adjustEnergy(the_third_residence, 21) - elif (game_layer.game_state.turn % 5 == 2): - adjustEnergy(the_fourth_residence, 21) - elif (game_layer.game_state.turn % 5 == 3): - adjustEnergy(the_fifth_residence, 21) - elif (game_layer.game_state.turn % 5 == 4): - adjustEnergy(the_sixth_residence, 21) + elif (game_layer.game_state.turn % rounds_between_energy == 0): + adjustEnergy(the_first_residence) + elif (game_layer.game_state.turn % rounds_between_energy == 1): + adjustEnergy(the_second_residence) + elif (game_layer.game_state.turn % rounds_between_energy == 2): + adjustEnergy(the_third_residence) + elif (game_layer.game_state.turn % rounds_between_energy == 3): + adjustEnergy(the_fourth_residence) + elif (game_layer.game_state.turn % rounds_between_energy == 4): + adjustEnergy(the_fifth_residence) + elif (game_layer.game_state.turn % rounds_between_energy == 5): + adjustEnergy(the_sixth_residence) else: # messages and errors for console log game_layer.wait() @@ -189,12 +191,14 @@ def chartMap(): if state.map[x][y] == 0: availableTiles.append((x, y)) -def adjustEnergy(currentBuilding, newTemp): +def adjustEnergy(currentBuilding): + global rounds_between_engery blueprint = game_layer.get_residence_blueprint(currentBuilding.building_name) outDoorTemp = game_layer.game_state.current_temp - effectiveEnergyIn = ((newTemp - currentBuilding.temperature - 0.04 * currentBuilding.current_pop + (currentBuilding.temperature - outDoorTemp)* 2 * blueprint.emissivity) / 0.75) + blueprint.base_energy_need - effectiveEnergyIn /= 1.7 + temp_acceleration = (2*(21 - currentBuilding.temperature)/(rounds_between_energy**2)) + + effectiveEnergyIn = ((temp_acceleration - 0.04 * currentBuilding.current_pop + (currentBuilding.temperature - outDoorTemp) * blueprint.emissivity) / 0.75) + blueprint.base_energy_need if effectiveEnergyIn > blueprint.base_energy_need: game_layer.adjust_energy_level((currentBuilding.X, currentBuilding.Y), effectiveEnergyIn) From cb2f1999d90a26f204339bfb91e226374b6e1608 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sun, 4 Oct 2020 14:23:50 +0200 Subject: [PATCH 13/61] energy WORKING ema temp sak --- main.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 617efc9..aa82e5a 100644 --- a/main.py +++ b/main.py @@ -14,8 +14,9 @@ game_layer = GameLayer(api_key) state = game_layer.game_state usePrebuiltStrategy = False timeUntilRunEnds = 50 -rounds_between_energy = 7 +rounds_between_energy = 6 +EMA_temp = None def main(): @@ -26,8 +27,13 @@ def main(): game_layer.start_game() # exit game after timeout start_time = time.time() + global EMA_temp while game_layer.game_state.turn < game_layer.game_state.max_turns: try: + if EMA_temp is None: + EMA_temp = game_layer.game_state.current_temp + ema_k_value = (2/(rounds_between_energy+1)) + EMA_temp = game_layer.game_state.current_temp * ema_k_value + EMA_temp*(1-ema_k_value) linus_take_turn() except: print(traceback.format_exc()) @@ -49,7 +55,6 @@ def linus_take_turn(): if state.map[x][y] == 0: freeSpace.append((x,y)) - #print(mylist) #if (i == 0 or i%5 == 0)and i<26: # game_layer.place_foundation(freeSpace[(i//5)+2], game_layer.game_state.available_residence_buildings[i//5].building_name) @@ -70,7 +75,7 @@ def linus_take_turn(): if the_third_residence.build_progress < 100: game_layer.build(freeSpace[5]) if len(state.residences) == 3: - game_layer.place_foundation((4,4), game_layer.game_state.available_residence_buildings[5].building_name) + game_layer.place_foundation((4,4), game_layer.game_state.available_residence_buildings[4].building_name) the_fourth_residence = state.residences[3] if the_fourth_residence.build_progress < 100: game_layer.build((4,4)) @@ -82,7 +87,7 @@ def linus_take_turn(): game_layer.build((4,5)) if len(state.residences) == 5: - game_layer.place_foundation((4,6), game_layer.game_state.available_residence_buildings[5].building_name) + game_layer.place_foundation((4,6), game_layer.game_state.available_residence_buildings[4].building_name) the_sixth_residence = state.residences[5] if (the_sixth_residence.build_progress < 100) and game_layer.game_state.funds > 4000: game_layer.build((4,6)) @@ -192,11 +197,12 @@ def chartMap(): availableTiles.append((x, y)) def adjustEnergy(currentBuilding): - global rounds_between_engery + global rounds_between_energy + global EMA_temp blueprint = game_layer.get_residence_blueprint(currentBuilding.building_name) - outDoorTemp = game_layer.game_state.current_temp + outDoorTemp = game_layer.game_state.current_temp * 2 - EMA_temp - temp_acceleration = (2*(21 - currentBuilding.temperature)/(rounds_between_energy**2)) + temp_acceleration = (2*(21 - currentBuilding.temperature)/(rounds_between_energy)) effectiveEnergyIn = ((temp_acceleration - 0.04 * currentBuilding.current_pop + (currentBuilding.temperature - outDoorTemp) * blueprint.emissivity) / 0.75) + blueprint.base_energy_need From 6cf041c70ef0579f21f1b4e77a5472941fc8a7f6 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sun, 4 Oct 2020 15:38:12 +0200 Subject: [PATCH 14/61] relative roundsenergy, build stuff HS, auto maintainance --- main.py | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 1368754..59625a4 100644 --- a/main.py +++ b/main.py @@ -14,7 +14,7 @@ game_layer = GameLayer(api_key) state = game_layer.game_state usePrebuiltStrategy = False timeUntilRunEnds = 50 -rounds_between_energy = 6 +rounds_between_energy = 5 utilities = 3 EMA_temp = None @@ -37,7 +37,7 @@ def main(): EMA_temp = game_layer.game_state.current_temp ema_k_value = (2/(rounds_between_energy+1)) EMA_temp = game_layer.game_state.current_temp * ema_k_value + EMA_temp*(1-ema_k_value) - linus_take_turn() + take_turn() except: print(traceback.format_exc()) game_layer.end_game() @@ -233,7 +233,29 @@ def optimizeAvailableTiles(): def something_needs_attention(): print("Checking for emergencies") global building_under_construction - if building_under_construction is not None: + global edit_temp + global maintain + state = game_layer.game_state + + #check if temp needs adjusting + edit_temp = (False, 0) + for i in range(len(state.residences)): + if (state.turn % rounds_between_energy == i) and not state.residences[i].build_progress < 100: + edit_temp = (True, i) + + #check if need for maintainance + maintain = (False, 0) + for i in range(len(state.residences)): + if state.residences[i].health < 41+rounds_between_energy*game_layer.get_residence_blueprint(state.residences[i].building_name).decay_rate: + maintain = (True, i) + + if maintain[0]: + game_layer.maintenance((state.residences[maintain[1]].X, state.residences[maintain[1]].Y)) + return True + elif edit_temp[0]: #adjust temp of building + adjustEnergy(state.residences[edit_temp[1]]) + return True + elif building_under_construction is not None: #finish construction print(building_under_construction) if game_layer.game_state.residences[building_under_construction[2]].build_progress < 100: # TODO: inte ba kolla residence utan också utility game_layer.build((building_under_construction[0], building_under_construction[1])) @@ -241,17 +263,19 @@ def something_needs_attention(): else: building_under_construction = None return False - elif False: - return True else: return False def develop_society(): - #state = game_layer.game_state - if len(game_layer.game_state.residences) < 6: - build("ModernApartments") - elif False: - pass + state = game_layer.game_state + if len(game_layer.game_state.residences) < 4: + build("Apartments") + elif len(game_layer.game_state.utilities) <1: + game_layer.place_foundation((3,6), "WindTurbine") + elif (state.utilities[0].build_progress < 100): + game_layer.build((3,6)) + elif state.funds > 25000 and len(game_layer.game_state.residences) < 7: + build("HighRise") else: game_layer.wait() @@ -259,6 +283,7 @@ def build(structure): print("Building " + structure) state = game_layer.game_state global building_under_construction + global rounds_between_energy for i in range(len(availableTiles)): if isinstance(availableTiles[i], tuple): game_layer.place_foundation(availableTiles[i], structure) @@ -268,6 +293,7 @@ def build(structure): if coords_to_check == availableTiles[i]: availableTiles[i] = building building_under_construction = (building.X, building.Y, j) + rounds_between_energy = len(state.residences)+5 return True for j in range(len(state.utilities)): building = state.utilities[j] @@ -275,6 +301,7 @@ def build(structure): if coords_to_check == availableTiles[i]: availableTiles[i] = building building_under_construction = (building.X, building.Y, j) + rounds_between_energy = len(state.residences)+5 return True From f5f694df3ee668601a64228b7e9ec0d221e8942d Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sun, 4 Oct 2020 17:52:27 +0200 Subject: [PATCH 15/61] construct utility buildings fix --- main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 59625a4..5a29db8 100644 --- a/main.py +++ b/main.py @@ -256,8 +256,10 @@ def something_needs_attention(): adjustEnergy(state.residences[edit_temp[1]]) return True elif building_under_construction is not None: #finish construction - print(building_under_construction) - if game_layer.game_state.residences[building_under_construction[2]].build_progress < 100: # TODO: inte ba kolla residence utan också utility + if (len(game_layer.game_state.residences) >= building_under_construction[2]) and (game_layer.game_state.residences[building_under_construction[2]].build_progress < 100): + game_layer.build((building_under_construction[0], building_under_construction[1])) + return True + elif (len(game_layer.game_state.utilities)-1 >= building_under_construction[2]) and (game_layer.game_state.utilities[building_under_construction[2]].build_progress < 100): game_layer.build((building_under_construction[0], building_under_construction[1])) return True else: From 0a8934c974602cf1f6327db72d1a03fa0116a083 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sun, 4 Oct 2020 17:54:10 +0200 Subject: [PATCH 16/61] testing buildings in develop --- main.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 5a29db8..70d74e9 100644 --- a/main.py +++ b/main.py @@ -270,13 +270,11 @@ def something_needs_attention(): def develop_society(): state = game_layer.game_state - if len(game_layer.game_state.residences) < 4: + if len(state.residences) < 5: build("Apartments") - elif len(game_layer.game_state.utilities) <1: - game_layer.place_foundation((3,6), "WindTurbine") - elif (state.utilities[0].build_progress < 100): - game_layer.build((3,6)) - elif state.funds > 25000 and len(game_layer.game_state.residences) < 7: + elif len(state.utilities) < 1: + build("WindTurbine") + elif state.funds > 25000 and len(game_layer.game_state.residences) < 11: build("HighRise") else: game_layer.wait() From 0833b843a38b997a7c4dbda1fd8ac9fdc915bdba Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sun, 4 Oct 2020 17:54:41 +0200 Subject: [PATCH 17/61] check if structures are available before building --- main.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 70d74e9..0ab3454 100644 --- a/main.py +++ b/main.py @@ -287,22 +287,27 @@ def build(structure): for i in range(len(availableTiles)): if isinstance(availableTiles[i], tuple): game_layer.place_foundation(availableTiles[i], structure) - for j in range(len(state.residences)): - building = state.residences[j] - coords_to_check = (building.X, building.Y) - if coords_to_check == availableTiles[i]: - availableTiles[i] = building - building_under_construction = (building.X, building.Y, j) - rounds_between_energy = len(state.residences)+5 - return True - for j in range(len(state.utilities)): - building = state.utilities[j] - coords_to_check = (building.X, building.Y) - if coords_to_check == availableTiles[i]: - availableTiles[i] = building - building_under_construction = (building.X, building.Y, j) - rounds_between_energy = len(state.residences)+5 - return True + for building in state.available_residence_buildings: + if structure in building.building_name: + for j in range(len(state.residences)): + building = state.residences[j] + coords_to_check = (building.X, building.Y) + if coords_to_check == availableTiles[i]: + availableTiles[i] = building + building_under_construction = (building.X, building.Y, j) + rounds_between_energy = len(state.residences)+2 + return True + for building in state.available_utility_buildings: + if structure in building.building_name: + for j in range(len(state.utilities)): + building = state.utilities[j] + coords_to_check = (building.X, building.Y) + if coords_to_check == availableTiles[i]: + availableTiles[i] = building + building_under_construction = (building.X, building.Y, j) + rounds_between_energy = len(state.residences)+2 + return True + return False if __name__ == "__main__": From 143a5dbecff5f4d2810b6b65c9d32a2eecb06955 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Mon, 5 Oct 2020 16:41:09 +0200 Subject: [PATCH 18/61] flytta upp dev society & need attention i koden --- main.py | 72 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/main.py b/main.py index 0ab3454..24846f9 100644 --- a/main.py +++ b/main.py @@ -194,42 +194,6 @@ def take_turn(): for error in game_layer.game_state.errors: print("Error: " + error) - -def chartMap(): - state = game_layer.game_state - for x in range(len(state.map) - 1): - for y in range(len(state.map) - 1): - if state.map[x][y] == 0: - availableTiles.append((x, y)) - optimizeAvailableTiles() - -def adjustEnergy(currentBuilding): - global rounds_between_energy - global EMA_temp - blueprint = game_layer.get_residence_blueprint(currentBuilding.building_name) - outDoorTemp = game_layer.game_state.current_temp * 2 - EMA_temp - - temp_acceleration = (2*(21 - currentBuilding.temperature)/(rounds_between_energy)) - - effectiveEnergyIn = ((temp_acceleration - 0.04 * currentBuilding.current_pop + (currentBuilding.temperature - outDoorTemp) * blueprint.emissivity) / 0.75) + blueprint.base_energy_need - - if effectiveEnergyIn > blueprint.base_energy_need: - game_layer.adjust_energy_level((currentBuilding.X, currentBuilding.Y), effectiveEnergyIn) - elif effectiveEnergyIn < blueprint.base_energy_need: - game_layer.adjust_energy_level((currentBuilding.X, currentBuilding.Y), blueprint.base_energy_need + 0.01) - else: - print("you did it!") - game_layer.wait() - - - - - -def optimizeAvailableTiles(): - #hitta #utilities antal bästa platser i mitten av smeten och sätt de först, sätt allt runt dem i ordning så närmast är längst fram i listan - pass - - def something_needs_attention(): print("Checking for emergencies") global building_under_construction @@ -279,6 +243,42 @@ def develop_society(): else: game_layer.wait() +def chartMap(): + state = game_layer.game_state + for x in range(len(state.map) - 1): + for y in range(len(state.map) - 1): + if state.map[x][y] == 0: + availableTiles.append((x, y)) + optimizeAvailableTiles() + +def adjustEnergy(currentBuilding): + global rounds_between_energy + global EMA_temp + blueprint = game_layer.get_residence_blueprint(currentBuilding.building_name) + outDoorTemp = game_layer.game_state.current_temp * 2 - EMA_temp + + temp_acceleration = (2*(21 - currentBuilding.temperature)/(rounds_between_energy)) + + effectiveEnergyIn = ((temp_acceleration - 0.04 * currentBuilding.current_pop + (currentBuilding.temperature - outDoorTemp) * blueprint.emissivity) / 0.75) + blueprint.base_energy_need + + if effectiveEnergyIn > blueprint.base_energy_need: + game_layer.adjust_energy_level((currentBuilding.X, currentBuilding.Y), effectiveEnergyIn) + elif effectiveEnergyIn < blueprint.base_energy_need: + game_layer.adjust_energy_level((currentBuilding.X, currentBuilding.Y), blueprint.base_energy_need + 0.01) + else: + print("you did it!") + game_layer.wait() + + + + + +def optimizeAvailableTiles(): + #hitta #utilities antal bästa platser i mitten av smeten och sätt de först, sätt allt runt dem i ordning så närmast är längst fram i listan + pass + + + def build(structure): print("Building " + structure) state = game_layer.game_state From 8408f8f0a01bfb78292930face2d9ed10b9b39c2 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Mon, 5 Oct 2020 16:42:31 +0200 Subject: [PATCH 19/61] purge linus_taketurn code --- main.py | 92 --------------------------------------------------------- 1 file changed, 92 deletions(-) diff --git a/main.py b/main.py index 24846f9..93e8bb2 100644 --- a/main.py +++ b/main.py @@ -49,94 +49,6 @@ def main(): print("Done with game: " + game_layer.game_state.game_id) print("Final score was: " + str(game_layer.get_score()["finalScore"])) -def linus_take_turn(): - freeSpace = [] - - state = game_layer.game_state - for x in range(len(state.map)-1): - for y in range(len(state.map)-1): - if state.map[x][y] == 0: - freeSpace.append((x,y)) - - - #if (i == 0 or i%5 == 0)and i<26: - # game_layer.place_foundation(freeSpace[(i//5)+2], game_layer.game_state.available_residence_buildings[i//5].building_name) - - if (game_layer.game_state.turn == 0): - game_layer.place_foundation(freeSpace[2], game_layer.game_state.available_residence_buildings[0].building_name) - the_first_residence = state.residences[0] - if the_first_residence.build_progress < 100: - game_layer.build(freeSpace[2]) - if len(state.residences) == 1: - game_layer.place_foundation(freeSpace[3], game_layer.game_state.available_residence_buildings[5].building_name) - the_second_residence = state.residences[1] - if the_second_residence.build_progress < 100: - game_layer.build(freeSpace[3]) - if len(state.residences) == 2: - game_layer.place_foundation(freeSpace[5], game_layer.game_state.available_residence_buildings[1].building_name) - the_third_residence = state.residences[2] - if the_third_residence.build_progress < 100: - game_layer.build(freeSpace[5]) - if len(state.residences) == 3: - game_layer.place_foundation((4,4), game_layer.game_state.available_residence_buildings[4].building_name) - the_fourth_residence = state.residences[3] - if the_fourth_residence.build_progress < 100: - game_layer.build((4,4)) - - if len(state.residences) == 4: - game_layer.place_foundation((4,5), game_layer.game_state.available_residence_buildings[3].building_name) - the_fifth_residence = state.residences[4] - if the_fifth_residence.build_progress < 100: - game_layer.build((4,5)) - - if len(state.residences) == 5: - game_layer.place_foundation((4,6), game_layer.game_state.available_residence_buildings[4].building_name) - the_sixth_residence = state.residences[5] - if (the_sixth_residence.build_progress < 100) and game_layer.game_state.funds > 4000: - game_layer.build((4,6)) - - elif the_first_residence.health < 70: - game_layer.maintenance(freeSpace[2]) - elif the_second_residence.health < 70: - game_layer.maintenance(freeSpace[3]) - elif the_third_residence.health < 70: - game_layer.maintenance(freeSpace[5]) - elif the_fourth_residence.health < 70: - game_layer.maintenance((4,4)) - elif the_fifth_residence.health < 70: - game_layer.maintenance((4,5)) - elif the_sixth_residence.health < 70: - game_layer.maintenance((4,6)) - elif (the_second_residence.health > 70) and not len(state.utilities) > 0: - game_layer.place_foundation(freeSpace[4], game_layer.game_state.available_utility_buildings[2].building_name) - elif (state.utilities[0].build_progress < 100): - game_layer.build(freeSpace[4]) - - - #elif (game_layer.game_state.turn > 35) and not len(state.utilities) > 1: - # game_layer.place_foundation((4,6), game_layer.game_state.available_utility_buildings[1].building_name) - #elif (state.utilities[1].build_progress < 100): - # game_layer.build((4,6)) - - elif (game_layer.game_state.turn % rounds_between_energy == 0): - adjustEnergy(the_first_residence) - elif (game_layer.game_state.turn % rounds_between_energy == 1): - adjustEnergy(the_second_residence) - elif (game_layer.game_state.turn % rounds_between_energy == 2): - adjustEnergy(the_third_residence) - elif (game_layer.game_state.turn % rounds_between_energy == 3): - adjustEnergy(the_fourth_residence) - elif (game_layer.game_state.turn % rounds_between_energy == 4): - adjustEnergy(the_fifth_residence) - elif (game_layer.game_state.turn % rounds_between_energy == 5): - adjustEnergy(the_sixth_residence) - else: - # messages and errors for console log - game_layer.wait() - for message in game_layer.game_state.messages: - print(message) - for error in game_layer.game_state.errors: - print("Error: " + error) def take_turn(): if not usePrebuiltStrategy: @@ -270,15 +182,11 @@ def adjustEnergy(currentBuilding): game_layer.wait() - - - def optimizeAvailableTiles(): #hitta #utilities antal bästa platser i mitten av smeten och sätt de först, sätt allt runt dem i ordning så närmast är längst fram i listan pass - def build(structure): print("Building " + structure) state = game_layer.game_state From 36521b7bf76352ec647db953d15d7170ccff6bf2 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Mon, 5 Oct 2020 16:43:52 +0200 Subject: [PATCH 20/61] flytta lite kod --- main.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 93e8bb2..cf40c9b 100644 --- a/main.py +++ b/main.py @@ -106,6 +106,17 @@ def take_turn(): for error in game_layer.game_state.errors: print("Error: " + error) +def develop_society(): + state = game_layer.game_state + if len(state.residences) < 5: + build("Apartments") + elif len(state.utilities) < 1: + build("WindTurbine") + elif state.funds > 25000 and len(game_layer.game_state.residences) < 11: + build("HighRise") + else: + game_layer.wait() + def something_needs_attention(): print("Checking for emergencies") global building_under_construction @@ -144,17 +155,6 @@ def something_needs_attention(): else: return False -def develop_society(): - state = game_layer.game_state - if len(state.residences) < 5: - build("Apartments") - elif len(state.utilities) < 1: - build("WindTurbine") - elif state.funds > 25000 and len(game_layer.game_state.residences) < 11: - build("HighRise") - else: - game_layer.wait() - def chartMap(): state = game_layer.game_state for x in range(len(state.map) - 1): From c2d40778f028414285cd316cc39465009c3eefaf Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Mon, 5 Oct 2020 18:28:59 +0200 Subject: [PATCH 21/61] =?UTF-8?q?wrapper=20s=C3=A5=20man=20kan=20k=C3=B6ra?= =?UTF-8?q?=20m=C3=A5nga=20games=20i=20rad=20(ej=20paralaliserad)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- launcher.py | 7 +++++++ main.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 launcher.py diff --git a/launcher.py b/launcher.py new file mode 100644 index 0000000..c922d71 --- /dev/null +++ b/launcher.py @@ -0,0 +1,7 @@ +import main +number_of_launches = 6 +result_list = [] +for i in range(number_of_launches): + result_list.append(main.main()) +for result in result_list: + print("Game " + result[0] + " had a score of: " + str(result[1])) \ No newline at end of file diff --git a/main.py b/main.py index cf40c9b..b9b967b 100644 --- a/main.py +++ b/main.py @@ -48,7 +48,7 @@ def main(): exit() print("Done with game: " + game_layer.game_state.game_id) print("Final score was: " + str(game_layer.get_score()["finalScore"])) - + return (game_layer.game_state.game_id, game_layer.get_score()["finalScore"]) def take_turn(): if not usePrebuiltStrategy: From de2b5181e00648061580859cf33a438ce10a07c8 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Mon, 5 Oct 2020 18:29:35 +0200 Subject: [PATCH 22/61] =?UTF-8?q?hitta=20"average"=20tile=20och=20sortera?= =?UTF-8?q?=20tiles=20utifr=C3=A5n=20avst=C3=A5nd=20till=20average?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index b9b967b..6215229 100644 --- a/main.py +++ b/main.py @@ -184,8 +184,27 @@ def adjustEnergy(currentBuilding): def optimizeAvailableTiles(): #hitta #utilities antal bästa platser i mitten av smeten och sätt de först, sätt allt runt dem i ordning så närmast är längst fram i listan - pass - + state = game_layer.game_state + global average_x, average_y, score_list + average_x = 0 + average_y = 0 + score_list = [] + for tile in availableTiles: #calc average coords + average_x += tile[0] + average_y += tile[1] + average_x /= len(availableTiles) + average_y /= len(availableTiles) + print("Assign scores") + for tile in availableTiles: + 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] + print("Sorting tile list") + score_list.sort(key=sort_key) + for i in range(len(score_list)): + availableTiles[i] = score_list[i][1] + print("average x,y: " + str(average_x) + ", " + str(average_y)) def build(structure): print("Building " + structure) From 3f678f69d782112712637051c8ccb5927e3a1420 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Mon, 5 Oct 2020 19:33:37 +0200 Subject: [PATCH 23/61] refactor variables, move code and use "state" --- main.py | 95 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/main.py b/main.py index 6215229..d1633d1 100644 --- a/main.py +++ b/main.py @@ -9,49 +9,51 @@ import traceback api_key = "74e3998d-ed3d-4d46-9ea8-6aab2efd8ae3" # The different map names can be found on considition.com/rules map_name = "training1" # TODO: You map choice here. If left empty, the map "training1" will be selected. - game_layer = GameLayer(api_key) -state = game_layer.game_state -usePrebuiltStrategy = False -timeUntilRunEnds = 50 -rounds_between_energy = 5 +#settings +use_prebuilt_strategy = False +time_until_run_ends = 70 utilities = 3 -EMA_temp = None -building_under_construction = None -availableTiles = [] - def main(): - #game_layer.force_end_game() + global EMA_temp, rounds_between_energy, building_under_construction, availableTiles, state + #global vars + rounds_between_energy = 5 + EMA_temp = None + building_under_construction = None + availableTiles = [] + game_layer.new_game(map_name) print("Starting game: " + game_layer.game_state.game_id) game_layer.start_game() - # exit game after timeout + # start timeout timer start_time = time.time() + state = game_layer.game_state chartMap() - global EMA_temp - while game_layer.game_state.turn < game_layer.game_state.max_turns: + while state.turn < state.max_turns: + state = game_layer.game_state try: if EMA_temp is None: - EMA_temp = game_layer.game_state.current_temp + EMA_temp = state.current_temp ema_k_value = (2/(rounds_between_energy+1)) - EMA_temp = game_layer.game_state.current_temp * ema_k_value + EMA_temp*(1-ema_k_value) + EMA_temp = state.current_temp * ema_k_value + EMA_temp*(1-ema_k_value) take_turn() except: print(traceback.format_exc()) game_layer.end_game() exit() time_diff = time.time() - start_time - if time_diff > timeUntilRunEnds: + if time_diff > time_until_run_ends: game_layer.end_game() exit() - print("Done with game: " + game_layer.game_state.game_id) + print("Done with game: " + state.game_id) print("Final score was: " + str(game_layer.get_score()["finalScore"])) - return (game_layer.game_state.game_id, game_layer.get_score()["finalScore"]) + return (state.game_id, game_layer.get_score()["finalScore"]) def take_turn(): - if not usePrebuiltStrategy: + global state + if not use_prebuilt_strategy: # TODO Implement your artificial intelligence here. # TODO Take one action per turn until the game ends. # TODO The following is a short example of how to use the StarterKit @@ -60,16 +62,14 @@ def take_turn(): else: develop_society() # messages and errors for console log - for message in game_layer.game_state.messages: + for message in state.messages: print(message) - for error in game_layer.game_state.errors: + for error in state.errors: print("Error: " + error) - # pre-made test strategy - # which came with - # starter kit - if usePrebuiltStrategy: + # pre-made test strategy which came with starter kit + if use_prebuilt_strategy: state = game_layer.game_state if len(state.residences) < 1: for i in range(len(state.map)): @@ -107,46 +107,52 @@ def take_turn(): print("Error: " + error) def develop_society(): - state = game_layer.game_state - if len(state.residences) < 5: + global state + + #check if queue is full + if state.housing_queue > 10 + len(state.utilities) * 0.15: + queue_is_full = True + else: + queue_is_full = False + + if len(state.residences) < 2: build("Apartments") elif len(state.utilities) < 1: build("WindTurbine") - elif state.funds > 25000 and len(game_layer.game_state.residences) < 11: + elif state.funds > 30000 and len(state.residences) < 4: build("HighRise") + elif queue_is_full: #build if queue full and can afford housing + + build("Apartments") + return True else: game_layer.wait() def something_needs_attention(): - print("Checking for emergencies") - global building_under_construction - global edit_temp - global maintain - state = game_layer.game_state + global building_under_construction, edit_temp, maintain, state #check if temp needs adjusting edit_temp = (False, 0) for i in range(len(state.residences)): if (state.turn % rounds_between_energy == i) and not state.residences[i].build_progress < 100: edit_temp = (True, i) - #check if need for maintainance maintain = (False, 0) for i in range(len(state.residences)): if state.residences[i].health < 41+rounds_between_energy*game_layer.get_residence_blueprint(state.residences[i].building_name).decay_rate: maintain = (True, i) - if maintain[0]: + if maintain[0]: #check maintainance game_layer.maintenance((state.residences[maintain[1]].X, state.residences[maintain[1]].Y)) return True - elif edit_temp[0]: #adjust temp of building + elif edit_temp[0]: #adjust temp of buildings adjustEnergy(state.residences[edit_temp[1]]) return True elif building_under_construction is not None: #finish construction - if (len(game_layer.game_state.residences) >= building_under_construction[2]) and (game_layer.game_state.residences[building_under_construction[2]].build_progress < 100): + if (len(state.residences)-1 >= building_under_construction[2]) and (state.residences[building_under_construction[2]].build_progress < 100): game_layer.build((building_under_construction[0], building_under_construction[1])) return True - elif (len(game_layer.game_state.utilities)-1 >= building_under_construction[2]) and (game_layer.game_state.utilities[building_under_construction[2]].build_progress < 100): + elif (len(state.utilities)-1 >= building_under_construction[2]) and (state.utilities[building_under_construction[2]].build_progress < 100): game_layer.build((building_under_construction[0], building_under_construction[1])) return True else: @@ -156,7 +162,7 @@ def something_needs_attention(): return False def chartMap(): - state = game_layer.game_state + global state for x in range(len(state.map) - 1): for y in range(len(state.map) - 1): if state.map[x][y] == 0: @@ -164,10 +170,9 @@ def chartMap(): optimizeAvailableTiles() def adjustEnergy(currentBuilding): - global rounds_between_energy - global EMA_temp + global rounds_between_energy, EMA_temp, state blueprint = game_layer.get_residence_blueprint(currentBuilding.building_name) - outDoorTemp = game_layer.game_state.current_temp * 2 - EMA_temp + outDoorTemp = state.current_temp * 2 - EMA_temp temp_acceleration = (2*(21 - currentBuilding.temperature)/(rounds_between_energy)) @@ -183,8 +188,6 @@ def adjustEnergy(currentBuilding): def optimizeAvailableTiles(): - #hitta #utilities antal bästa platser i mitten av smeten och sätt de först, sätt allt runt dem i ordning så närmast är längst fram i listan - state = game_layer.game_state global average_x, average_y, score_list average_x = 0 average_y = 0 @@ -208,9 +211,7 @@ def optimizeAvailableTiles(): def build(structure): print("Building " + structure) - state = game_layer.game_state - global building_under_construction - global rounds_between_energy + global building_under_construction, rounds_between_energy, state for i in range(len(availableTiles)): if isinstance(availableTiles[i], tuple): game_layer.place_foundation(availableTiles[i], structure) From a9ce9a96780b169e72b98c06fed512be213a139f Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Mon, 5 Oct 2020 19:54:12 +0200 Subject: [PATCH 24/61] update construction status faster --- main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index d1633d1..1985ce9 100644 --- a/main.py +++ b/main.py @@ -151,9 +151,13 @@ def something_needs_attention(): elif building_under_construction is not None: #finish construction if (len(state.residences)-1 >= building_under_construction[2]) and (state.residences[building_under_construction[2]].build_progress < 100): game_layer.build((building_under_construction[0], building_under_construction[1])) + if not state.residences[building_under_construction[2]].build_progress < 100: + building_under_construction = None return True elif (len(state.utilities)-1 >= building_under_construction[2]) and (state.utilities[building_under_construction[2]].build_progress < 100): game_layer.build((building_under_construction[0], building_under_construction[1])) + if not state.residences[building_under_construction[2]].build_progress < 100: + building_under_construction = None return True else: building_under_construction = None @@ -210,8 +214,8 @@ def optimizeAvailableTiles(): print("average x,y: " + str(average_x) + ", " + str(average_y)) def build(structure): - print("Building " + structure) global building_under_construction, rounds_between_energy, state + print("Building " + structure) for i in range(len(availableTiles)): if isinstance(availableTiles[i], tuple): game_layer.place_foundation(availableTiles[i], structure) From 876036fbe97f35c524ed002fbde6130aec00db5c Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Mon, 5 Oct 2020 20:54:41 +0200 Subject: [PATCH 25/61] time out building new residences --- main.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 1985ce9..44d4881 100644 --- a/main.py +++ b/main.py @@ -17,12 +17,13 @@ utilities = 3 def main(): - global EMA_temp, rounds_between_energy, building_under_construction, availableTiles, state + global EMA_temp, rounds_between_energy, building_under_construction, availableTiles, state, queue_timeout #global vars rounds_between_energy = 5 EMA_temp = None building_under_construction = None availableTiles = [] + queue_timeout = 0 game_layer.new_game(map_name) print("Starting game: " + game_layer.game_state.game_id) @@ -107,13 +108,22 @@ def take_turn(): print("Error: " + error) def develop_society(): - global state + global state, queue_timeout #check if queue is full - if state.housing_queue > 10 + len(state.utilities) * 0.15: + if (state.housing_queue > 10 + len(state.utilities) * 0.15) and queue_timeout >= 5: queue_is_full = True + queue_timeout = 0 else: queue_is_full = False + queue_timeout += 1 + + build_residence_score = 0 + upgrade_residence_score = 0 + build_utility_score = 0 + build_upgrade_score = 0 + + decision_engine = None if len(state.residences) < 2: build("Apartments") @@ -122,9 +132,11 @@ def develop_society(): elif state.funds > 30000 and len(state.residences) < 4: build("HighRise") elif queue_is_full: #build if queue full and can afford housing - - build("Apartments") - return True + build("ModernApartments") + elif build_upgrade_score: + #if state.available_upgrades[0].name not in the_only_residence.effects: + # game_layer.buy_upgrade((the_only_residence.X, the_only_residence.Y), state.available_upgrades[0].name) + pass else: game_layer.wait() From 3b55e5a597813faad5d08f1f939f999fc65899cf Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Mon, 5 Oct 2020 21:21:25 +0200 Subject: [PATCH 26/61] refactor available tiles --- main.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/main.py b/main.py index 44d4881..cfcae18 100644 --- a/main.py +++ b/main.py @@ -17,12 +17,12 @@ utilities = 3 def main(): - global EMA_temp, rounds_between_energy, building_under_construction, availableTiles, state, queue_timeout + global EMA_temp, rounds_between_energy, building_under_construction, available_tiles, state, queue_timeout #global vars rounds_between_energy = 5 EMA_temp = None building_under_construction = None - availableTiles = [] + available_tiles = [] queue_timeout = 0 game_layer.new_game(map_name) @@ -108,7 +108,7 @@ def take_turn(): print("Error: " + error) def develop_society(): - global state, queue_timeout + global state, queue_timeout, available_tiles #check if queue is full if (state.housing_queue > 10 + len(state.utilities) * 0.15) and queue_timeout >= 5: @@ -182,8 +182,8 @@ def chartMap(): for x in range(len(state.map) - 1): for y in range(len(state.map) - 1): if state.map[x][y] == 0: - availableTiles.append((x, y)) - optimizeAvailableTiles() + available_tiles.append((x, y)) + optimize_available_tiles() def adjustEnergy(currentBuilding): global rounds_between_energy, EMA_temp, state @@ -203,18 +203,18 @@ def adjustEnergy(currentBuilding): game_layer.wait() -def optimizeAvailableTiles(): +def optimize_available_tiles(): global average_x, average_y, score_list average_x = 0 average_y = 0 score_list = [] - for tile in availableTiles: #calc average coords + for tile in available_tiles: #calc average coords average_x += tile[0] average_y += tile[1] - average_x /= len(availableTiles) - average_y /= len(availableTiles) + average_x /= len(available_tiles) + average_y /= len(available_tiles) print("Assign scores") - for tile in availableTiles: + 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): @@ -222,22 +222,22 @@ def optimizeAvailableTiles(): print("Sorting tile list") score_list.sort(key=sort_key) for i in range(len(score_list)): - availableTiles[i] = score_list[i][1] + 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) - for i in range(len(availableTiles)): - if isinstance(availableTiles[i], tuple): - game_layer.place_foundation(availableTiles[i], structure) + for i in range(len(available_tiles)): + if isinstance(available_tiles[i], tuple): + game_layer.place_foundation(available_tiles[i], structure) for building in state.available_residence_buildings: if structure in building.building_name: for j in range(len(state.residences)): building = state.residences[j] coords_to_check = (building.X, building.Y) - if coords_to_check == availableTiles[i]: - availableTiles[i] = building + if coords_to_check == available_tiles[i]: + available_tiles[i] = building building_under_construction = (building.X, building.Y, j) rounds_between_energy = len(state.residences)+2 return True @@ -246,8 +246,8 @@ def build(structure): for j in range(len(state.utilities)): building = state.utilities[j] coords_to_check = (building.X, building.Y) - if coords_to_check == availableTiles[i]: - availableTiles[i] = building + if coords_to_check == available_tiles[i]: + available_tiles[i] = building building_under_construction = (building.X, building.Y, j) rounds_between_energy = len(state.residences)+2 return True From a830dd5d8137c9c408394d7d289cc441cffee998 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Mon, 5 Oct 2020 21:35:14 +0200 Subject: [PATCH 27/61] refactor and clear up code (whitespaces etc) --- main.py | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/main.py b/main.py index cfcae18..8efcbc8 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,7 @@ api_key = "74e3998d-ed3d-4d46-9ea8-6aab2efd8ae3" # The different map names can be found on considition.com/rules map_name = "training1" # TODO: You map choice here. If left empty, the map "training1" will be selected. game_layer = GameLayer(api_key) -#settings +# settings use_prebuilt_strategy = False time_until_run_ends = 70 utilities = 3 @@ -18,7 +18,7 @@ utilities = 3 def main(): global EMA_temp, rounds_between_energy, building_under_construction, available_tiles, state, queue_timeout - #global vars + # global vars rounds_between_energy = 5 EMA_temp = None building_under_construction = None @@ -31,7 +31,7 @@ def main(): # start timeout timer start_time = time.time() state = game_layer.game_state - chartMap() + chart_map() while state.turn < state.max_turns: state = game_layer.game_state try: @@ -40,7 +40,7 @@ def main(): ema_k_value = (2/(rounds_between_energy+1)) EMA_temp = state.current_temp * ema_k_value + EMA_temp*(1-ema_k_value) take_turn() - except: + except Exception: print(traceback.format_exc()) game_layer.end_game() exit() @@ -52,6 +52,7 @@ def main(): print("Final score was: " + str(game_layer.get_score()["finalScore"])) return (state.game_id, game_layer.get_score()["finalScore"]) + def take_turn(): global state if not use_prebuilt_strategy: @@ -68,7 +69,6 @@ def take_turn(): for error in state.errors: print("Error: " + error) - # pre-made test strategy which came with starter kit if use_prebuilt_strategy: state = game_layer.game_state @@ -107,10 +107,11 @@ def take_turn(): for error in game_layer.game_state.errors: print("Error: " + error) + def develop_society(): global state, queue_timeout, available_tiles - #check if queue is full + # check if queue is full if (state.housing_queue > 10 + len(state.utilities) * 0.15) and queue_timeout >= 5: queue_is_full = True queue_timeout = 0 @@ -131,33 +132,34 @@ def develop_society(): build("WindTurbine") elif state.funds > 30000 and len(state.residences) < 4: build("HighRise") - elif queue_is_full: #build if queue full and can afford housing + elif queue_is_full: # build if queue full and can afford housing build("ModernApartments") elif build_upgrade_score: - #if state.available_upgrades[0].name not in the_only_residence.effects: + # if state.available_upgrades[0].name not in the_only_residence.effects: # game_layer.buy_upgrade((the_only_residence.X, the_only_residence.Y), state.available_upgrades[0].name) pass else: game_layer.wait() + def something_needs_attention(): global building_under_construction, edit_temp, maintain, state - #check if temp needs adjusting + # check if temp needs adjusting edit_temp = (False, 0) for i in range(len(state.residences)): if (state.turn % rounds_between_energy == i) and not state.residences[i].build_progress < 100: edit_temp = (True, i) - #check if need for maintainance + # check if need for maintenance maintain = (False, 0) for i in range(len(state.residences)): if state.residences[i].health < 41+rounds_between_energy*game_layer.get_residence_blueprint(state.residences[i].building_name).decay_rate: maintain = (True, i) - if maintain[0]: #check maintainance + if maintain[0]: # check maintenance game_layer.maintenance((state.residences[maintain[1]].X, state.residences[maintain[1]].Y)) return True - elif edit_temp[0]: #adjust temp of buildings + elif edit_temp[0]: # adjust temp of buildings adjustEnergy(state.residences[edit_temp[1]]) return True elif building_under_construction is not None: #finish construction @@ -177,7 +179,7 @@ def something_needs_attention(): else: return False -def chartMap(): +def chart_map(): global state for x in range(len(state.map) - 1): for y in range(len(state.map) - 1): @@ -185,19 +187,20 @@ def chartMap(): available_tiles.append((x, y)) optimize_available_tiles() -def adjustEnergy(currentBuilding): + +def adjust_energy(current_building): global rounds_between_energy, EMA_temp, state - blueprint = game_layer.get_residence_blueprint(currentBuilding.building_name) + blueprint = game_layer.get_residence_blueprint(current_building.building_name) outDoorTemp = state.current_temp * 2 - EMA_temp - temp_acceleration = (2*(21 - currentBuilding.temperature)/(rounds_between_energy)) + temp_acceleration = (2*(21 - current_building.temperature)/(rounds_between_energy)) - effectiveEnergyIn = ((temp_acceleration - 0.04 * currentBuilding.current_pop + (currentBuilding.temperature - outDoorTemp) * blueprint.emissivity) / 0.75) + blueprint.base_energy_need + effectiveEnergyIn = ((temp_acceleration - 0.04 * current_building.current_pop + (current_building.temperature - outDoorTemp) * blueprint.emissivity) / 0.75) + blueprint.base_energy_need if effectiveEnergyIn > blueprint.base_energy_need: - game_layer.adjust_energy_level((currentBuilding.X, currentBuilding.Y), effectiveEnergyIn) + game_layer.adjust_energy_level((current_building.X, current_building.Y), effectiveEnergyIn) elif effectiveEnergyIn < blueprint.base_energy_need: - game_layer.adjust_energy_level((currentBuilding.X, currentBuilding.Y), blueprint.base_energy_need + 0.01) + game_layer.adjust_energy_level((current_building.X, current_building.Y), blueprint.base_energy_need + 0.01) else: print("you did it!") game_layer.wait() @@ -208,7 +211,7 @@ def optimize_available_tiles(): average_x = 0 average_y = 0 score_list = [] - for tile in available_tiles: #calc average coords + for tile in available_tiles: # calc average coordinates average_x += tile[0] average_y += tile[1] average_x /= len(available_tiles) @@ -217,6 +220,7 @@ def optimize_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] print("Sorting tile list") @@ -225,6 +229,7 @@ def optimize_available_tiles(): 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) From 638ebcfd721846ed78aebd7283417368bf5201f6 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Mon, 5 Oct 2020 21:35:34 +0200 Subject: [PATCH 28/61] change energy return (wasted wait()) --- main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 8efcbc8..c8af3d4 100644 --- a/main.py +++ b/main.py @@ -160,9 +160,8 @@ def something_needs_attention(): game_layer.maintenance((state.residences[maintain[1]].X, state.residences[maintain[1]].Y)) return True elif edit_temp[0]: # adjust temp of buildings - adjustEnergy(state.residences[edit_temp[1]]) - return True - elif building_under_construction is not None: #finish construction + return adjust_energy(state.residences[edit_temp[1]]) + elif building_under_construction is not None: # finish construction if (len(state.residences)-1 >= building_under_construction[2]) and (state.residences[building_under_construction[2]].build_progress < 100): game_layer.build((building_under_construction[0], building_under_construction[1])) if not state.residences[building_under_construction[2]].build_progress < 100: @@ -199,11 +198,12 @@ def adjust_energy(current_building): if effectiveEnergyIn > blueprint.base_energy_need: game_layer.adjust_energy_level((current_building.X, current_building.Y), effectiveEnergyIn) + return True elif effectiveEnergyIn < blueprint.base_energy_need: game_layer.adjust_energy_level((current_building.X, current_building.Y), blueprint.base_energy_need + 0.01) + return True else: - print("you did it!") - game_layer.wait() + return False def optimize_available_tiles(): From 9713be3eaf8aa6b0fe52af1b203de83474ec59cb Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Mon, 5 Oct 2020 22:58:09 +0200 Subject: [PATCH 29/61] =?UTF-8?q?kommentera=20trash=20metoden,=20optimizat?= =?UTF-8?q?ions,=20jobb=20p=C3=A5=20decision=20engine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 140 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 69 insertions(+), 71 deletions(-) diff --git a/main.py b/main.py index c8af3d4..40602b1 100644 --- a/main.py +++ b/main.py @@ -11,7 +11,6 @@ api_key = "74e3998d-ed3d-4d46-9ea8-6aab2efd8ae3" map_name = "training1" # TODO: You map choice here. If left empty, the map "training1" will be selected. game_layer = GameLayer(api_key) # settings -use_prebuilt_strategy = False time_until_run_ends = 70 utilities = 3 @@ -23,7 +22,7 @@ def main(): EMA_temp = None building_under_construction = None available_tiles = [] - queue_timeout = 0 + queue_timeout = 1 game_layer.new_game(map_name) print("Starting game: " + game_layer.game_state.game_id) @@ -55,106 +54,105 @@ def main(): def take_turn(): global state - if not use_prebuilt_strategy: - # TODO Implement your artificial intelligence here. - # TODO Take one action per turn until the game ends. - # TODO The following is a short example of how to use the StarterKit - if something_needs_attention(): - pass - else: - develop_society() - # messages and errors for console log - for message in state.messages: - print(message) - for error in state.errors: - print("Error: " + error) + # TODO Implement your artificial intelligence here. + # TODO Take one action per turn until the game ends. + # TODO The following is a short example of how to use the StarterKit + if something_needs_attention(): + pass + else: + develop_society() + # messages and errors for console log + for message in state.messages: + print(message) + for error in state.errors: + print("Error: " + error) # pre-made test strategy which came with starter kit - if use_prebuilt_strategy: - state = game_layer.game_state - if len(state.residences) < 1: - for i in range(len(state.map)): - for j in range(len(state.map)): - if state.map[i][j] == 0: - x = i - y = j - break - game_layer.place_foundation((x, y), game_layer.game_state.available_residence_buildings[0].building_name) + ''' + state = game_layer.game_state + if len(state.residences) < 1: + for i in range(len(state.map)): + for j in range(len(state.map)): + if state.map[i][j] == 0: + x = i + y = j + break + game_layer.place_foundation((x, y), game_layer.game_state.available_residence_buildings[0].building_name) + else: + the_only_residence = state.residences[0] + if the_only_residence.build_progress < 100: + game_layer.build((the_only_residence.X, the_only_residence.Y)) + elif the_only_residence.health < 50: + game_layer.maintenance((the_only_residence.X, the_only_residence.Y)) + elif the_only_residence.temperature < 18: + blueprint = game_layer.get_residence_blueprint(the_only_residence.building_name) + energy = blueprint.base_energy_need + 0.5 \ + + (the_only_residence.temperature - state.current_temp) * blueprint.emissivity / 1 \ + - the_only_residence.current_pop * 0.04 + game_layer.adjust_energy_level((the_only_residence.X, the_only_residence.Y), energy) + elif the_only_residence.temperature > 24: + blueprint = game_layer.get_residence_blueprint(the_only_residence.building_name) + energy = blueprint.base_energy_need - 0.5 \ + + (the_only_residence.temperature - state.current_temp) * blueprint.emissivity / 1 \ + - the_only_residence.current_pop * 0.04 + game_layer.adjust_energy_level((the_only_residence.X, the_only_residence.Y), energy) + elif state.available_upgrades[0].name not in the_only_residence.effects: + game_layer.buy_upgrade((the_only_residence.X, the_only_residence.Y), state.available_upgrades[0].name) else: - the_only_residence = state.residences[0] - if the_only_residence.build_progress < 100: - game_layer.build((the_only_residence.X, the_only_residence.Y)) - elif the_only_residence.health < 50: - game_layer.maintenance((the_only_residence.X, the_only_residence.Y)) - elif the_only_residence.temperature < 18: - blueprint = game_layer.get_residence_blueprint(the_only_residence.building_name) - energy = blueprint.base_energy_need + 0.5 \ - + (the_only_residence.temperature - state.current_temp) * blueprint.emissivity / 1 \ - - the_only_residence.current_pop * 0.04 - game_layer.adjust_energy_level((the_only_residence.X, the_only_residence.Y), energy) - elif the_only_residence.temperature > 24: - blueprint = game_layer.get_residence_blueprint(the_only_residence.building_name) - energy = blueprint.base_energy_need - 0.5 \ - + (the_only_residence.temperature - state.current_temp) * blueprint.emissivity / 1 \ - - the_only_residence.current_pop * 0.04 - game_layer.adjust_energy_level((the_only_residence.X, the_only_residence.Y), energy) - elif state.available_upgrades[0].name not in the_only_residence.effects: - game_layer.buy_upgrade((the_only_residence.X, the_only_residence.Y), state.available_upgrades[0].name) - else: - game_layer.wait() - for message in game_layer.game_state.messages: - print(message) - for error in game_layer.game_state.errors: - print("Error: " + error) + game_layer.wait() + for message in game_layer.game_state.messages: + print(message) + for error in game_layer.game_state.errors: + print("Error: " + error) + ''' def develop_society(): global state, queue_timeout, available_tiles + if queue_timeout > 1: + queue_timeout -= 1 - # check if queue is full - if (state.housing_queue > 10 + len(state.utilities) * 0.15) and queue_timeout >= 5: - queue_is_full = True - queue_timeout = 0 - else: - queue_is_full = False - queue_timeout += 1 - build_residence_score = 0 + # priority scores, 1 = very urgent, 0 = not urgent at all + build_residence_score = state.housing_queue / (15 * queue_timeout) upgrade_residence_score = 0 build_utility_score = 0 - build_upgrade_score = 0 + build_upgrade_score = 1 - state.turn/700 - decision_engine = None + actions = { + 'build_residence': build_residence_score, + 'upgrade_residence': upgrade_residence_score, + 'build_utility': build_utility_score, + 'build_upgrade': build_upgrade_score + } + decision = str(max(actions, key=actions.get)) if len(state.residences) < 2: build("Apartments") - elif len(state.utilities) < 1: + elif decision == "build_utility": build("WindTurbine") - elif state.funds > 30000 and len(state.residences) < 4: - build("HighRise") - elif queue_is_full: # build if queue full and can afford housing + elif decision == "build_residence": # build if queue full and can afford housing build("ModernApartments") - elif build_upgrade_score: + elif decision == "build_upgrade": # if state.available_upgrades[0].name not in the_only_residence.effects: # game_layer.buy_upgrade((the_only_residence.X, the_only_residence.Y), state.available_upgrades[0].name) - pass + game_layer.wait() else: game_layer.wait() def something_needs_attention(): - global building_under_construction, edit_temp, maintain, state + global building_under_construction, edit_temp, maintain, state, rounds_between_energy # check if temp needs adjusting edit_temp = (False, 0) - for i in range(len(state.residences)): - if (state.turn % rounds_between_energy == i) and not state.residences[i].build_progress < 100: - edit_temp = (True, i) # check if need for maintenance maintain = (False, 0) for i in range(len(state.residences)): - if state.residences[i].health < 41+rounds_between_energy*game_layer.get_residence_blueprint(state.residences[i].building_name).decay_rate: + if state.residences[i].health < 35+rounds_between_energy*game_layer.get_residence_blueprint(state.residences[i].building_name).decay_rate: maintain = (True, i) + if (state.turn % rounds_between_energy == i) and not state.residences[i].build_progress < 100: + edit_temp = (True, i) if maintain[0]: # check maintenance game_layer.maintenance((state.residences[maintain[1]].X, state.residences[maintain[1]].Y)) From db7c1c05be73f905adfbbfd8e530ab7c2fb3dc5c Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Tue, 6 Oct 2020 00:18:36 +0200 Subject: [PATCH 30/61] brain mechanics --- main.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/main.py b/main.py index 40602b1..c4c3d2c 100644 --- a/main.py +++ b/main.py @@ -59,8 +59,11 @@ def take_turn(): # TODO The following is a short example of how to use the StarterKit if something_needs_attention(): pass + elif develop_society(): + pass else: - develop_society() + game_layer.wait() + # messages and errors for console log for message in state.messages: print(message) @@ -108,16 +111,17 @@ def take_turn(): def develop_society(): - global state, queue_timeout, available_tiles + global state, queue_timeout, available_tiles, utilities if queue_timeout > 1: queue_timeout -= 1 # priority scores, 1 = very urgent, 0 = not urgent at all - build_residence_score = state.housing_queue / (15 * queue_timeout) + # queue modifier * funds modifier * existing houses modifier + build_residence_score = (state.housing_queue / (15 * queue_timeout)) * (1 - 7500/state.funds) * (1 - len(state.residences) / (len(available_tiles)-utilities)) upgrade_residence_score = 0 - build_utility_score = 0 - build_upgrade_score = 1 - state.turn/700 + build_utility_score = (len(state.residences) / (len(available_tiles)-utilities)) * (1 - len(state.utilities) / utilities) + build_upgrade_score = (1 - state.turn/700) * (2 - 15000/state.funds) actions = { 'build_residence': build_residence_score, @@ -127,18 +131,19 @@ def develop_society(): } decision = str(max(actions, key=actions.get)) - if len(state.residences) < 2: - build("Apartments") + if len(state.residences) < 1: + return build("Apartments") elif decision == "build_utility": - build("WindTurbine") + return build("WindTurbine") elif decision == "build_residence": # build if queue full and can afford housing - build("ModernApartments") + return build("ModernApartments") elif decision == "build_upgrade": - # if state.available_upgrades[0].name not in the_only_residence.effects: - # game_layer.buy_upgrade((the_only_residence.X, the_only_residence.Y), state.available_upgrades[0].name) - game_layer.wait() - else: - game_layer.wait() + for i in range(5): + for residence in state.residences: + if state.available_upgrades[i].name not in residence.effects: + game_layer.buy_upgrade((residence.X, residence.Y), state.available_upgrades[i].name) + return True + def something_needs_attention(): @@ -214,14 +219,12 @@ def optimize_available_tiles(): average_y += tile[1] average_x /= len(available_tiles) average_y /= len(available_tiles) - print("Assign scores") 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] - print("Sorting tile list") score_list.sort(key=sort_key) for i in range(len(score_list)): available_tiles[i] = score_list[i][1] @@ -230,7 +233,7 @@ def optimize_available_tiles(): def build(structure): global building_under_construction, rounds_between_energy, state - print("Building " + structure) + # print("Building " + structure) for i in range(len(available_tiles)): if isinstance(available_tiles[i], tuple): game_layer.place_foundation(available_tiles[i], structure) From 8309d2938c1ba2d8ad4d4b22e930588ab18e2858 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Tue, 6 Oct 2020 01:49:09 +0200 Subject: [PATCH 31/61] =?UTF-8?q?adjust=20energy=20ta=20h=C3=A4nsyn=20till?= =?UTF-8?q?=20upgrades?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index c4c3d2c..2e50fa4 100644 --- a/main.py +++ b/main.py @@ -193,17 +193,24 @@ def chart_map(): def adjust_energy(current_building): global rounds_between_energy, EMA_temp, state blueprint = game_layer.get_residence_blueprint(current_building.building_name) - outDoorTemp = state.current_temp * 2 - EMA_temp + base_energy = blueprint.base_energy_need + if "Charger" in current_building.effects: + base_energy += 1.8 + emissivity = blueprint.emissivity + if "Insulation" in current_building.effects: + emissivity *= 0.6 + + outDoorTemp = state.current_temp * 2 - EMA_temp temp_acceleration = (2*(21 - current_building.temperature)/(rounds_between_energy)) - effectiveEnergyIn = ((temp_acceleration - 0.04 * current_building.current_pop + (current_building.temperature - outDoorTemp) * blueprint.emissivity) / 0.75) + blueprint.base_energy_need + effectiveEnergyIn = ((temp_acceleration - 0.04 * current_building.current_pop + (current_building.temperature - outDoorTemp) * emissivity) / 0.75) + base_energy - if effectiveEnergyIn > blueprint.base_energy_need: + if effectiveEnergyIn > base_energy: game_layer.adjust_energy_level((current_building.X, current_building.Y), effectiveEnergyIn) return True - elif effectiveEnergyIn < blueprint.base_energy_need: - game_layer.adjust_energy_level((current_building.X, current_building.Y), blueprint.base_energy_need + 0.01) + elif effectiveEnergyIn < base_energy: + game_layer.adjust_energy_level((current_building.X, current_building.Y), base_energy + 0.01) return True else: return False From 2cda0a08b7f19c4b0a056ab8709b38f60b920e13 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Tue, 6 Oct 2020 01:49:23 +0200 Subject: [PATCH 32/61] decision engine rework --- main.py | 61 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/main.py b/main.py index 2e50fa4..466938a 100644 --- a/main.py +++ b/main.py @@ -118,31 +118,48 @@ def develop_society(): # priority scores, 1 = very urgent, 0 = not urgent at all # queue modifier * funds modifier * existing houses modifier - build_residence_score = (state.housing_queue / (15 * queue_timeout)) * (1 - 7500/state.funds) * (1 - len(state.residences) / (len(available_tiles)-utilities)) + build_residence_score = (state.housing_queue / (15 * queue_timeout)) * (1 - (7500 / state.funds)) * (1 - (len(state.residences) / (len(available_tiles)-utilities))) upgrade_residence_score = 0 - build_utility_score = (len(state.residences) / (len(available_tiles)-utilities)) * (1 - len(state.utilities) / utilities) - build_upgrade_score = (1 - state.turn/700) * (2 - 15000/state.funds) - - actions = { - 'build_residence': build_residence_score, - 'upgrade_residence': upgrade_residence_score, - 'build_utility': build_utility_score, - 'build_upgrade': build_upgrade_score - } - decision = str(max(actions, key=actions.get)) + # existing houses modifier * funds modifier * existing utilities modifier + build_utility_score = (len(state.residences) / (len(available_tiles)-utilities)) * (1 - (16000 / state.funds)) * (1 - (len(state.utilities) / utilities)) + # turn modifier * funds modifier + build_upgrade_score = (1 - (state.turn / 700)) * (2 - (15000 / state.funds)) if len(state.residences) < 1: - return build("Apartments") - elif decision == "build_utility": - return build("WindTurbine") - elif decision == "build_residence": # build if queue full and can afford housing - return build("ModernApartments") - elif decision == "build_upgrade": - for i in range(5): - for residence in state.residences: - if state.available_upgrades[i].name not in residence.effects: - game_layer.buy_upgrade((residence.X, residence.Y), state.available_upgrades[i].name) - return True + build_residence_score = 100 + + decision = [ + ('build_residence', build_residence_score), + ('upgrade_residence', upgrade_residence_score), + ('build_utility', build_utility_score), + ('build_upgrade', build_upgrade_score) + ] + def sort_key(e): + return e[1] + decision.sort(reverse=True, key=sort_key) + print(decision) + + 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) + + if decision[0][0] == "build_utility": # build utilities + return build("WindTurbine") + + if decision[0][0] == "upgrade_residence": # build utilities + pass + + if decision[0][0] == "build_upgrade": # build upgrades + for i in range(6): + for residence in state.residences: + if state.available_upgrades[i].name not in residence.effects: + game_layer.buy_upgrade((residence.X, residence.Y), state.available_upgrades[i].name) + return True + del decision[0] + return False From 9ae3b54c417ae06d5cc47cd93530503f8a01252b Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Tue, 6 Oct 2020 02:02:28 +0200 Subject: [PATCH 33/61] 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) From 1bb5ba898d18118afd059ddfe6022ceed9e51d8a Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Tue, 6 Oct 2020 05:06:04 +0200 Subject: [PATCH 34/61] decision logic, income, best upgrade/residence functions --- main.py | 128 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 112 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 73a418c..458d761 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,7 @@ game_layer = GameLayer(api_key) # settings time_until_run_ends = 70 utilities = 3 +money_reserve_multiplier = 1.5 def main(): @@ -118,12 +119,12 @@ def develop_society(): # priority scores, 1 = very urgent, 0 = not urgent at all # queue modifier * funds modifier * existing houses modifier - build_residence_score = (state.housing_queue / (15 * queue_timeout)) * (1 - (7500 / state.funds)) * (1 - (len(state.residences) / (len(available_tiles)-utilities))) + build_residence_score = (state.housing_queue / (15 * queue_timeout)) * (1 - (7500 / (1 + state.funds))) * (1 - (len(state.residences) / (1 + len(available_tiles) - utilities))) upgrade_residence_score = 0 # existing houses modifier * funds modifier * existing utilities modifier - build_utility_score = (len(state.residences) / (len(available_tiles)-utilities)) * (1 - (16000 / state.funds)) * (1 - (len(state.utilities) / utilities)) + build_utility_score = (len(state.residences) / (1 + len(available_tiles)-utilities)) * (1 - (16000 / (1 + state.funds))) * (1 - (len(state.utilities) / utilities)) # turn modifier * funds modifier - build_upgrade_score = (1 - (state.turn / 700)) * (2 - (15000 / state.funds)) + build_upgrade_score = (1 - (state.turn / 700)) * (2 - (15000 / (1 + state.funds))) if len(state.residences) < 1: build_residence_score = 100 @@ -137,28 +138,35 @@ def develop_society(): def sort_key(e): return e[1] decision.sort(reverse=True, key=sort_key) - print(decision) for i in range(4): if decision[0][0] == "build_residence": # build housing queue_timeout = 5 - 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 len(state.residences) < len(state.available_residence_buildings): + # return build(state.available_residence_buildings[len(state.residences)].building_name) + #else: + cbr = calculate_best_residence() + if cbr: + return build(cbr[1]) if decision[0][0] == "build_utility": # build utilities - return build("WindTurbine") - + #return build("WindTurbine") + pass if decision[0][0] == "upgrade_residence": # build utilities pass - if decision[0][0] == "build_upgrade": # build upgrades - for i in range(6): - for residence in state.residences: - if state.available_upgrades[i].name not in residence.effects: - game_layer.buy_upgrade((residence.X, residence.Y), state.available_upgrades[i].name) - return True + for residence in state.residences: + if state.available_upgrades[0].name not in residence.effects and (money_reserve_multiplier*3500 < state.funds) and ((total_income() - 6) > 50): + game_layer.buy_upgrade((residence.X, residence.Y), state.available_upgrades[0].name) + return True + if state.available_upgrades[5].name not in residence.effects and (money_reserve_multiplier*1250 < state.funds): + game_layer.buy_upgrade((residence.X, residence.Y), state.available_upgrades[5].name) + return True + gbp = get_best_upgrade() + if gbp: + game_layer.buy_upgrade((gbp[2].X, gbp[2].Y), gbp[1]) + return True del decision[0] + return False @@ -199,6 +207,94 @@ def something_needs_attention(): return False +def total_income(): + global state + income = 0 + for residence in state.residences: + income += game_layer.get_residence_blueprint(residence.building_name).income_per_pop * residence.current_pop + return income + + +def get_best_upgrade(): + global state + + best_upgrade = [] + for residence in state.residences: + cbu = calculate_best_upgrade(residence) + if cbu is not False: + score = cbu[0] + upgrade = cbu[1] + best_upgrade.append((score, upgrade, residence)) + + def sort_key(e): + return e[0] + best_upgrade.sort(reverse=True, key=sort_key) + if not best_upgrade: + return False + return best_upgrade[0] + + +def calculate_best_upgrade(current_building): + global state + + rounds_left = 700 - state.turn + current_pop = current_building.current_pop + blueprint = game_layer.get_blueprint(current_building.building_name) + base_energy_need = blueprint.base_energy_need + best_upgrade = [] + for upgrade in state.available_upgrades: + effect = game_layer.get_effect(upgrade.effect) + if (upgrade.name not in current_building.effects) and ((total_income() + effect.building_income_increase) > 50) and (money_reserve_multiplier*upgrade.cost < state.funds): + average_outdoor_temp = (state.max_temp - state.min_temp)/2 + + average_heating_energy = (((21 - average_outdoor_temp) * blueprint.emissivity * effect.emissivity_multiplier) / 0.75) + old_average_heating_energy = (((21 - average_outdoor_temp) * blueprint.emissivity) / 0.75) + + lifetime_energy = (base_energy_need + effect.base_energy_mwh_increase + average_heating_energy - effect.mwh_production) * rounds_left + old_lifetime_energy = (base_energy_need + old_average_heating_energy) * rounds_left + + + upgrade_co2 = (effect.co2_per_pop_increase * 0.03) * current_pop * rounds_left + (0.1 * lifetime_energy / 1000) + old_co2 = 0.03 * current_pop * rounds_left + (0.1 * old_lifetime_energy / 1000) + co2 = upgrade_co2 - old_co2 + max_happiness = effect.max_happiness_increase * rounds_left + + score = max_happiness/10 - co2 + best_upgrade.append((score, upgrade.name)) + + def sort_key(e): + return e[0] + best_upgrade.sort(reverse=True, key=sort_key) + if not best_upgrade: + return False + return best_upgrade[0] + + +def calculate_best_residence(): + global state + + rounds_left = 700 - state.turn + best_residence = [] + for residence_blueprint in state.available_residence_buildings: + if state.turn >= residence_blueprint.release_tick and (money_reserve_multiplier*residence_blueprint.cost < state.funds): + average_outdoor_temp = (state.max_temp - state.min_temp)/2 + average_heating_energy = ((0 - 0.04 * residence_blueprint.max_pop + (21 - average_outdoor_temp) * residence_blueprint.emissivity) / 0.75) + lifetime_energy = (residence_blueprint.base_energy_need + average_heating_energy) * rounds_left + + co2 = 0.03 * residence_blueprint.max_pop * rounds_left + residence_blueprint.co2_cost + (0.1 * lifetime_energy / 1000) + max_happiness = residence_blueprint.max_happiness * rounds_left + + score = residence_blueprint.max_pop*15 + max_happiness/10 - co2 + best_residence.append((score, residence_blueprint.building_name)) + + def sort_key(e): + return e[0] + best_residence.sort(reverse=True, key=sort_key) + if not best_residence: + return False + return best_residence[0] + + def chart_map(): global state for x in range(len(state.map) - 1): From 5180e293d7fbcab7c81f34792197745e3f5fa75e Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Tue, 6 Oct 2020 12:16:19 +0200 Subject: [PATCH 35/61] launcher exiter --- launcher.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/launcher.py b/launcher.py index c922d71..23d6915 100644 --- a/launcher.py +++ b/launcher.py @@ -4,4 +4,5 @@ result_list = [] for i in range(number_of_launches): result_list.append(main.main()) for result in result_list: - print("Game " + result[0] + " had a score of: " + str(result[1])) \ No newline at end of file + print("Game " + result[0] + " had a score of: " + str(result[1])) + input("Press Enter to exit") \ No newline at end of file From 1d238ecc2fd70cf7ce2278cd9ccd9ea99a8f6bff Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Tue, 6 Oct 2020 22:53:27 +0200 Subject: [PATCH 36/61] clean some code --- main.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 458d761..cabd59b 100644 --- a/main.py +++ b/main.py @@ -235,7 +235,7 @@ def get_best_upgrade(): def calculate_best_upgrade(current_building): - global state + global state, money_reserve_multiplier rounds_left = 700 - state.turn current_pop = current_building.current_pop @@ -271,7 +271,7 @@ def calculate_best_upgrade(current_building): def calculate_best_residence(): - global state + global state, money_reserve_multiplier rounds_left = 700 - state.turn best_residence = [] @@ -323,7 +323,6 @@ def optimize_available_tiles(): 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): @@ -354,7 +353,6 @@ def adjust_energy(current_building): def build(structure): global building_under_construction, rounds_between_energy, state - # print("Building " + structure) for i in range(len(available_tiles)): if isinstance(available_tiles[i], tuple): game_layer.place_foundation(available_tiles[i], structure) From 9f759e8d2106395bebbcca02e286c38034565b14 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Wed, 7 Oct 2020 00:24:15 +0200 Subject: [PATCH 37/61] purge premade code --- main.py | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/main.py b/main.py index cabd59b..4abf01e 100644 --- a/main.py +++ b/main.py @@ -71,45 +71,6 @@ def take_turn(): for error in state.errors: print("Error: " + error) - # pre-made test strategy which came with starter kit - ''' - state = game_layer.game_state - if len(state.residences) < 1: - for i in range(len(state.map)): - for j in range(len(state.map)): - if state.map[i][j] == 0: - x = i - y = j - break - game_layer.place_foundation((x, y), game_layer.game_state.available_residence_buildings[0].building_name) - else: - the_only_residence = state.residences[0] - if the_only_residence.build_progress < 100: - game_layer.build((the_only_residence.X, the_only_residence.Y)) - elif the_only_residence.health < 50: - game_layer.maintenance((the_only_residence.X, the_only_residence.Y)) - elif the_only_residence.temperature < 18: - blueprint = game_layer.get_residence_blueprint(the_only_residence.building_name) - energy = blueprint.base_energy_need + 0.5 \ - + (the_only_residence.temperature - state.current_temp) * blueprint.emissivity / 1 \ - - the_only_residence.current_pop * 0.04 - game_layer.adjust_energy_level((the_only_residence.X, the_only_residence.Y), energy) - elif the_only_residence.temperature > 24: - blueprint = game_layer.get_residence_blueprint(the_only_residence.building_name) - energy = blueprint.base_energy_need - 0.5 \ - + (the_only_residence.temperature - state.current_temp) * blueprint.emissivity / 1 \ - - the_only_residence.current_pop * 0.04 - game_layer.adjust_energy_level((the_only_residence.X, the_only_residence.Y), energy) - elif state.available_upgrades[0].name not in the_only_residence.effects: - game_layer.buy_upgrade((the_only_residence.X, the_only_residence.Y), state.available_upgrades[0].name) - else: - game_layer.wait() - for message in game_layer.game_state.messages: - print(message) - for error in game_layer.game_state.errors: - print("Error: " + error) - ''' - def develop_society(): global state, queue_timeout, available_tiles, utilities From d3a4849fd16690dc14b519ce2bba1c4a097de91c Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Wed, 7 Oct 2020 00:43:39 +0200 Subject: [PATCH 38/61] patch launcher --- launcher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/launcher.py b/launcher.py index 23d6915..806528a 100644 --- a/launcher.py +++ b/launcher.py @@ -1,8 +1,8 @@ import main -number_of_launches = 6 +number_of_launches = 4 result_list = [] for i in range(number_of_launches): result_list.append(main.main()) for result in result_list: print("Game " + result[0] + " had a score of: " + str(result[1])) - input("Press Enter to exit") \ No newline at end of file +input("Press Enter to exit") \ No newline at end of file From cf977331e36c42b892c77ee4a4ec57087e45ebdb Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Wed, 7 Oct 2020 03:34:42 +0200 Subject: [PATCH 39/61] PARALLELISERAD LAUNCHER!!! --- launcher.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/launcher.py b/launcher.py index 806528a..3dde4cb 100644 --- a/launcher.py +++ b/launcher.py @@ -1,8 +1,23 @@ import main -number_of_launches = 4 -result_list = [] -for i in range(number_of_launches): - result_list.append(main.main()) -for result in result_list: - print("Game " + result[0] + " had a score of: " + str(result[1])) -input("Press Enter to exit") \ No newline at end of file +import time +from multiprocessing import Pool +import multiprocessing + +proc_running = 4 # MAX 4!!! + + +def run_main(n): + result = main.main() + return result + + +def launch(list): + for result in list: + print("Game " + result[0] + " had a score of: " + str(result[1])) + input("Press Enter to exit") + + +if __name__ == '__main__': + with Pool(proc_running) as p: + results = p.map(run_main, range(proc_running)) + launch(results) From cc693ee83d13de97c5393b3a0dc33b543edcdc8e Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Wed, 7 Oct 2020 04:04:39 +0200 Subject: [PATCH 40/61] some fixes, big work on devsociety and get_best_ --- main.py | 72 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 31 deletions(-) diff --git a/main.py b/main.py index 4abf01e..5294d7e 100644 --- a/main.py +++ b/main.py @@ -5,15 +5,18 @@ from sys import exit from game_layer import GameLayer import game_state import traceback +import random api_key = "74e3998d-ed3d-4d46-9ea8-6aab2efd8ae3" # The different map names can be found on considition.com/rules map_name = "training1" # TODO: You map choice here. If left empty, the map "training1" will be selected. game_layer = GameLayer(api_key) # settings +use_regulator = False +other_upgrade_threshold = 0.25 time_until_run_ends = 70 utilities = 3 -money_reserve_multiplier = 1.5 +money_reserve_multiplier = 1 def main(): @@ -73,22 +76,35 @@ def take_turn(): def develop_society(): - global state, queue_timeout, available_tiles, utilities + global state, queue_timeout, available_tiles, utilities, money_reserve_multiplier + queue_reset = 10 if queue_timeout > 1: queue_timeout -= 1 - + best_residence = calculate_best_residence() + best_upgrade = get_best_upgrade() + build_residence_score = 0 + build_upgrade_score = 0 # priority scores, 1 = very urgent, 0 = not urgent at all # queue modifier * funds modifier * existing houses modifier - build_residence_score = (state.housing_queue / (15 * queue_timeout)) * (1 - (7500 / (1 + state.funds))) * (1 - (len(state.residences) / (1 + len(available_tiles) - utilities))) + # build_residence_score = (state.housing_queue / (15 * queue_timeout)) * (state.funds/(money_reserve_multiplier * 18000)) * (1 - (len(state.residences) / (1 + len(available_tiles) - utilities))) + if len(state.residences) < 1: + build_residence_score = 100 + elif state.housing_queue < 5: + build_residence_score = 0 + elif best_residence: + build_residence_score = best_residence[0] # * (state.housing_queue / (15 * queue_timeout)) + elif state.housing_queue > 15 and queue_timeout <= 0: + build_residence_score = 100 + # upgrade_residence_score = 0 # existing houses modifier * funds modifier * existing utilities modifier build_utility_score = (len(state.residences) / (1 + len(available_tiles)-utilities)) * (1 - (16000 / (1 + state.funds))) * (1 - (len(state.utilities) / utilities)) # turn modifier * funds modifier - build_upgrade_score = (1 - (state.turn / 700)) * (2 - (15000 / (1 + state.funds))) + # build_upgrade_score = (1 - (state.turn / 700)) * (state.funds/(money_reserve_multiplier * 7200)) + if best_upgrade: + build_upgrade_score = best_upgrade[0] - if len(state.residences) < 1: - build_residence_score = 100 decision = [ ('build_residence', build_residence_score), @@ -99,35 +115,29 @@ def develop_society(): def sort_key(e): return e[1] decision.sort(reverse=True, key=sort_key) - - for i in range(4): + print(decision) + if decision[0][1] >= 0: if decision[0][0] == "build_residence": # build housing - queue_timeout = 5 - #if len(state.residences) < len(state.available_residence_buildings): - # return build(state.available_residence_buildings[len(state.residences)].building_name) - #else: - cbr = calculate_best_residence() - if cbr: - return build(cbr[1]) + queue_timeout = queue_reset + if best_residence: + return build(best_residence[1]) if decision[0][0] == "build_utility": # build utilities #return build("WindTurbine") pass - if decision[0][0] == "upgrade_residence": # build utilities + if decision[0][0] == "upgrade_residence": # upgrade housing pass if decision[0][0] == "build_upgrade": # build upgrades - for residence in state.residences: - if state.available_upgrades[0].name not in residence.effects and (money_reserve_multiplier*3500 < state.funds) and ((total_income() - 6) > 50): - game_layer.buy_upgrade((residence.X, residence.Y), state.available_upgrades[0].name) - return True - if state.available_upgrades[5].name not in residence.effects and (money_reserve_multiplier*1250 < state.funds): - game_layer.buy_upgrade((residence.X, residence.Y), state.available_upgrades[5].name) - return True - gbp = get_best_upgrade() - if gbp: - game_layer.buy_upgrade((gbp[2].X, gbp[2].Y), gbp[1]) + if random.random() < other_upgrade_threshold: + for residence in state.residences: + if state.available_upgrades[0].name not in residence.effects and (money_reserve_multiplier*3500 < state.funds) and ((total_income() - 6) > 50): + game_layer.buy_upgrade((residence.X, residence.Y), state.available_upgrades[0].name) + return True + if use_regulator and state.available_upgrades[5].name not in residence.effects and (money_reserve_multiplier*1250 < state.funds): + game_layer.buy_upgrade((residence.X, residence.Y), state.available_upgrades[5].name) + return True + if best_upgrade: + game_layer.buy_upgrade((best_upgrade[2].X, best_upgrade[2].Y), best_upgrade[1]) return True - del decision[0] - return False @@ -218,7 +228,7 @@ def calculate_best_upgrade(current_building): upgrade_co2 = (effect.co2_per_pop_increase * 0.03) * current_pop * rounds_left + (0.1 * lifetime_energy / 1000) old_co2 = 0.03 * current_pop * rounds_left + (0.1 * old_lifetime_energy / 1000) co2 = upgrade_co2 - old_co2 - max_happiness = effect.max_happiness_increase * rounds_left + max_happiness = effect.max_happiness_increase * current_pop * rounds_left score = max_happiness/10 - co2 best_upgrade.append((score, upgrade.name)) @@ -243,7 +253,7 @@ def calculate_best_residence(): lifetime_energy = (residence_blueprint.base_energy_need + average_heating_energy) * rounds_left co2 = 0.03 * residence_blueprint.max_pop * rounds_left + residence_blueprint.co2_cost + (0.1 * lifetime_energy / 1000) - max_happiness = residence_blueprint.max_happiness * rounds_left + max_happiness = residence_blueprint.max_happiness * residence_blueprint.max_pop * rounds_left score = residence_blueprint.max_pop*15 + max_happiness/10 - co2 best_residence.append((score, residence_blueprint.building_name)) From 3e20b79fa3fecea82177feeeccee0b1a811189b1 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Wed, 7 Oct 2020 06:00:35 +0200 Subject: [PATCH 41/61] HS 7800. massa helper functions, calculate best util, tile score, etc --- main.py | 130 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 110 insertions(+), 20 deletions(-) diff --git a/main.py b/main.py index 5294d7e..2db088d 100644 --- a/main.py +++ b/main.py @@ -14,8 +14,7 @@ game_layer = GameLayer(api_key) # settings use_regulator = False other_upgrade_threshold = 0.25 -time_until_run_ends = 70 -utilities = 3 +time_until_run_ends = 90 money_reserve_multiplier = 1 @@ -76,32 +75,32 @@ def take_turn(): def develop_society(): - global state, queue_timeout, available_tiles, utilities, money_reserve_multiplier - queue_reset = 10 + global state, queue_timeout, available_tiles, money_reserve_multiplier + queue_reset = 5 if queue_timeout > 1: queue_timeout -= 1 best_residence = calculate_best_residence() + best_utility = calculate_best_utility() best_upgrade = get_best_upgrade() build_residence_score = 0 + build_utility_score = 0 build_upgrade_score = 0 # priority scores, 1 = very urgent, 0 = not urgent at all - # queue modifier * funds modifier * existing houses modifier - # build_residence_score = (state.housing_queue / (15 * queue_timeout)) * (state.funds/(money_reserve_multiplier * 18000)) * (1 - (len(state.residences) / (1 + len(available_tiles) - utilities))) if len(state.residences) < 1: - build_residence_score = 100 - elif state.housing_queue < 5: + build_residence_score = 1000 + elif (current_tot_pop() - max_tot_pop() + state.housing_queue) < 0: build_residence_score = 0 + elif (current_tot_pop() - max_tot_pop() + state.housing_queue) > 15 and queue_timeout <= 0: + build_residence_score = 1000 elif best_residence: build_residence_score = best_residence[0] # * (state.housing_queue / (15 * queue_timeout)) - elif state.housing_queue > 15 and queue_timeout <= 0: - build_residence_score = 100 # upgrade_residence_score = 0 - # existing houses modifier * funds modifier * existing utilities modifier - build_utility_score = (len(state.residences) / (1 + len(available_tiles)-utilities)) * (1 - (16000 / (1 + state.funds))) * (1 - (len(state.utilities) / utilities)) - # turn modifier * funds modifier - # build_upgrade_score = (1 - (state.turn / 700)) * (state.funds/(money_reserve_multiplier * 7200)) + # + if best_utility: + build_utility_score = best_utility[0] + # if best_upgrade: build_upgrade_score = best_upgrade[0] @@ -115,15 +114,16 @@ def develop_society(): def sort_key(e): return e[1] decision.sort(reverse=True, key=sort_key) - print(decision) + # print(decision) + if decision[0][1] >= 0: if decision[0][0] == "build_residence": # build housing - queue_timeout = queue_reset if best_residence: + queue_timeout = queue_reset return build(best_residence[1]) if decision[0][0] == "build_utility": # build utilities - #return build("WindTurbine") - pass + if best_utility: + return build_place(best_utility[1], best_utility[2]) if decision[0][0] == "upgrade_residence": # upgrade housing pass if decision[0][0] == "build_upgrade": # build upgrades @@ -168,7 +168,7 @@ def something_needs_attention(): return True elif (len(state.utilities)-1 >= building_under_construction[2]) and (state.utilities[building_under_construction[2]].build_progress < 100): game_layer.build((building_under_construction[0], building_under_construction[1])) - if not state.residences[building_under_construction[2]].build_progress < 100: + if not state.utilities[building_under_construction[2]].build_progress < 100: building_under_construction = None return True else: @@ -178,6 +178,22 @@ def something_needs_attention(): return False +def max_tot_pop(): + global state + max_pop = 0 + for residence in state.residences: + max_pop += game_layer.get_blueprint(residence.building_name).max_pop + return max_pop + + +def current_tot_pop(): + global state + current_pop = 0 + for residence in state.residences: + current_pop += residence.current_pop + return current_pop + + def total_income(): global state income = 0 @@ -231,6 +247,7 @@ def calculate_best_upgrade(current_building): max_happiness = effect.max_happiness_increase * current_pop * rounds_left score = max_happiness/10 - co2 + # score = score / upgrade.cost best_upgrade.append((score, upgrade.name)) def sort_key(e): @@ -241,6 +258,38 @@ def calculate_best_upgrade(current_building): return best_upgrade[0] +def calculate_best_utility(): + global state, money_reserve_multiplier + + rounds_left = 700 - state.turn + best_utility = [] + for utility_blueprint in state.available_utility_buildings: + if state.turn >= utility_blueprint.release_tick and (money_reserve_multiplier*utility_blueprint.cost < state.funds): + for i in range(len(available_tiles)): + if isinstance(available_tiles[i], tuple): + score = 0 + cost = utility_blueprint.cost + for effect_name in utility_blueprint.effects: + effect = game_layer.get_effect(effect_name) + affected_people = tile_score(available_tiles[i], effect.radius)[0] + affected_buildings = tile_score(available_tiles[i], effect.radius)[1] + cost -= effect.building_income_increase * rounds_left + happiness_increase = affected_people * effect.max_happiness_increase * rounds_left + co2 = affected_people * effect.co2_per_pop_increase * rounds_left - effect.mwh_production * affected_buildings + score = happiness_increase / 10 - co2 + # score = score / cost + best_utility.append((score, utility_blueprint.building_name, i)) + + + + def sort_key(e): + return e[0] + best_utility.sort(reverse=True, key=sort_key) + if not best_utility: + return False + return best_utility[0] + + def calculate_best_residence(): global state, money_reserve_multiplier @@ -256,6 +305,7 @@ def calculate_best_residence(): max_happiness = residence_blueprint.max_happiness * residence_blueprint.max_pop * rounds_left score = residence_blueprint.max_pop*15 + max_happiness/10 - co2 + # score = score / residence_blueprint.cost best_residence.append((score, residence_blueprint.building_name)) def sort_key(e): @@ -275,6 +325,21 @@ def chart_map(): optimize_available_tiles() +def tile_score(tile, radius): + global state + affected_people = 0 + affected_buildings = 0 + # send back # of max people in radius + for residence in state.residences: + delta_x = abs(tile[0] - residence.X) + delta_y = abs(tile[1] - residence.Y) + distance = delta_x + delta_y + if distance <= radius: + affected_people += residence.current_pop + affected_buildings += 1 + return affected_people, affected_buildings + + def optimize_available_tiles(): global average_x, average_y, score_list average_x = 0 @@ -322,6 +387,32 @@ def adjust_energy(current_building): return False +def build_place(structure, i): + global building_under_construction, rounds_between_energy, state + if isinstance(available_tiles[i], tuple): + game_layer.place_foundation(available_tiles[i], structure) + for building in state.available_residence_buildings: + if structure in building.building_name: + for j in range(len(state.residences)): + building = state.residences[j] + coords_to_check = (building.X, building.Y) + if coords_to_check == available_tiles[i]: + available_tiles[i] = building + building_under_construction = (building.X, building.Y, j) + rounds_between_energy = len(state.residences)+2 + return True + for building in state.available_utility_buildings: + if structure in building.building_name: + for j in range(len(state.utilities)): + building = state.utilities[j] + coords_to_check = (building.X, building.Y) + if coords_to_check == available_tiles[i]: + available_tiles[i] = building + building_under_construction = (building.X, building.Y, j) + return True + return False + + def build(structure): global building_under_construction, rounds_between_energy, state for i in range(len(available_tiles)): @@ -345,7 +436,6 @@ def build(structure): if coords_to_check == available_tiles[i]: available_tiles[i] = building building_under_construction = (building.X, building.Y, j) - rounds_between_energy = len(state.residences)+2 return True return False From dc3e5c154436ad4597a678f521dc4a74ce4addcb Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Wed, 7 Oct 2020 06:03:43 +0200 Subject: [PATCH 42/61] fixa lite i launchern --- clearGames.py | 10 +++++----- launcher.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clearGames.py b/clearGames.py index e36f892..5c47af8 100644 --- a/clearGames.py +++ b/clearGames.py @@ -1,8 +1,8 @@ from game_layer import GameLayer api_key = "74e3998d-ed3d-4d46-9ea8-6aab2efd8ae3" game_layer = GameLayer(api_key) -state = game_layer.game_state -game_layer.force_end_game() -game_layer.force_end_game() -game_layer.force_end_game() -game_layer.force_end_game() \ No newline at end of file +def clear_it(): + game_layer.force_end_game() + game_layer.force_end_game() + game_layer.force_end_game() + game_layer.force_end_game() \ No newline at end of file diff --git a/launcher.py b/launcher.py index 3dde4cb..bc399f8 100644 --- a/launcher.py +++ b/launcher.py @@ -1,7 +1,6 @@ import main -import time +import clearGames from multiprocessing import Pool -import multiprocessing proc_running = 4 # MAX 4!!! @@ -18,6 +17,7 @@ def launch(list): if __name__ == '__main__': + clearGames.clear_it() with Pool(proc_running) as p: results = p.map(run_main, range(proc_running)) launch(results) From 00b96b09c322a0bc85c0a8e500787bc94cd4f828 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Wed, 7 Oct 2020 06:52:30 +0200 Subject: [PATCH 43/61] fixes --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 2db088d..8397eb5 100644 --- a/main.py +++ b/main.py @@ -15,7 +15,7 @@ game_layer = GameLayer(api_key) use_regulator = False other_upgrade_threshold = 0.25 time_until_run_ends = 90 -money_reserve_multiplier = 1 +money_reserve_multiplier = 0.1 def main(): @@ -334,7 +334,7 @@ def tile_score(tile, radius): delta_x = abs(tile[0] - residence.X) delta_y = abs(tile[1] - residence.Y) distance = delta_x + delta_y - if distance <= radius: + if (distance <= radius) and not ("Park", "WindTurbine", "Mall.2" in residence.effects): affected_people += residence.current_pop affected_buildings += 1 return affected_people, affected_buildings From 68cceee9fa86f325e70f5d695ce35b84742ab80e Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Wed, 7 Oct 2020 13:41:44 +0200 Subject: [PATCH 44/61] launcher remove input --- launcher.py | 1 - 1 file changed, 1 deletion(-) diff --git a/launcher.py b/launcher.py index bc399f8..2f69911 100644 --- a/launcher.py +++ b/launcher.py @@ -13,7 +13,6 @@ def run_main(n): def launch(list): for result in list: print("Game " + result[0] + " had a score of: " + str(result[1])) - input("Press Enter to exit") if __name__ == '__main__': From 87356ad8bd6574777f1e4e9664f80d5c7c15e14c Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Wed, 7 Oct 2020 17:58:03 +0200 Subject: [PATCH 45/61] =?UTF-8?q?f=C3=B6rb=C3=A4ttra=20loq=20health=20dete?= =?UTF-8?q?ction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 8397eb5..4e07f5b 100644 --- a/main.py +++ b/main.py @@ -150,7 +150,8 @@ def something_needs_attention(): # check if need for maintenance maintain = (False, 0) for i in range(len(state.residences)): - if state.residences[i].health < 35+rounds_between_energy*game_layer.get_residence_blueprint(state.residences[i].building_name).decay_rate: + blueprint = game_layer.get_residence_blueprint(state.residences[i].building_name) + if state.residences[i].health < 40+(max(((blueprint.maintenance_cost- state.funds) / (1+total_income())), 1) * blueprint.decay_rate): maintain = (True, i) if (state.turn % rounds_between_energy == i) and not state.residences[i].build_progress < 100: edit_temp = (True, i) From 6af8e1a46dcd6b0e9808a1136f76173d86b678ef Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Wed, 7 Oct 2020 19:14:26 +0200 Subject: [PATCH 46/61] optimize vars --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 4e07f5b..bd299ec 100644 --- a/main.py +++ b/main.py @@ -15,7 +15,7 @@ game_layer = GameLayer(api_key) use_regulator = False other_upgrade_threshold = 0.25 time_until_run_ends = 90 -money_reserve_multiplier = 0.1 +money_reserve_multiplier = 0 def main(): @@ -76,7 +76,7 @@ def take_turn(): def develop_society(): global state, queue_timeout, available_tiles, money_reserve_multiplier - queue_reset = 5 + queue_reset = 1 if queue_timeout > 1: queue_timeout -= 1 From 96633a9e98fe60faa8d5298fb1c10659bc9b3d6c Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Wed, 7 Oct 2020 19:15:09 +0200 Subject: [PATCH 47/61] fix build position --- main.py | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/main.py b/main.py index bd299ec..55771fe 100644 --- a/main.py +++ b/main.py @@ -392,26 +392,14 @@ def build_place(structure, i): global building_under_construction, rounds_between_energy, state if isinstance(available_tiles[i], tuple): game_layer.place_foundation(available_tiles[i], structure) - for building in state.available_residence_buildings: - if structure in building.building_name: - for j in range(len(state.residences)): - building = state.residences[j] - coords_to_check = (building.X, building.Y) - if coords_to_check == available_tiles[i]: - available_tiles[i] = building - building_under_construction = (building.X, building.Y, j) - rounds_between_energy = len(state.residences)+2 - return True - for building in state.available_utility_buildings: - if structure in building.building_name: - for j in range(len(state.utilities)): - building = state.utilities[j] - coords_to_check = (building.X, building.Y) - if coords_to_check == available_tiles[i]: - available_tiles[i] = building - building_under_construction = (building.X, building.Y, j) - return True - return False + for j in range(len(state.utilities)): + building = state.utilities[j] + coords_to_check = (building.X, building.Y) + if coords_to_check == available_tiles[i]: + available_tiles[i] = building + building_under_construction = (building.X, building.Y, j) + return True + return False def build(structure): @@ -438,7 +426,7 @@ def build(structure): available_tiles[i] = building building_under_construction = (building.X, building.Y, j) return True - return False + return False if __name__ == "__main__": From fd424496bb978642921e802791c265f094458e11 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Wed, 7 Oct 2020 19:15:31 +0200 Subject: [PATCH 48/61] tilescore check effect properly --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 55771fe..fd80cbf 100644 --- a/main.py +++ b/main.py @@ -326,7 +326,7 @@ def chart_map(): optimize_available_tiles() -def tile_score(tile, radius): +def tile_score(tile, radius, effect): global state affected_people = 0 affected_buildings = 0 @@ -335,7 +335,7 @@ def tile_score(tile, radius): delta_x = abs(tile[0] - residence.X) delta_y = abs(tile[1] - residence.Y) distance = delta_x + delta_y - if (distance <= radius) and not ("Park", "WindTurbine", "Mall.2" in residence.effects): + if (distance <= radius) and not effect in residence.effects: affected_people += residence.current_pop affected_buildings += 1 return affected_people, affected_buildings From 5637da5a3480aaf259ecb3ed48ece1f65fcc131c Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Wed, 7 Oct 2020 19:16:42 +0200 Subject: [PATCH 49/61] check building diversity and take account for build delay in score --- main.py | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index fd80cbf..01473c3 100644 --- a/main.py +++ b/main.py @@ -262,30 +262,31 @@ def calculate_best_upgrade(current_building): def calculate_best_utility(): global state, money_reserve_multiplier - rounds_left = 700 - state.turn best_utility = [] for utility_blueprint in state.available_utility_buildings: if state.turn >= utility_blueprint.release_tick and (money_reserve_multiplier*utility_blueprint.cost < state.funds): + rounds_left = 700 - state.turn - (100 / utility_blueprint.build_speed) + for i in range(len(available_tiles)): if isinstance(available_tiles[i], tuple): score = 0 cost = utility_blueprint.cost for effect_name in utility_blueprint.effects: effect = game_layer.get_effect(effect_name) - affected_people = tile_score(available_tiles[i], effect.radius)[0] - affected_buildings = tile_score(available_tiles[i], effect.radius)[1] + affected_people = tile_score(available_tiles[i], effect.radius, effect_name)[0] + affected_buildings = tile_score(available_tiles[i], effect.radius, effect_name)[1] cost -= effect.building_income_increase * rounds_left happiness_increase = affected_people * effect.max_happiness_increase * rounds_left - co2 = affected_people * effect.co2_per_pop_increase * rounds_left - effect.mwh_production * affected_buildings - score = happiness_increase / 10 - co2 + co2 = affected_people * effect.co2_per_pop_increase * rounds_left - effect.mwh_production * affected_buildings * rounds_left + score += happiness_increase / 10 - co2 + # print(effect_name + " gave score " + str(score)) # score = score / cost best_utility.append((score, utility_blueprint.building_name, i)) - - def sort_key(e): return e[0] best_utility.sort(reverse=True, key=sort_key) + # print(best_utility) if not best_utility: return False return best_utility[0] @@ -294,18 +295,30 @@ def calculate_best_utility(): def calculate_best_residence(): global state, money_reserve_multiplier - rounds_left = 700 - state.turn best_residence = [] for residence_blueprint in state.available_residence_buildings: if state.turn >= residence_blueprint.release_tick and (money_reserve_multiplier*residence_blueprint.cost < state.funds): + rounds_left = 700 - state.turn - (100 / residence_blueprint.build_speed) + average_outdoor_temp = (state.max_temp - state.min_temp)/2 average_heating_energy = ((0 - 0.04 * residence_blueprint.max_pop + (21 - average_outdoor_temp) * residence_blueprint.emissivity) / 0.75) lifetime_energy = (residence_blueprint.base_energy_need + average_heating_energy) * rounds_left + distinct_residences = number_of_distinct_residences(residence_blueprint.building_name) + diversity = 1 + distinct_residences[0]/10 + co2 = 0.03 * residence_blueprint.max_pop * rounds_left + residence_blueprint.co2_cost + (0.1 * lifetime_energy / 1000) max_happiness = residence_blueprint.max_happiness * residence_blueprint.max_pop * rounds_left + max_happiness *= diversity - score = residence_blueprint.max_pop*15 + max_happiness/10 - co2 + diversity_bonus = 0 + if distinct_residences[1]: + happy = 0 + for residence in state.residences: + happy += residence.happiness_per_tick_per_pop * residence.current_pop + diversity_bonus = (happy * rounds_left / 10) / 10 + + score = residence_blueprint.max_pop*15 + max_happiness / 10 - co2 + diversity_bonus # score = score / residence_blueprint.cost best_residence.append((score, residence_blueprint.building_name)) @@ -317,6 +330,18 @@ def calculate_best_residence(): return best_residence[0] +def number_of_distinct_residences(new_building): + global state + unique_names = [] + for residence in state.residences: + if not residence.building_name in unique_names: + unique_names.append(residence.building_name) + if not new_building in unique_names: + unique_names.append(new_building) + return len(unique_names), True + return len(unique_names), False + + def chart_map(): global state for x in range(len(state.map) - 1): From 17fc759321b05d71af769a796cebd26c9eb65d2f Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Wed, 7 Oct 2020 20:02:22 +0200 Subject: [PATCH 50/61] temp acceleration multiplier --- main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 01473c3..7bd0a4f 100644 --- a/main.py +++ b/main.py @@ -16,6 +16,7 @@ use_regulator = False other_upgrade_threshold = 0.25 time_until_run_ends = 90 money_reserve_multiplier = 0 +temp_acc_multiplier = 1.125 def main(): @@ -388,7 +389,7 @@ def optimize_available_tiles(): def adjust_energy(current_building): - global rounds_between_energy, EMA_temp, state + global rounds_between_energy, EMA_temp, state, temp_acc_multiplier blueprint = game_layer.get_residence_blueprint(current_building.building_name) base_energy = blueprint.base_energy_need if "Charger" in current_building.effects: @@ -399,7 +400,7 @@ def adjust_energy(current_building): emissivity *= 0.6 outDoorTemp = state.current_temp * 2 - EMA_temp - temp_acceleration = (2*(21 - current_building.temperature)/(rounds_between_energy)) + temp_acceleration = (2*(21 - current_building.temperature)/(rounds_between_energy)) * temp_acc_multiplier effectiveEnergyIn = ((temp_acceleration - 0.04 * current_building.current_pop + (current_building.temperature - outDoorTemp) * emissivity) / 0.75) + base_energy From d25f6f2ac132c4c95dfc23d6b7c9142851f48ff1 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Wed, 7 Oct 2020 20:02:47 +0200 Subject: [PATCH 51/61] fix for building functions --- main.py | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/main.py b/main.py index 7bd0a4f..2de8f1e 100644 --- a/main.py +++ b/main.py @@ -418,6 +418,13 @@ def build_place(structure, i): global building_under_construction, rounds_between_energy, state if isinstance(available_tiles[i], tuple): game_layer.place_foundation(available_tiles[i], structure) + for j in range(len(state.residences)): + building = state.residences[j] + coords_to_check = (building.X, building.Y) + if coords_to_check == available_tiles[i]: + available_tiles[i] = building + building_under_construction = (building.X, building.Y, j) + return True for j in range(len(state.utilities)): building = state.utilities[j] coords_to_check = (building.X, building.Y) @@ -433,25 +440,22 @@ def build(structure): for i in range(len(available_tiles)): if isinstance(available_tiles[i], tuple): game_layer.place_foundation(available_tiles[i], structure) - for building in state.available_residence_buildings: - if structure in building.building_name: - for j in range(len(state.residences)): - building = state.residences[j] - coords_to_check = (building.X, building.Y) - if coords_to_check == available_tiles[i]: - available_tiles[i] = building - building_under_construction = (building.X, building.Y, j) - rounds_between_energy = len(state.residences)+2 - return True - for building in state.available_utility_buildings: - if structure in building.building_name: - for j in range(len(state.utilities)): - building = state.utilities[j] - coords_to_check = (building.X, building.Y) - if coords_to_check == available_tiles[i]: - available_tiles[i] = building - building_under_construction = (building.X, building.Y, j) - return True + for j in range(len(state.residences)): + building = state.residences[j] + coords_to_check = (building.X, building.Y) + if coords_to_check == available_tiles[i]: + available_tiles[i] = building + building_under_construction = (building.X, building.Y, j) + rounds_between_energy = len(state.residences)+2 + return True + for j in range(len(state.utilities)): + building = state.utilities[j] + coords_to_check = (building.X, building.Y) + if coords_to_check == available_tiles[i]: + available_tiles[i] = building + building_under_construction = (building.X, building.Y, j) + return True + return False return False From 2c3d4897e7e98057427823e75296649584ed06c7 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Thu, 8 Oct 2020 00:27:31 +0200 Subject: [PATCH 52/61] clear junk and remove some soft warnings --- main.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index 2de8f1e..8a19ddb 100644 --- a/main.py +++ b/main.py @@ -18,6 +18,16 @@ time_until_run_ends = 90 money_reserve_multiplier = 0 temp_acc_multiplier = 1.125 +# vars +EMA_temp = none +rounds_between_energy = none +building_under_construction = none +available_tiles = none +state = none +queue_timeout = none +edit_temp = none +maintain = none + def main(): global EMA_temp, rounds_between_energy, building_under_construction, available_tiles, state, queue_timeout @@ -95,7 +105,7 @@ def develop_society(): elif (current_tot_pop() - max_tot_pop() + state.housing_queue) > 15 and queue_timeout <= 0: build_residence_score = 1000 elif best_residence: - build_residence_score = best_residence[0] # * (state.housing_queue / (15 * queue_timeout)) + build_residence_score = best_residence[0] # upgrade_residence_score = 0 # @@ -105,13 +115,13 @@ def develop_society(): if best_upgrade: build_upgrade_score = best_upgrade[0] - decision = [ ('build_residence', build_residence_score), ('upgrade_residence', upgrade_residence_score), ('build_utility', build_utility_score), ('build_upgrade', build_upgrade_score) ] + def sort_key(e): return e[1] decision.sort(reverse=True, key=sort_key) @@ -142,7 +152,6 @@ def develop_society(): return False - def something_needs_attention(): global building_under_construction, edit_temp, maintain, state, rounds_between_energy @@ -152,7 +161,7 @@ def something_needs_attention(): maintain = (False, 0) for i in range(len(state.residences)): blueprint = game_layer.get_residence_blueprint(state.residences[i].building_name) - if state.residences[i].health < 40+(max(((blueprint.maintenance_cost- state.funds) / (1+total_income())), 1) * blueprint.decay_rate): + if state.residences[i].health < 40+(max(((blueprint.maintenance_cost - state.funds) / (1+total_income())), 1) * blueprint.decay_rate): maintain = (True, i) if (state.turn % rounds_between_energy == i) and not state.residences[i].build_progress < 100: edit_temp = (True, i) @@ -242,7 +251,6 @@ def calculate_best_upgrade(current_building): lifetime_energy = (base_energy_need + effect.base_energy_mwh_increase + average_heating_energy - effect.mwh_production) * rounds_left old_lifetime_energy = (base_energy_need + old_average_heating_energy) * rounds_left - upgrade_co2 = (effect.co2_per_pop_increase * 0.03) * current_pop * rounds_left + (0.1 * lifetime_energy / 1000) old_co2 = 0.03 * current_pop * rounds_left + (0.1 * old_lifetime_energy / 1000) co2 = upgrade_co2 - old_co2 @@ -335,9 +343,9 @@ def number_of_distinct_residences(new_building): global state unique_names = [] for residence in state.residences: - if not residence.building_name in unique_names: + if residence.building_name not in unique_names: unique_names.append(residence.building_name) - if not new_building in unique_names: + if new_building not in unique_names: unique_names.append(new_building) return len(unique_names), True return len(unique_names), False @@ -361,14 +369,13 @@ def tile_score(tile, radius, effect): delta_x = abs(tile[0] - residence.X) delta_y = abs(tile[1] - residence.Y) distance = delta_x + delta_y - if (distance <= radius) and not effect in residence.effects: + if (distance <= radius) and effect not in residence.effects: affected_people += residence.current_pop affected_buildings += 1 return affected_people, affected_buildings def optimize_available_tiles(): - global average_x, average_y, score_list average_x = 0 average_y = 0 score_list = [] @@ -399,15 +406,15 @@ def adjust_energy(current_building): if "Insulation" in current_building.effects: emissivity *= 0.6 - outDoorTemp = state.current_temp * 2 - EMA_temp - temp_acceleration = (2*(21 - current_building.temperature)/(rounds_between_energy)) * temp_acc_multiplier + out_door_temp = state.current_temp * 2 - EMA_temp + temp_acceleration = (2*(21 - current_building.temperature)/rounds_between_energy) * temp_acc_multiplier - effectiveEnergyIn = ((temp_acceleration - 0.04 * current_building.current_pop + (current_building.temperature - outDoorTemp) * emissivity) / 0.75) + base_energy + effective_energy_in = ((temp_acceleration - 0.04 * current_building.current_pop + (current_building.temperature - out_door_temp) * emissivity) / 0.75) + base_energy - if effectiveEnergyIn > base_energy: - game_layer.adjust_energy_level((current_building.X, current_building.Y), effectiveEnergyIn) + if effective_energy_in > base_energy: + game_layer.adjust_energy_level((current_building.X, current_building.Y), effective_energy_in) return True - elif effectiveEnergyIn < base_energy: + elif effective_energy_in < base_energy: game_layer.adjust_energy_level((current_building.X, current_building.Y), base_energy + 0.01) return True else: From 7e2599c3358caf4500d848712d7da8c72140513a Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Thu, 8 Oct 2020 00:28:16 +0200 Subject: [PATCH 53/61] fix none to None --- main.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 8a19ddb..a3fd01b 100644 --- a/main.py +++ b/main.py @@ -19,14 +19,14 @@ money_reserve_multiplier = 0 temp_acc_multiplier = 1.125 # vars -EMA_temp = none -rounds_between_energy = none -building_under_construction = none -available_tiles = none -state = none -queue_timeout = none -edit_temp = none -maintain = none +EMA_temp = None +rounds_between_energy = None +building_under_construction = None +available_tiles = None +state = None +queue_timeout = None +edit_temp = None +maintain = None def main(): From 259fdc14e89fef1f3d1896442b6c77868e93d44b Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Thu, 8 Oct 2020 01:59:16 +0200 Subject: [PATCH 54/61] hotfix --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index a3fd01b..6b76ef1 100644 --- a/main.py +++ b/main.py @@ -20,11 +20,11 @@ temp_acc_multiplier = 1.125 # vars EMA_temp = None -rounds_between_energy = None +rounds_between_energy = 5 building_under_construction = None -available_tiles = None +available_tiles = [] state = None -queue_timeout = None +queue_timeout = 1 edit_temp = None maintain = None From 21ef5b75da27b091c22d658705fd19343d7763f0 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Thu, 8 Oct 2020 02:00:05 +0200 Subject: [PATCH 55/61] build residences near utilities --- main.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 6b76ef1..af97689 100644 --- a/main.py +++ b/main.py @@ -125,13 +125,16 @@ def develop_society(): def sort_key(e): return e[1] decision.sort(reverse=True, key=sort_key) - # print(decision) + print(decision) if decision[0][1] >= 0: if decision[0][0] == "build_residence": # build housing if best_residence: queue_timeout = queue_reset - return build(best_residence[1]) + if best_residence[2]: + return build_place(best_residence[1], best_residence[2]) + else: + return build(best_residence[1]) if decision[0][0] == "build_utility": # build utilities if best_utility: return build_place(best_utility[1], best_utility[2]) @@ -329,7 +332,27 @@ def calculate_best_residence(): score = residence_blueprint.max_pop*15 + max_happiness / 10 - co2 + diversity_bonus # score = score / residence_blueprint.cost - best_residence.append((score, residence_blueprint.building_name)) + + # calculate tiles near utils + best_foundation_tile = [] + for i in range(len(available_tiles)): + tile = available_tiles[i] + if isinstance(tile, tuple): + for utility in state.utilities: + for effect_name in utility.effects: + effect = game_layer.get_effect(effect_name) + delta_x = abs(tile[0] - utility.X) + delta_y = abs(tile[1] - utility.Y) + distance = delta_x + delta_y + if (distance <= effect.radius): + best_foundation_tile.append((distance, i)) + def sort_key(e): + return e[0] + best_foundation_tile.sort(key=sort_key) + if best_foundation_tile: + best_residence.append((score, residence_blueprint.building_name, best_foundation_tile[0][1])) + else: + best_residence.append((score, residence_blueprint.building_name, False)) def sort_key(e): return e[0] @@ -431,6 +454,7 @@ def build_place(structure, i): if coords_to_check == available_tiles[i]: available_tiles[i] = building building_under_construction = (building.X, building.Y, j) + rounds_between_energy = len(state.residences)+2 return True for j in range(len(state.utilities)): building = state.utilities[j] From a7d1981d7147be8eaa10b116d63287a4f7513f23 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Thu, 8 Oct 2020 02:49:39 +0200 Subject: [PATCH 56/61] ema length --- main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index af97689..b9c8cf9 100644 --- a/main.py +++ b/main.py @@ -34,6 +34,7 @@ def main(): # global vars rounds_between_energy = 5 EMA_temp = None + ema_length = 16 building_under_construction = None available_tiles = [] queue_timeout = 1 @@ -50,7 +51,7 @@ def main(): try: if EMA_temp is None: EMA_temp = state.current_temp - ema_k_value = (2/(rounds_between_energy+1)) + ema_k_value = (2/(ema_length+1)) EMA_temp = state.current_temp * ema_k_value + EMA_temp*(1-ema_k_value) take_turn() except Exception: From 1b298bb72f7417de1721d173d143f8bd0ef049f0 Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Thu, 8 Oct 2020 02:50:05 +0200 Subject: [PATCH 57/61] minor changes --- main.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index b9c8cf9..80bf4de 100644 --- a/main.py +++ b/main.py @@ -12,15 +12,16 @@ api_key = "74e3998d-ed3d-4d46-9ea8-6aab2efd8ae3" map_name = "training1" # TODO: You map choice here. If left empty, the map "training1" will be selected. game_layer = GameLayer(api_key) # settings -use_regulator = False +use_regulator = True other_upgrade_threshold = 0.25 time_until_run_ends = 90 money_reserve_multiplier = 0 temp_acc_multiplier = 1.125 +rounds_between_energy = 5 +round_buffer = 0 # vars EMA_temp = None -rounds_between_energy = 5 building_under_construction = None available_tiles = [] state = None @@ -259,7 +260,8 @@ def calculate_best_upgrade(current_building): old_co2 = 0.03 * current_pop * rounds_left + (0.1 * old_lifetime_energy / 1000) co2 = upgrade_co2 - old_co2 max_happiness = effect.max_happiness_increase * current_pop * rounds_left - + if "Charger" in current_building.effects and upgrade.name == "Mall.2": + co2 = 0 score = max_happiness/10 - co2 # score = score / upgrade.cost best_upgrade.append((score, upgrade.name)) @@ -273,12 +275,12 @@ def calculate_best_upgrade(current_building): def calculate_best_utility(): - global state, money_reserve_multiplier + global state, money_reserve_multiplier, round_buffer best_utility = [] for utility_blueprint in state.available_utility_buildings: if state.turn >= utility_blueprint.release_tick and (money_reserve_multiplier*utility_blueprint.cost < state.funds): - rounds_left = 700 - state.turn - (100 / utility_blueprint.build_speed) + rounds_left = 700 - state.turn - (100 / utility_blueprint.build_speed) - round_buffer for i in range(len(available_tiles)): if isinstance(available_tiles[i], tuple): @@ -306,12 +308,12 @@ def calculate_best_utility(): def calculate_best_residence(): - global state, money_reserve_multiplier + global state, money_reserve_multiplier, round_buffer best_residence = [] for residence_blueprint in state.available_residence_buildings: if state.turn >= residence_blueprint.release_tick and (money_reserve_multiplier*residence_blueprint.cost < state.funds): - rounds_left = 700 - state.turn - (100 / residence_blueprint.build_speed) + rounds_left = 700 - state.turn - (100 / residence_blueprint.build_speed) - round_buffer average_outdoor_temp = (state.max_temp - state.min_temp)/2 average_heating_energy = ((0 - 0.04 * residence_blueprint.max_pop + (21 - average_outdoor_temp) * residence_blueprint.emissivity) / 0.75) @@ -455,7 +457,7 @@ def build_place(structure, i): if coords_to_check == available_tiles[i]: available_tiles[i] = building building_under_construction = (building.X, building.Y, j) - rounds_between_energy = len(state.residences)+2 + rounds_between_energy = len(state.residences)+1 return True for j in range(len(state.utilities)): building = state.utilities[j] @@ -478,7 +480,7 @@ def build(structure): if coords_to_check == available_tiles[i]: available_tiles[i] = building building_under_construction = (building.X, building.Y, j) - rounds_between_energy = len(state.residences)+2 + rounds_between_energy = len(state.residences)+1 return True for j in range(len(state.utilities)): building = state.utilities[j] From 95c0ab761a5f66da2eb4714a38b0066d5d23ea5a Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Thu, 8 Oct 2020 03:50:33 +0200 Subject: [PATCH 58/61] round buffer --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 80bf4de..0db1d89 100644 --- a/main.py +++ b/main.py @@ -18,7 +18,7 @@ time_until_run_ends = 90 money_reserve_multiplier = 0 temp_acc_multiplier = 1.125 rounds_between_energy = 5 -round_buffer = 0 +round_buffer = 78 # vars EMA_temp = None @@ -457,7 +457,7 @@ def build_place(structure, i): if coords_to_check == available_tiles[i]: available_tiles[i] = building building_under_construction = (building.X, building.Y, j) - rounds_between_energy = len(state.residences)+1 + rounds_between_energy = len(state.residences)+2 return True for j in range(len(state.utilities)): building = state.utilities[j] @@ -480,7 +480,7 @@ def build(structure): if coords_to_check == available_tiles[i]: available_tiles[i] = building building_under_construction = (building.X, building.Y, j) - rounds_between_energy = len(state.residences)+1 + rounds_between_energy = len(state.residences)+2 return True for j in range(len(state.utilities)): building = state.utilities[j] From 4a649b9124d4019ec9facb7dc5f1f3c2a07fa9cd Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Thu, 8 Oct 2020 03:50:44 +0200 Subject: [PATCH 59/61] mall/charger fix --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 0db1d89..b79dea3 100644 --- a/main.py +++ b/main.py @@ -256,12 +256,12 @@ def calculate_best_upgrade(current_building): lifetime_energy = (base_energy_need + effect.base_energy_mwh_increase + average_heating_energy - effect.mwh_production) * rounds_left old_lifetime_energy = (base_energy_need + old_average_heating_energy) * rounds_left - upgrade_co2 = (effect.co2_per_pop_increase * 0.03) * current_pop * rounds_left + (0.1 * lifetime_energy / 1000) + upgrade_co2 = (effect.co2_per_pop_increase + 0.03) * current_pop * rounds_left + (0.1 * lifetime_energy / 1000) + if "Mall.2" in current_building.effects and upgrade.name == "Charger": + upgrade_co2 = (effect.co2_per_pop_increase - 0.009 + 0.03) * current_pop * rounds_left + (0.1 * lifetime_energy / 1000) old_co2 = 0.03 * current_pop * rounds_left + (0.1 * old_lifetime_energy / 1000) co2 = upgrade_co2 - old_co2 max_happiness = effect.max_happiness_increase * current_pop * rounds_left - if "Charger" in current_building.effects and upgrade.name == "Mall.2": - co2 = 0 score = max_happiness/10 - co2 # score = score / upgrade.cost best_upgrade.append((score, upgrade.name)) From 38a3ea5e2ea66873ce3cbb9ee0be51dc9dbcc6df Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Thu, 8 Oct 2020 03:57:17 +0200 Subject: [PATCH 60/61] auto use regulator --- main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index b79dea3..cf2db6e 100644 --- a/main.py +++ b/main.py @@ -12,8 +12,8 @@ api_key = "74e3998d-ed3d-4d46-9ea8-6aab2efd8ae3" map_name = "training1" # TODO: You map choice here. If left empty, the map "training1" will be selected. game_layer = GameLayer(api_key) # settings -use_regulator = True -other_upgrade_threshold = 0.25 +use_regulator = False # turns on if map max temp >21c +other_upgrade_threshold = 0.5 time_until_run_ends = 90 money_reserve_multiplier = 0 temp_acc_multiplier = 1.125 @@ -31,7 +31,7 @@ maintain = None def main(): - global EMA_temp, rounds_between_energy, building_under_construction, available_tiles, state, queue_timeout + global EMA_temp, rounds_between_energy, building_under_construction, available_tiles, state, queue_timeout, use_regulator # global vars rounds_between_energy = 5 EMA_temp = None @@ -47,6 +47,8 @@ def main(): start_time = time.time() state = game_layer.game_state chart_map() + if state.max_temp >21: + use_regulator = True while state.turn < state.max_turns: state = game_layer.game_state try: From 3271e4be5680e2ee09f3dcbe320f73eb725c2e7b Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Thu, 8 Oct 2020 04:44:03 +0200 Subject: [PATCH 61/61] =?UTF-8?q?sm=C3=A5skit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index cf2db6e..2ecf874 100644 --- a/main.py +++ b/main.py @@ -15,7 +15,7 @@ game_layer = GameLayer(api_key) use_regulator = False # turns on if map max temp >21c other_upgrade_threshold = 0.5 time_until_run_ends = 90 -money_reserve_multiplier = 0 +money_reserve_multiplier = 0.5 temp_acc_multiplier = 1.125 rounds_between_energy = 5 round_buffer = 78 @@ -47,7 +47,7 @@ def main(): start_time = time.time() state = game_layer.game_state chart_map() - if state.max_temp >21: + if state.max_temp > 21: use_regulator = True while state.turn < state.max_turns: state = game_layer.game_state @@ -108,15 +108,15 @@ def develop_society(): build_residence_score = 0 elif (current_tot_pop() - max_tot_pop() + state.housing_queue) > 15 and queue_timeout <= 0: build_residence_score = 1000 - elif best_residence: + elif best_residence and best_residence[0] > 0: build_residence_score = best_residence[0] # upgrade_residence_score = 0 # - if best_utility: + if best_utility and best_utility[0] > 0: build_utility_score = best_utility[0] # - if best_upgrade: + if best_upgrade and best_upgrade[0] > 0: build_upgrade_score = best_upgrade[0] decision = [ @@ -252,8 +252,8 @@ def calculate_best_upgrade(current_building): if (upgrade.name not in current_building.effects) and ((total_income() + effect.building_income_increase) > 50) and (money_reserve_multiplier*upgrade.cost < state.funds): average_outdoor_temp = (state.max_temp - state.min_temp)/2 - average_heating_energy = (((21 - average_outdoor_temp) * blueprint.emissivity * effect.emissivity_multiplier) / 0.75) - old_average_heating_energy = (((21 - average_outdoor_temp) * blueprint.emissivity) / 0.75) + average_heating_energy = max((((21 - average_outdoor_temp) * blueprint.emissivity * effect.emissivity_multiplier) / 0.75), 0) + old_average_heating_energy = max((((21 - average_outdoor_temp) * blueprint.emissivity) / 0.75), 0) lifetime_energy = (base_energy_need + effect.base_energy_mwh_increase + average_heating_energy - effect.mwh_production) * rounds_left old_lifetime_energy = (base_energy_need + old_average_heating_energy) * rounds_left