Skip to content

Commit

Permalink
Improve werewolf game (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
qbc2016 authored Jan 25, 2024
1 parent fd326e3 commit 619b4a9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/werewolf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ More details please refer to the code of [`DictDialogAgent`](../..
with msghub(wolves, announcement=hint) as hub:
for _ in range(MAX_WEREWOLF_DISCUSSION_ROUND):
x = sequentialpipeline(wolves)
if x.agreement:
if x.get("agreement", False):
break
# ...
```
7 changes: 4 additions & 3 deletions examples/werewolf/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Prompts:
to_wolves = (
"{}, you are werewolves. If you are alone, eliminate a player, else "
"discuss with your teammates and reach an agreement. Response in the "
"following format which can be loaded by python json.loads()"
"following format which can be loaded by python json.loads()\n"
"{{\n"
' "thought": "thought",\n'
' "speak": "thoughts summary to say to others",\n'
Expand All @@ -35,7 +35,7 @@ class Prompts:
"{{\n"
' "thought": "thought",\n'
' "speak": "thoughts summary to say",\n'
' "resurrect": "true/false"\n'
' "resurrect": true/false\n'
"}}"
)

Expand All @@ -44,7 +44,8 @@ class Prompts:
"json format which can be loaded by python json.loads()\n"
"{{\n"
' "thought": "thought", \n'
' "speak": "False or player_name"\n'
' "speak": "thoughts summary to say",\n'
' "eliminate": ture/false\n'
"}}"
)

Expand Down
6 changes: 3 additions & 3 deletions examples/werewolf/werewolf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
with msghub(wolves, announcement=hint) as hub:
for _ in range(MAX_WEREWOLF_DISCUSSION_ROUND):
x = sequentialpipeline(wolves)
if x.agreement:
if x.get("agreement", False):
break

# werewolves vote
Expand All @@ -56,14 +56,14 @@
{"witch_name": witch.name, "dead_name": dead_player[0]},
),
)
if witch(hint).resurrect:
if witch(hint).get("resurrect", False):
healing_used_tonight = True
dead_player.pop()
healing = False

if poison and not healing_used_tonight:
x = witch(HostMsg(content=Prompts.to_witch_poison))
if "False" not in x.content:
if x.get("eliminate", False):
dead_player.append(extract_name_and_id(x.content)[0])
poison = False

Expand Down

0 comments on commit 619b4a9

Please sign in to comment.