energy WORKING ema temp sak

This commit is contained in:
Thefeli73 2020-10-04 14:23:50 +02:00
parent 0c49a3fb37
commit cb2f1999d9

20
main.py
View File

@ -14,8 +14,9 @@ game_layer = GameLayer(api_key)
state = game_layer.game_state state = game_layer.game_state
usePrebuiltStrategy = False usePrebuiltStrategy = False
timeUntilRunEnds = 50 timeUntilRunEnds = 50
rounds_between_energy = 7 rounds_between_energy = 6
EMA_temp = None
def main(): def main():
@ -26,8 +27,13 @@ def main():
game_layer.start_game() game_layer.start_game()
# exit game after timeout # exit game after timeout
start_time = time.time() start_time = time.time()
global EMA_temp
while game_layer.game_state.turn < game_layer.game_state.max_turns: while game_layer.game_state.turn < game_layer.game_state.max_turns:
try: 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() linus_take_turn()
except: except:
print(traceback.format_exc()) print(traceback.format_exc())
@ -49,7 +55,6 @@ def linus_take_turn():
if state.map[x][y] == 0: if state.map[x][y] == 0:
freeSpace.append((x,y)) freeSpace.append((x,y))
#print(mylist)
#if (i == 0 or i%5 == 0)and i<26: #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) # 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: if the_third_residence.build_progress < 100:
game_layer.build(freeSpace[5]) game_layer.build(freeSpace[5])
if len(state.residences) == 3: 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] the_fourth_residence = state.residences[3]
if the_fourth_residence.build_progress < 100: if the_fourth_residence.build_progress < 100:
game_layer.build((4,4)) game_layer.build((4,4))
@ -82,7 +87,7 @@ def linus_take_turn():
game_layer.build((4,5)) game_layer.build((4,5))
if len(state.residences) == 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] the_sixth_residence = state.residences[5]
if (the_sixth_residence.build_progress < 100) and game_layer.game_state.funds > 4000: if (the_sixth_residence.build_progress < 100) and game_layer.game_state.funds > 4000:
game_layer.build((4,6)) game_layer.build((4,6))
@ -192,11 +197,12 @@ def chartMap():
availableTiles.append((x, y)) availableTiles.append((x, y))
def adjustEnergy(currentBuilding): def adjustEnergy(currentBuilding):
global rounds_between_engery global rounds_between_energy
global EMA_temp
blueprint = game_layer.get_residence_blueprint(currentBuilding.building_name) 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 effectiveEnergyIn = ((temp_acceleration - 0.04 * currentBuilding.current_pop + (currentBuilding.temperature - outDoorTemp) * blueprint.emissivity) / 0.75) + blueprint.base_energy_need