From 8b6eb1abb245159ad4ee26e7d69a2ea8f606b9d6 Mon Sep 17 00:00:00 2001 From: linhara Date: Sun, 4 Oct 2020 12:26:34 +0200 Subject: [PATCH 1/5] 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 2/5] 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 3/5] =?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 4/5] 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 5/5] 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