X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=server%2Fai.py;h=88b087939f5ca2cd49c428f30fe1420b110c36c1;hb=08e48fa62e37ab29b6b7728db0bf78407ff22ba4;hp=ed65fbdfd13fa80a4b53ff9c49cf348a85de2587;hpb=0a56367e8396b2ece4c1bce8a25e93ceabd901c1;p=plomrogue diff --git a/server/ai.py b/server/ai.py index ed65fbd..88b0879 100644 --- a/server/ai.py +++ b/server/ai.py @@ -33,6 +33,7 @@ def get_dir_to_target(t, filter): "s": memory map cell with greatest-reachable degree of unexploredness """ from server.utils import rand, libpr, c_pointer_to_bytearray + from server.config.world_data import symbols_passable def zero_score_map_where_char_on_memdepthmap(c): # OUTSOURCED FOR PERFORMANCE REASONS TO libplomrogue.so: @@ -112,13 +113,13 @@ def get_dir_to_target(t, filter): def set_cells_passable_on_memmap_to_65534_on_scoremap(): # OUTSOURCED FOR PERFORMANCE REASONS TO libplomrogue.so: - # ord_dot = ord(".") # memmap = t["T_MEMMAP"] # for i in [i for i in range(world_db["MAP_LENGTH"] ** 2) - # if ord_dot == memmap[i]]: + # 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): + if libpr.set_cells_passable_on_memmap_to_65534_on_scoremap(map, + symbols_passable): raise RuntimeError("No score map allocated for set_cells_passable" "_on_memmap_to_65534_on_scoremap().") @@ -274,21 +275,26 @@ def ai(t): """Determine next command/argment for actor t via AI algorithms.""" t["T_COMMAND"] = [id for id in world_db["ThingActions"] if world_db["ThingActions"][id]["TA_NAME"] == "wait"][0] - if get_dir_to_target(t, "f"): - return - sel = get_inventory_slot_to_consume(t) - if -1 != sel: - t["T_COMMAND"] = [id for id in world_db["ThingActions"] - if world_db["ThingActions"][id]["TA_NAME"] - == "use"][0] - t["T_ARGUMENT"] = sel - elif standing_on_food(t): + eating = len([id for id in world_db["ThingActions"] + if world_db["ThingActions"][id]["TA_NAME"] == "use"]) > 0 + picking = len([id for id in world_db["ThingActions"] + if world_db["ThingActions"][id]["TA_NAME"] == "pickup"]) > 0 + if eating and picking: + if get_dir_to_target(t, "f"): + return + sel = get_inventory_slot_to_consume(t) + if -1 != sel: t["T_COMMAND"] = [id for id in world_db["ThingActions"] if world_db["ThingActions"][id]["TA_NAME"] - == "pick_up"][0] - else: - going_to_known_food_spot = get_dir_to_target(t, "c") - if not going_to_known_food_spot: - aiming_for_walking_food = get_dir_to_target(t, "a") - if not aiming_for_walking_food: - get_dir_to_target(t, "s") + == "use"][0] + t["T_ARGUMENT"] = sel + elif standing_on_food(t): + t["T_COMMAND"] = [id for id in world_db["ThingActions"] + if world_db["ThingActions"][id]["TA_NAME"] + == "pickup"][0] + else: + going_to_known_food_spot = get_dir_to_target(t, "c") + if not going_to_known_food_spot: + aiming_for_walking_food = get_dir_to_target(t, "a") + if not aiming_for_walking_food: + get_dir_to_target(t, "s")