add guard

This commit is contained in:
kevin-meng 2023-09-25 00:26:33 +08:00
parent 0221028de2
commit 02cc5c274d
2 changed files with 14 additions and 11 deletions

View file

@ -5,9 +5,10 @@ class Protect(Action):
PROMPT_TEMPLATE = """
It's a werewolf game and you are a guard,
you can choose to protect a player, including yourself, then the protected player will not be killed by the Werewolves this night.
this is game history:
{context}.
Attention: you can not protect the same player in a row.
Attention: you can not protect the same player two nights in a row.
Now, choose one to portect, you will:
"""
@ -21,4 +22,4 @@ class Protect(Action):
rsp = await self._aask(prompt)
# rsp = "Protect Player 1"
return rsp
return rsp

View file

@ -1,21 +1,21 @@
from examples.werewolf_game.roles.base_player import BasePlayer
from examples.werewolf_game.actions import Speak, Hunt
from examples.werewolf_game.actions import Speak, Protect
from metagpt.schema import Message
from metagpt.logs import logger
class Werewolf(BasePlayer):
class Guard(BasePlayer):
def __init__(
self,
name: str = "",
profile: str = "Werewolf",
team: str = "werewolves",
special_action_names: list[str] = ["Hunt"],
profile: str = "Guard",
team: str = "good guys",
special_action_names: list[str] = ["Protect"],
**kwargs,
):
super().__init__(name, profile, team, special_action_names, **kwargs)
async def _act(self):
# todo为_think时确定的有两种情况Speak或Hunt
# todo为_think时确定的有两种情况Speak或Protect
todo = self._rc.todo
logger.info(f"{self._setting}: ready to {str(todo)}")
@ -31,14 +31,16 @@ class Werewolf(BasePlayer):
cause_by=Speak, send_to="", restricted_to="",
)
elif isinstance(todo, Hunt):
elif isinstance(todo, Protect):
rsp = await todo.run(context=memories)
msg = Message(
content=rsp, role=self.profile, sent_from=self.name,
cause_by=Hunt, send_to="",
restricted_to=f"Moderator,{self.profile}", # 给Moderator及狼阵营发送要杀的人的加密消息
cause_by=Protect, send_to="",
restricted_to=f"Moderator,{self.profile}", # 给Moderator发送守卫要保护的人加密消息
)
logger.info(f"{self._setting}: {rsp}")
return msg