decision engine rework
This commit is contained in:
parent
8309d2938c
commit
2cda0a08b7
61
main.py
61
main.py
@ -118,31 +118,48 @@ def develop_society():
|
|||||||
|
|
||||||
# priority scores, 1 = very urgent, 0 = not urgent at all
|
# priority scores, 1 = very urgent, 0 = not urgent at all
|
||||||
# queue modifier * funds modifier * existing houses modifier
|
# 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
|
upgrade_residence_score = 0
|
||||||
build_utility_score = (len(state.residences) / (len(available_tiles)-utilities)) * (1 - len(state.utilities) / utilities)
|
# existing houses modifier * funds modifier * existing utilities modifier
|
||||||
build_upgrade_score = (1 - state.turn/700) * (2 - 15000/state.funds)
|
build_utility_score = (len(state.residences) / (len(available_tiles)-utilities)) * (1 - (16000 / state.funds)) * (1 - (len(state.utilities) / utilities))
|
||||||
|
# turn modifier * funds modifier
|
||||||
actions = {
|
build_upgrade_score = (1 - (state.turn / 700)) * (2 - (15000 / state.funds))
|
||||||
'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) < 1:
|
if len(state.residences) < 1:
|
||||||
return build("Apartments")
|
build_residence_score = 100
|
||||||
elif decision == "build_utility":
|
|
||||||
return build("WindTurbine")
|
decision = [
|
||||||
elif decision == "build_residence": # build if queue full and can afford housing
|
('build_residence', build_residence_score),
|
||||||
return build("ModernApartments")
|
('upgrade_residence', upgrade_residence_score),
|
||||||
elif decision == "build_upgrade":
|
('build_utility', build_utility_score),
|
||||||
for i in range(5):
|
('build_upgrade', build_upgrade_score)
|
||||||
for residence in state.residences:
|
]
|
||||||
if state.available_upgrades[i].name not in residence.effects:
|
def sort_key(e):
|
||||||
game_layer.buy_upgrade((residence.X, residence.Y), state.available_upgrades[i].name)
|
return e[1]
|
||||||
return True
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user