|
1 | 1 |
|
2 | | -from typing import List, Optional |
| 2 | +from typing import List |
3 | 3 | from among_them.models.player import Player |
4 | 4 | from among_them.game_config import GameConfig |
5 | 5 | from among_them.models.history import History |
|
9 | 9 | from among_them.models.action_type import ActionType |
10 | 10 | from among_them.models.phase import GamePhase |
11 | 11 | from among_them.models.tasks import get_impostor_tasks, get_crewmate_tasks |
12 | | -from among_them.utils.player_utils import get_players_in_room, get_last_player_action |
13 | 12 |
|
14 | 13 | def initialize_history(players: List[Player], game_config: GameConfig) -> List[History]: |
15 | 14 | """Create first history entry – a system message that the game started (TASK phase).""" |
@@ -72,94 +71,3 @@ def create_system_message( |
72 | 71 | votes_before_this_discussion_message={}, |
73 | 72 | alive_player_names=alive_player_names.copy(), |
74 | 73 | ) |
75 | | - |
76 | | -def get_action_history_str(history: List[History], players: List[Player], player: Player, game_config: GameConfig, phase: Optional[GamePhase] = None) -> str: |
77 | | - """ |
78 | | - DEPRECATED: see prompt_utils.py |
79 | | - Returns all actions seen by agent and actions that agent saw/spectated in history in order. |
80 | | - """ |
81 | | - phase = history[-1].phase |
82 | | - players_in_room = get_players_in_room(history, players, player) |
83 | | - alive_players = [p for p in players if p.name in history[-1].alive_player_names] |
84 | | - location = get_last_player_action(history, player).location |
85 | | - |
86 | | - # Agent description |
87 | | - history_str = "<player_info>\n" |
88 | | - history_str += f"<player_name>{player.name}</player_name>\n<current_role>{player.role.value}</current_role>\n<current_location>{location.value}</current_location>\n" |
89 | | - other_impostors = [p for p in alive_players if p.role == PlayerRole.IMPOSTOR and p.name != player.name] |
90 | | - if player.role == PlayerRole.IMPOSTOR: |
91 | | - other_crewmates = [p for p in alive_players if p.role == PlayerRole.CREWMATE and p.name != player.name] |
92 | | - if other_impostors: |
93 | | - history_str += "<other_impostors>\n" |
94 | | - for imp in other_impostors: |
95 | | - history_str += f"<impostor>{imp.name}</impostor>\n" |
96 | | - history_str += "</other_impostors>\n" |
97 | | - else: |
98 | | - history_str += "<other_impostors>none</other_impostors>\n" |
99 | | - |
100 | | - if other_crewmates: |
101 | | - history_str += "<crewmates>\n" |
102 | | - for crew in other_crewmates: |
103 | | - history_str += f"<crewmate>{crew.name}</crewmate>\n" |
104 | | - history_str += "</crewmates>\n" |
105 | | - else: |
106 | | - other_players = [p.name for p in alive_players if p.name != player.name] |
107 | | - history_str += f"<impostor_count>{len(other_impostors)}</impostor_count>\n" |
108 | | - history_str += "<potential_impostors>\n" |
109 | | - for other_player in other_players: |
110 | | - history_str += f"<player>{other_player}</player>\n" |
111 | | - history_str += "</potential_impostors>\n" |
112 | | - |
113 | | - # Tasks left |
114 | | - tasks_left = [] |
115 | | - for h in history: |
116 | | - if player.name in h.tasks_left_to_do: |
117 | | - tasks_left = h.tasks_left_to_do[player.name] |
118 | | - break |
119 | | - |
120 | | - if tasks_left: |
121 | | - history_str += "<tasks_left>\n" |
122 | | - for task in tasks_left: |
123 | | - history_str += f"<task><name>{task.name}</name><location>{task.location.value if task.location else 'N/A'}</location></task>\n" |
124 | | - history_str += "</tasks_left>\n" |
125 | | - history_str += "</player_info>\n\n" |
126 | | - |
127 | | - # Game history |
128 | | - history_str += "<game_history>\n" |
129 | | - for h in history: |
130 | | - if h.action_taken: |
131 | | - if h.action_taken.player_name == player.name: |
132 | | - if hasattr(h, 'llm_cot') and h.llm_cot: |
133 | | - cot_without_think_tags = h.llm_cot.replace("<think>", "<thought>").replace("</think>", "</thought>") |
134 | | - history_str += f"<player_thought>{cot_without_think_tags}</player_thought>\n" |
135 | | - if h.action_taken.type == ActionType.SPEAK: |
136 | | - history_str += f"<action type=\"player_message\">{h.action_taken.agent_perspective}</action>\n" |
137 | | - else: |
138 | | - history_str += f"<action type=\"player_action\">{h.action_taken.agent_perspective}</action>\n" |
139 | | - elif player.name in h.spectators_who_saw: |
140 | | - if h.action_taken.type == ActionType.SPEAK: |
141 | | - history_str += f"<action type=\"discussion\">{h.action_taken.observer_perspective}</action>\n" |
142 | | - elif h.action_taken.type != ActionType.VOTE: # players cannot see others voting |
143 | | - history_str += f"<action type=\"observed\">{h.action_taken.observer_perspective}</action>\n" |
144 | | - history_str += "</game_history>\n\n" |
145 | | - |
146 | | - # Current game state |
147 | | - history_str += "<current_state>\n" |
148 | | - other_players = [p.name for p in players_in_room if p.name != player.name] |
149 | | - if phase == GamePhase.TASKS: |
150 | | - if len(other_players) == 0: |
151 | | - history_str += "<companions>none</companions>\n" |
152 | | - history_str += f"<location>{location.value}</location>\n" |
153 | | - else: |
154 | | - history_str += "<companions>\n" |
155 | | - for other_player in other_players: |
156 | | - history_str += f"<player>{other_player}</player>\n" |
157 | | - history_str += "</companions>\n" |
158 | | - history_str += f"<location>{location.value}</location>\n" |
159 | | - history_str += "<phase>Task</phase>\n<note>You cannot speak during this phase.</note>\n" |
160 | | - elif phase == GamePhase.VOTING: |
161 | | - history_str += "<phase>Voting</phase>\n" |
162 | | - else: |
163 | | - history_str += "<phase>Discussion</phase>\n<note>You can speak now. Respond to the crewmates.</note>\n" |
164 | | - history_str += "</current_state>\n" |
165 | | - return history_str |
0 commit comments