mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-02 14:45:17 +02:00
add guard
This commit is contained in:
parent
0221028de2
commit
02cc5c274d
2 changed files with 14 additions and 11 deletions
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue