Eric Botti
commited on
Commit
·
485a836
1
Parent(s):
72e4e68
fixed chameleon not seeing all players responses
Browse files- src/game.py +5 -8
- src/prompts.py +13 -6
src/game.py
CHANGED
@@ -4,7 +4,7 @@ from game_utils import *
|
|
4 |
from models import *
|
5 |
from player import Player
|
6 |
from parser import ParserKani
|
7 |
-
from prompts import fetch_prompt
|
8 |
|
9 |
# Default Values
|
10 |
NUMBER_OF_PLAYERS = 5
|
@@ -88,11 +88,9 @@ class Game:
|
|
88 |
# Phase I: Collect Player Animal Descriptions
|
89 |
for player in self.players:
|
90 |
if player.role == "chameleon":
|
91 |
-
|
92 |
-
prompt = prompt_template.format(player_responses=self.format_responses())
|
93 |
else:
|
94 |
-
|
95 |
-
prompt = prompt_template.format(animal=herd_animal, player_responses=self.format_responses())
|
96 |
|
97 |
# Get Player Animal Description
|
98 |
response = await player.respond_to(prompt)
|
@@ -102,7 +100,7 @@ class Game:
|
|
102 |
self.player_responses.append({"sender": player.name, "response": output.description})
|
103 |
|
104 |
# Phase II: Chameleon Decides if they want to guess the animal (secretly)
|
105 |
-
prompt =
|
106 |
|
107 |
response = await self.players[self.chameleon_index].respond_to(prompt)
|
108 |
output = await self.parser.parse(prompt, response, ChameleonGuessDecisionModel)
|
@@ -129,8 +127,7 @@ class Game:
|
|
129 |
# All Players Vote for Chameleon
|
130 |
player_votes = []
|
131 |
for player in self.players:
|
132 |
-
|
133 |
-
prompt = prompt_template.format(player_responses=self.format_responses())
|
134 |
|
135 |
# Get Player Vote
|
136 |
response = await player.respond_to(prompt)
|
|
|
4 |
from models import *
|
5 |
from player import Player
|
6 |
from parser import ParserKani
|
7 |
+
from prompts import fetch_prompt, format_prompt
|
8 |
|
9 |
# Default Values
|
10 |
NUMBER_OF_PLAYERS = 5
|
|
|
88 |
# Phase I: Collect Player Animal Descriptions
|
89 |
for player in self.players:
|
90 |
if player.role == "chameleon":
|
91 |
+
prompt = format_prompt("chameleon_animal", player_responses=self.format_responses())
|
|
|
92 |
else:
|
93 |
+
prompt = format_prompt("herd_animal", animal=herd_animal, player_responses=self.format_responses())
|
|
|
94 |
|
95 |
# Get Player Animal Description
|
96 |
response = await player.respond_to(prompt)
|
|
|
100 |
self.player_responses.append({"sender": player.name, "response": output.description})
|
101 |
|
102 |
# Phase II: Chameleon Decides if they want to guess the animal (secretly)
|
103 |
+
prompt = format_prompt("chameleon_guess_decision", player_responses=self.format_responses())
|
104 |
|
105 |
response = await self.players[self.chameleon_index].respond_to(prompt)
|
106 |
output = await self.parser.parse(prompt, response, ChameleonGuessDecisionModel)
|
|
|
127 |
# All Players Vote for Chameleon
|
128 |
player_votes = []
|
129 |
for player in self.players:
|
130 |
+
prompt = format_prompt("vote", player_responses=self.format_responses())
|
|
|
131 |
|
132 |
# Get Player Vote
|
133 |
response = await player.respond_to(prompt)
|
src/prompts.py
CHANGED
@@ -1,8 +1,11 @@
|
|
1 |
-
|
2 |
-
|
3 |
def fetch_prompt(prompt_name):
|
|
|
4 |
return prompts[prompt_name]
|
5 |
|
|
|
|
|
|
|
|
|
6 |
|
7 |
_game_rules = '''\
|
8 |
GAME RULES: You are playing a social deduction game where every player pretends the be the same animal.
|
@@ -30,6 +33,11 @@ Previously Mentioned Descriptions:
|
|
30 |
{player_responses}
|
31 |
"""
|
32 |
|
|
|
|
|
|
|
|
|
|
|
33 |
_chameleon_guess_decision = """\
|
34 |
You now have the opportunity to guess what animal the other players are pretending to be.
|
35 |
If you guess correctly you will WIN, if you guess incorrectly you will LOSE.
|
@@ -41,15 +49,14 @@ What animal do you think the other players are pretending to be?
|
|
41 |
"""
|
42 |
|
43 |
_vote_prompt = """\
|
44 |
-
|
45 |
-
{player_responses}
|
46 |
"""
|
47 |
|
48 |
prompts = {
|
49 |
"herd_animal": _game_rules + _herd_animal,
|
50 |
"chameleon_animal": _game_rules + _chameleon_animal,
|
51 |
-
"chameleon_guess_decision": _chameleon_guess_decision,
|
52 |
"chameleon_guess_animal": _chameleon_guess_animal,
|
53 |
-
"vote": _vote_prompt
|
54 |
}
|
55 |
|
|
|
|
|
|
|
1 |
def fetch_prompt(prompt_name):
|
2 |
+
"""Fetches a static prompt."""
|
3 |
return prompts[prompt_name]
|
4 |
|
5 |
+
def format_prompt(prompt_name, **kwargs):
|
6 |
+
"""Fetches a template prompt and populates it."""
|
7 |
+
return fetch_prompt(prompt_name).format(**kwargs)
|
8 |
+
|
9 |
|
10 |
_game_rules = '''\
|
11 |
GAME RULES: You are playing a social deduction game where every player pretends the be the same animal.
|
|
|
33 |
{player_responses}
|
34 |
"""
|
35 |
|
36 |
+
_all_responses = """\
|
37 |
+
Below are the responses from all the other players.
|
38 |
+
{player_responses}
|
39 |
+
"""
|
40 |
+
|
41 |
_chameleon_guess_decision = """\
|
42 |
You now have the opportunity to guess what animal the other players are pretending to be.
|
43 |
If you guess correctly you will WIN, if you guess incorrectly you will LOSE.
|
|
|
49 |
"""
|
50 |
|
51 |
_vote_prompt = """\
|
52 |
+
Now it is time to vote. Choose from the players above who you think the Chameleon is.
|
|
|
53 |
"""
|
54 |
|
55 |
prompts = {
|
56 |
"herd_animal": _game_rules + _herd_animal,
|
57 |
"chameleon_animal": _game_rules + _chameleon_animal,
|
58 |
+
"chameleon_guess_decision": _all_responses + _chameleon_guess_decision,
|
59 |
"chameleon_guess_animal": _chameleon_guess_animal,
|
60 |
+
"vote": _all_responses + _vote_prompt
|
61 |
}
|
62 |
|