fix: Werewolf Game

- As all the roles in werewolf game as `react_mode` =
  `RoleReactMode.REACT`, so `role._react()` will be called everytime.
- When not returning anything from `role._think()` => Therefore,
  `role._act()` will not be executed.
- Due to which this issue was comming: https://github.com/geekan/MetaGPT/issues/1313
This commit is contained in:
Kaushal_26 2024-06-02 22:25:04 +05:30
parent bc1cd11a4b
commit 84a240ac8d
4 changed files with 4 additions and 0 deletions

View file

@ -86,6 +86,7 @@ class BasePlayer(Role):
# FIXME: hard code to split, restricted为"Moderator"或"Moderator, 角色profile"
# Moderator加密发给自己的意味着要执行角色的特殊动作
self.rc.todo = self.special_actions[0]()
return self.rc.todo is not None
async def _act(self):
# todo为_think时确定的有两种情况Speak或Protect

View file

@ -171,6 +171,7 @@ class Moderator(BasePlayer):
else:
# 上一轮消息是游戏角色的发言,解析角色的发言
self.rc.todo = ParseSpeak()
return self.rc.todo is not None
def _init_fields_from_obj(self, obs: dict[str, Union[int, str, list[str]]]):
self.game_setup = obs.get("game_setup", "")

View file

@ -13,3 +13,4 @@ class Werewolf(BasePlayer):
await super()._think()
if isinstance(self.rc.todo, Speak):
self.rc.todo = Impersonate()
return self.rc.todo is not None

View file

@ -26,3 +26,4 @@ class Witch(BasePlayer):
self.rc.todo = Poison()
else:
raise ValueError("Moderator's instructions must include save or poison keyword")
return self.rc.todo is not None