home
·
contact
·
privacy
projects
/
plomrogue
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
7843178
)
Better integration of eat cost vs. eat gain in all AI deliberations.
author
Christian Heller
<c.heller@plomlompom.de>
Sat, 14 Mar 2015 12:57:44 +0000
(13:57 +0100)
committer
Christian Heller
<c.heller@plomlompom.de>
Sat, 14 Mar 2015 12:57:44 +0000
(13:57 +0100)
roguelike-server
patch
|
blob
|
history
diff --git
a/roguelike-server
b/roguelike-server
index 2a987fd88961d913844d1a3daa555209a59b80f8..4ace6e9d9bd621b2ea51b05eb3d74e5ff6cbfadf 100755
(executable)
--- a/
roguelike-server
+++ b/
roguelike-server
@@
-549,6
+549,14
@@
def make_map():
altar_placed = True # #
altar_placed = True # #
+def eat_vs_hunger_threshold(thingtype):
+ """Return satiation cost of eating for type. Good food for it must be >."""
+ hunger_unit = hunger_per_turn(thingtype)
+ actiontype = [id for id in world_db["ThingActions"]
+ if world_db["ThingActions"][id]["TA_NAME"] == "use"][0]
+ return world_db["ThingActions"][actiontype]["TA_EFFORT"] * hunger_unit
+
+
def update_map_memory(t, age_map=True):
"""Update t's T_MEMMAP with what's in its FOV now,age its T_MEMMEPTHMAP."""
def update_map_memory(t, age_map=True):
"""Update t's T_MEMMAP with what's in its FOV now,age its T_MEMMEPTHMAP."""
@@
-888,7
+896,7
@@
def actor_pick_up(t):
Define topmostness by how low the thing's type ID is.
"""
# 7DRL: Non-player picking up player-dropped consumable -> GOD_FAVOR gain.
Define topmostness by how low the thing's type ID is.
"""
# 7DRL: Non-player picking up player-dropped consumable -> GOD_FAVOR gain.
- # 7DRL:
Only player picks up non-food
.
+ # 7DRL:
Non-players pick up nothing but food of good value to them
.
used_slots = len(t["T_CARRIES"]) # #
if used_slots < world_db["ThingTypes"][t["T_TYPE"]]["TT_STORAGE"]: # #
ids = [id for id in world_db["Things"] if world_db["Things"][id] != t
used_slots = len(t["T_CARRIES"]) # #
if used_slots < world_db["ThingTypes"][t["T_TYPE"]]["TT_STORAGE"]: # #
ids = [id for id in world_db["Things"] if world_db["Things"][id] != t
@@
-897,12
+905,15
@@
def actor_pick_up(t):
if world_db["Things"][id]["T_POSX"] == t["T_POSX"]]
if len(ids):
lowest_tid = -1
if world_db["Things"][id]["T_POSX"] == t["T_POSX"]]
if len(ids):
lowest_tid = -1
+ eat_cost = eat_vs_hunger_threshold(t["T_TYPE"]) # #
for iid in ids:
tid = world_db["Things"][iid]["T_TYPE"]
if lowest_tid == -1 or tid < lowest_tid:
if (t != world_db["Things"][0] and # #
for iid in ids:
tid = world_db["Things"][iid]["T_TYPE"]
if lowest_tid == -1 or tid < lowest_tid:
if (t != world_db["Things"][0] and # #
- world_db["ThingTypes"][tid]["TT_TOOL"] != "food"):
- continue
+ (world_db["ThingTypes"][tid]["TT_TOOL"] != "food" # #
+ or (world_db["ThingTypes"][tid]["TT_TOOLPOWER"] # #
+ <= eat_cost))): # #
+ continue # #
id = iid
lowest_tid = tid
world_db["Things"][id]["carried"] = True
id = iid
lowest_tid = tid
world_db["Things"][id]["carried"] = True
@@
-1136,10
+1147,13
@@
def get_dir_to_target(t, filter):
t["T_LIFEPOINTS"]):
return True
elif t["T_MEMMAP"] and "c" == filter:
t["T_LIFEPOINTS"]):
return True
elif t["T_MEMMAP"] and "c" == filter:
+ eat_cost = eat_vs_hunger_threshold(t["T_TYPE"])
for mt in t["T_MEMTHING"]:
if ' ' != chr(t["T_MEMMAP"][(mt[1] * world_db["MAP_LENGTH"])
+ mt[2]]) \
for mt in t["T_MEMTHING"]:
if ' ' != chr(t["T_MEMMAP"][(mt[1] * world_db["MAP_LENGTH"])
+ mt[2]]) \
- and world_db["ThingTypes"][mt[0]]["TT_TOOL"] == "food":
+ and world_db["ThingTypes"][mt[0]]["TT_TOOL"] == "food" \
+ and world_db["ThingTypes"][mt[0]]["TT_TOOLPOWER"] \
+ > eat_cost:
return True
return False
return True
return False
@@
-1187,11
+1201,14
@@
def get_dir_to_target(t, filter):
world_db["ThingTypes"][Thing["T_TYPE"]]["TT_LIFEPOINTS"]:
set_map_score(pos, 0)
elif "c" == filter:
world_db["ThingTypes"][Thing["T_TYPE"]]["TT_LIFEPOINTS"]:
set_map_score(pos, 0)
elif "c" == filter:
+ eat_cost = eat_vs_hunger_threshold(t["T_TYPE"])
for mt in [mt for mt in t["T_MEMTHING"]
if ord_blank != t["T_MEMMAP"][mt[1]
* world_db["MAP_LENGTH"]
+ mt[2]]
for mt in [mt for mt in t["T_MEMTHING"]
if ord_blank != t["T_MEMMAP"][mt[1]
* world_db["MAP_LENGTH"]
+ mt[2]]
- if world_db["ThingTypes"][mt[0]]["TT_TOOL"] == "food"]:
+ if world_db["ThingTypes"][mt[0]]["TT_TOOL"] == "food"
+ if world_db["ThingTypes"][mt[0]]["TT_TOOLPOWER"]
+ > eat_cost]:
set_map_score(mt[1] * world_db["MAP_LENGTH"] + mt[2], 0)
elif "s" == filter:
zero_score_map_where_char_on_memdepthmap(mem_depth_c[0])
set_map_score(mt[1] * world_db["MAP_LENGTH"] + mt[2], 0)
elif "s" == filter:
zero_score_map_where_char_on_memdepthmap(mem_depth_c[0])
@@
-1278,13
+1295,16
@@
def get_dir_to_target(t, filter):
def standing_on_food(t):
def standing_on_food(t):
- """Return True/False whether t is standing on a consumable."""
+ """Return True/False whether t is standing on healthy consumable."""
+ eat_cost = eat_vs_hunger_threshold(t["T_TYPE"])
for id in [id for id in world_db["Things"] if world_db["Things"][id] != t
if not world_db["Things"][id]["carried"]
if world_db["Things"][id]["T_POSY"] == t["T_POSY"]
if world_db["Things"][id]["T_POSX"] == t["T_POSX"]
if world_db["ThingTypes"][world_db["Things"][id]["T_TYPE"]]
for id in [id for id in world_db["Things"] if world_db["Things"][id] != t
if not world_db["Things"][id]["carried"]
if world_db["Things"][id]["T_POSY"] == t["T_POSY"]
if world_db["Things"][id]["T_POSX"] == t["T_POSX"]
if world_db["ThingTypes"][world_db["Things"][id]["T_TYPE"]]
- ["TT_TOOL"] == "food"]:
+ ["TT_TOOL"] == "food"
+ if world_db["ThingTypes"][world_db["Things"][id]["T_TYPE"]]
+ ["TT_TOOLPOWER"] > eat_cost]:
return True
return False
return True
return False
@@
-1294,18
+1314,14
@@
def get_inventory_slot_to_consume(t):
cmp_food = -1
selection = -1
i = 0
cmp_food = -1
selection = -1
i = 0
- hunger_u = hunger_per_turn(t["T_TYPE"])
- type = [id for id in world_db["ThingActions"]
- if world_db["ThingActions"][id]["TA_NAME"] == "use"][0]
- consume_hungering = world_db["ThingActions"][type]["TA_EFFORT"] * hunger_u
+ eat_cost = eat_vs_hunger_threshold(t["T_TYPE"])
for id in t["T_CARRIES"]:
type = world_db["Things"][id]["T_TYPE"]
if world_db["ThingTypes"][type]["TT_TOOL"] == "food" \
and world_db["ThingTypes"][type]["TT_TOOLPOWER"]:
nutvalue = world_db["ThingTypes"][type]["TT_TOOLPOWER"]
for id in t["T_CARRIES"]:
type = world_db["Things"][id]["T_TYPE"]
if world_db["ThingTypes"][type]["TT_TOOL"] == "food" \
and world_db["ThingTypes"][type]["TT_TOOLPOWER"]:
nutvalue = world_db["ThingTypes"][type]["TT_TOOLPOWER"]
- tmp_cmp = abs(t["T_SATIATION"] + nutvalue -
consume_hungering
)
+ tmp_cmp = abs(t["T_SATIATION"] + nutvalue -
eat_cost
)
if (cmp_food < 0 and tmp_cmp < abs(t["T_SATIATION"])) \
if (cmp_food < 0 and tmp_cmp < abs(t["T_SATIATION"])) \
- or (cmp_food < 0 and 0 > t["T_SATIATION"] + nutvalue) \
or tmp_cmp < cmp_food:
cmp_food = tmp_cmp
selection = i
or tmp_cmp < cmp_food:
cmp_food = tmp_cmp
selection = i