Skip to content
Snippets Groups Projects
Commit f8b59471 authored by Maxime Morge's avatar Maxime Morge :construction_worker:
Browse files

PyGAAMAS: Strategies generated by models fo MP

parent 89f2754b
No related branches found
No related tags found
No related merge requests found
...@@ -203,15 +203,8 @@ class MP: ...@@ -203,15 +203,8 @@ class MP:
"""Play the next move using a heuristic.""" """Play the next move using a heuristic."""
prediction = "" prediction = ""
print(self.model) print(self.model)
if self.model == "gpt-4.5-preview-2025-02-27": if self.model == "gpt-4.5-preview-2025-02-27":
"""
Play the next move using a heuristic.
- Simple strategy: Alternate between "Head" and "Tail".
- Prediction: Assume opponent is also alternating.
"""
moves = ["Head", "Tail"] moves = ["Head", "Tail"]
# If no rounds played, start with "Head" # If no rounds played, start with "Head"
if not self.history: if not self.history:
move = "Head" move = "Head"
...@@ -221,20 +214,16 @@ class MP: ...@@ -221,20 +214,16 @@ class MP:
+ (f"Predicting opponent starts with 'Tail' (alternating)." if self.prediction else "") + (f"Predicting opponent starts with 'Tail' (alternating)." if self.prediction else "")
) )
return move, prediction, reasoning return move, prediction, reasoning
# Get last move you played and the opponent's last move # Get last move you played and the opponent's last move
last_agent_move = self.history[-1]["Agent Move"] last_agent_move = self.history[-1]["Agent Move"]
last_opponent_move = self.history[-1]["Opponent Move"] last_opponent_move = self.history[-1]["Opponent Move"]
# Alternate your move from last time # Alternate your move from last time
move = "Tail" if last_agent_move == "Head" else "Head" move = "Tail" if last_agent_move == "Head" else "Head"
# Prediction: Suppose opponent is also alternating # Prediction: Suppose opponent is also alternating
if self.prediction: if self.prediction:
prediction = "Tail" if last_opponent_move == "Head" else "Head" prediction = "Tail" if last_opponent_move == "Head" else "Head"
else: else:
prediction = "None" prediction = "None"
reasoning = ( reasoning = (
f"Last round I played {last_agent_move}, opponent played {last_opponent_move}. " f"Last round I played {last_agent_move}, opponent played {last_opponent_move}. "
f"I'm alternating my move to '{move}'. " f"I'm alternating my move to '{move}'. "
...@@ -244,6 +233,34 @@ class MP: ...@@ -244,6 +233,34 @@ class MP:
) )
) )
return move, prediction, reasoning return move, prediction, reasoning
if self.model == "mistral-small":
if not self.history:
# If there is no history yet, play randomly.
moves = ["Head", "Tail"]
return random.choice(moves), f"First round, choosing {random.choice(moves)}."
head_count = 0
tail_count = 0
for move in [r['Opponent Move'] for r in self.history]:
if move == 'Head':
head_count += 1
elif move == 'Tail':
tail_count += 1
# If there are more heads, play Tail and vice versa.
if head_count > tail_count:
next_move = "Tail"
elif tail_count > head_count:
next_move = "Head"
else: # Equal counts
moves = ["Head", "Tail"]
next_move = random.choice(moves)
reasoning = f"Opponent's 'Head' count: {head_count}, 'Tail' count: {tail_count}. Chose to play '{next_move}' based on the opponent's move frequency."
return next_move, "None", reasoning
if self.model == "qwen3":
move = random.choice(["Head", "Tail"])
prediction = move # Assume the opponent will match our move
reasoning = f"Choosing randomly. Assuming the opponent will match my move {move}."
return move, prediction, reasoning
return "None", "None", "None"
else: else:
opponent_move = self.opponent_strategy_fn(self.history) opponent_move = self.opponent_strategy_fn(self.history)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment