kommentera trash metoden, optimizations, jobb på decision engine
This commit is contained in:
parent
638ebcfd72
commit
9713be3eaf
48
main.py
48
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.
|
map_name = "training1" # TODO: You map choice here. If left empty, the map "training1" will be selected.
|
||||||
game_layer = GameLayer(api_key)
|
game_layer = GameLayer(api_key)
|
||||||
# settings
|
# settings
|
||||||
use_prebuilt_strategy = False
|
|
||||||
time_until_run_ends = 70
|
time_until_run_ends = 70
|
||||||
utilities = 3
|
utilities = 3
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ def main():
|
|||||||
EMA_temp = None
|
EMA_temp = None
|
||||||
building_under_construction = None
|
building_under_construction = None
|
||||||
available_tiles = []
|
available_tiles = []
|
||||||
queue_timeout = 0
|
queue_timeout = 1
|
||||||
|
|
||||||
game_layer.new_game(map_name)
|
game_layer.new_game(map_name)
|
||||||
print("Starting game: " + game_layer.game_state.game_id)
|
print("Starting game: " + game_layer.game_state.game_id)
|
||||||
@ -55,7 +54,6 @@ def main():
|
|||||||
|
|
||||||
def take_turn():
|
def take_turn():
|
||||||
global state
|
global state
|
||||||
if not use_prebuilt_strategy:
|
|
||||||
# TODO Implement your artificial intelligence here.
|
# TODO Implement your artificial intelligence here.
|
||||||
# TODO Take one action per turn until the game ends.
|
# TODO Take one action per turn until the game ends.
|
||||||
# TODO The following is a short example of how to use the StarterKit
|
# TODO The following is a short example of how to use the StarterKit
|
||||||
@ -70,7 +68,7 @@ def take_turn():
|
|||||||
print("Error: " + error)
|
print("Error: " + error)
|
||||||
|
|
||||||
# pre-made test strategy which came with starter kit
|
# pre-made test strategy which came with starter kit
|
||||||
if use_prebuilt_strategy:
|
'''
|
||||||
state = game_layer.game_state
|
state = game_layer.game_state
|
||||||
if len(state.residences) < 1:
|
if len(state.residences) < 1:
|
||||||
for i in range(len(state.map)):
|
for i in range(len(state.map)):
|
||||||
@ -106,55 +104,55 @@ def take_turn():
|
|||||||
print(message)
|
print(message)
|
||||||
for error in game_layer.game_state.errors:
|
for error in game_layer.game_state.errors:
|
||||||
print("Error: " + error)
|
print("Error: " + error)
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
def develop_society():
|
def develop_society():
|
||||||
global state, queue_timeout, available_tiles
|
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
|
upgrade_residence_score = 0
|
||||||
build_utility_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:
|
if len(state.residences) < 2:
|
||||||
build("Apartments")
|
build("Apartments")
|
||||||
elif len(state.utilities) < 1:
|
elif decision == "build_utility":
|
||||||
build("WindTurbine")
|
build("WindTurbine")
|
||||||
elif state.funds > 30000 and len(state.residences) < 4:
|
elif decision == "build_residence": # build if queue full and can afford housing
|
||||||
build("HighRise")
|
|
||||||
elif queue_is_full: # build if queue full and can afford housing
|
|
||||||
build("ModernApartments")
|
build("ModernApartments")
|
||||||
elif build_upgrade_score:
|
elif decision == "build_upgrade":
|
||||||
# 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)
|
# game_layer.buy_upgrade((the_only_residence.X, the_only_residence.Y), state.available_upgrades[0].name)
|
||||||
pass
|
game_layer.wait()
|
||||||
else:
|
else:
|
||||||
game_layer.wait()
|
game_layer.wait()
|
||||||
|
|
||||||
|
|
||||||
def something_needs_attention():
|
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
|
# check if temp needs adjusting
|
||||||
edit_temp = (False, 0)
|
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
|
# check if need for maintenance
|
||||||
maintain = (False, 0)
|
maintain = (False, 0)
|
||||||
for i in range(len(state.residences)):
|
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)
|
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
|
if maintain[0]: # check maintenance
|
||||||
game_layer.maintenance((state.residences[maintain[1]].X, state.residences[maintain[1]].Y))
|
game_layer.maintenance((state.residences[maintain[1]].X, state.residences[maintain[1]].Y))
|
||||||
|
Reference in New Issue
Block a user