X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=server%2Fai.py;h=f9455f5bbe16d9994db1cdec53a431163d66afa8;hb=5bbcda8ee4e25d43627e94b534f72a12da95e66e;hp=db40625659d00878ef866e467d6973c09ee563e7;hpb=2f7c446f698dbcf510a4997e1689e3a2df3e24be;p=plomrogue diff --git a/server/ai.py b/server/ai.py index db40625..f9455f5 100644 --- a/server/ai.py +++ b/server/ai.py @@ -23,7 +23,8 @@ def get_dir_to_target(t, filter): "c": Thing in memorized map is consumable of sufficient nutrition for t "s": memory map cell with greatest-reachable degree of unexploredness """ - from server.utils import rand, libpr, c_pointer_to_bytearray + from server.utils import rand, libpr, c_pointer_to_bytearray, \ + c_pointer_to_string from server.config.world_data import symbols_passable tt = world_db["ThingTypes"][t["T_TYPE"]] @@ -64,8 +65,7 @@ def get_dir_to_target(t, filter): return False def good_flee_target(m): - own_corpse_id = world_db["ThingTypes"][t["T_TYPE"]]["TT_CORPSE_ID"] - corpse_type = world_db["ThingTypes"][own_corpse_id] + corpse_type = world_db["ThingTypes"][tt["TT_CORPSE_ID"]] targetness = 0 if corpse_type["TT_TOOL"] != "food" \ else corpse_type["TT_TOOLPOWER"] type = world_db["ThingTypes"][m["T_TYPE"]] @@ -105,9 +105,10 @@ def get_dir_to_target(t, filter): # for i in [i for i in range(world_db["MAP_LENGTH"] ** 2) # if memmap[i] in symbols_passable]: # set_map_score(i, 65534) # i.e. 65535-1 - map = c_pointer_to_bytearray(t["T_MEMMAP"]) - if libpr.set_cells_passable_on_memmap_to_65534_on_scoremap(map, - symbols_passable): + scoremap = c_pointer_to_bytearray(t["T_MEMMAP"]) + passable_string = c_pointer_to_string(symbols_passable) + if libpr.set_cells_passable_on_memmap_to_65534_on_scoremap(scoremap, + passable_string): raise RuntimeError("No score map allocated for set_cells_passable" "_on_memmap_to_65534_on_scoremap().") @@ -165,19 +166,18 @@ def get_dir_to_target(t, filter): import math dir_to_target = False dirs = "edcxsw" - eye_pos = t["pos"] - neighbors = get_neighbor_scores(dirs, eye_pos) + neighbors = get_neighbor_scores(dirs, t["pos"]) minmax_start = 0 if "f" == filter else 65535 - 1 minmax_neighbor = minmax_start for i in range(len(dirs)): - if ("f" == filter and get_map_score(eye_pos) < neighbors[i] and + if ("f" == filter and get_map_score(t["pos"]) < neighbors[i] and minmax_neighbor < neighbors[i] and 65535 != neighbors[i]) \ or ("f" != filter and minmax_neighbor > neighbors[i]): minmax_neighbor = neighbors[i] if minmax_neighbor != minmax_start: dir_to_target = rand_target_dir(neighbors, minmax_neighbor, dirs) if "f" == filter: - distance = get_map_score(eye_pos) + distance = get_map_score(t["pos"]) fear_distance = world_db["MAP_LENGTH"] if t["T_SATIATION"] < 0 and math.sqrt(-t["T_SATIATION"]) > 0: fear_distance = fear_distance / math.sqrt(-t["T_SATIATION"])