update ai

This commit is contained in:
bridge
2025-09-12 23:21:00 +08:00
parent 7933f20614
commit 4d1945dd18
4 changed files with 24 additions and 11 deletions

View File

@@ -150,8 +150,13 @@ class Move(DefineAction, ChunkActionMixin):
移动到某个tile
"""
world = self.world
new_x = self.avatar.pos_x + delta_x
new_y = self.avatar.pos_y + delta_y
# 基于境界的移动步长:每轴最多移动 move_step_length 格
step = getattr(self.avatar, "move_step_length", 1)
clamped_dx = max(-step, min(step, delta_x))
clamped_dy = max(-step, min(step, delta_y))
new_x = self.avatar.pos_x + clamped_dx
new_y = self.avatar.pos_y + clamped_dy
# 边界检查:越界则不移动
if world.map.is_in_bounds(new_x, new_y):
@@ -180,9 +185,10 @@ class MoveToRegion(DefineAction, ActualActionMixin):
region_center_loc = region.center_loc
delta_x = region_center_loc[0] - cur_loc[0]
delta_y = region_center_loc[1] - cur_loc[1]
# 横纵向一次最多移动格(可以同时横纵移动)
delta_x = max(-1, min(1, delta_x))
delta_y = max(-1, min(1, delta_y))
# 横纵向一次最多移动 move_step_length 格(可以同时横纵移动)
step = getattr(self.avatar, "move_step_length", 1)
delta_x = max(-step, min(step, delta_x))
delta_y = max(-step, min(step, delta_y))
Move(self.avatar, self.world).execute(delta_x, delta_y)
def is_finished(self, region: Region|str) -> bool:

View File

@@ -114,7 +114,7 @@ class LLMAI(AI):
异步决策逻辑通过LLM决定执行什么动作和参数
"""
global_info = world.get_info()
avatar_infos = {avatar.id: avatar.get_prompt() for avatar in avatars_to_decide}
avatar_infos = {avatar.name: avatar.get_prompt() for avatar in avatars_to_decide}
info = {
"avatar_infos": avatar_infos,
"global_info": global_info,
@@ -122,9 +122,9 @@ class LLMAI(AI):
res = await get_ai_prompt_and_call_llm_async(info)
results: dict[Avatar, tuple[ACTION_NAME, ACTION_PARAMS, str]] = {}
for avatar in avatars_to_decide:
action_name = res[avatar.id]["action_name"]
action_params = res[avatar.id]["action_params"]
avatar_thinking = res[avatar.id]["avatar_thinking"]
action_name = res[avatar.name]["action_name"]
action_params = res[avatar.name]["action_params"]
avatar_thinking = res[avatar.name]["avatar_thinking"]
results[avatar] = (action_name, action_params, avatar_thinking)
return results

View File

@@ -297,6 +297,13 @@ class Avatar:
return f"{info}\n其个性为:{persona}\n{magic_stone_info}\n{items_info}\n决策时需参考这个角色的个性。\n该角色的动作空间及其参数为:{action_space}"
@property
def move_step_length(self) -> int:
"""
获取角色的移动步长
"""
return int(self.cultivation_progress.realm.value)
def get_new_avatar_from_ordinary(world: World, current_month_stamp: MonthStamp, name: str, age: Age):
"""
从凡人中来的新修士

View File

@@ -1,12 +1,12 @@
你是一个决策者这是一个修仙的仙侠世界你负责来决定一些NPC的下一步行为。
{global_info}
你需要进行决策的NPC的dict[AvatarId, info]为
你需要进行决策的NPC的dict[AvatarName, info]为
{avatar_infos}
注意只返回json格式的结果。
分Avatar进行返回格式为
{{
AvatarId: {{
AvatarName: {{
"thinking": ..., // 简单思考应该怎么决策
"action_name": ...,
"action_params": ...,