Skip to content
Snippets Groups Projects
Commit f7915062 authored by stephanebonnevay's avatar stephanebonnevay
Browse files

Match Pennies

parent 4941c86f
No related branches found
No related tags found
No related merge requests found
File moved
...@@ -15,7 +15,7 @@ from autogen_ext.models.openai import OpenAIChatCompletionClient ...@@ -15,7 +15,7 @@ from autogen_ext.models.openai import OpenAIChatCompletionClient
# Load API keys from environment variables # Load API keys from environment variables
################### ###################
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
OPENAI_API_KEY = "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" OPENAI_API_KEY = "cle"
################### ###################
PAGODA_API_KEY = os.getenv("PAGODA_API_KEY") PAGODA_API_KEY = os.getenv("PAGODA_API_KEY")
PAGODA_API_KEY = "cle" PAGODA_API_KEY = "cle"
...@@ -24,7 +24,7 @@ if not OPENAI_API_KEY: ...@@ -24,7 +24,7 @@ if not OPENAI_API_KEY:
if not PAGODA_API_KEY: if not PAGODA_API_KEY:
raise ValueError("Missing PAGODA_API_KEY. Set it as an environment variable.") raise ValueError("Missing PAGODA_API_KEY. Set it as an environment variable.")
CSV_FILE_PATH = "../../data/mp/mp.csv" CSV_FILE_PATH = "../../data/mp/mp_.csv"
# Define the expected response format as a Pydantic model # Define the expected response format as a Pydantic model
class AgentResponse(BaseModel): class AgentResponse(BaseModel):
...@@ -201,14 +201,60 @@ class MP: ...@@ -201,14 +201,60 @@ class MP:
def apply_strategy(self): def apply_strategy(self):
"""Play the next move using a heuristic.""" """Play the next move using a heuristic."""
opponent_move = self.opponent_strategy_fn(self.history) prediction = ""
# Default: at random print(self.model)
move = random.choice(["Head", "Tail"])
reasoning = "Choosing randomly." 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"]
# If no rounds played, start with "Head"
if not self.history:
move = "Head"
prediction = "Tail" if self.prediction else "None"
reasoning = (
"First round, no history. Starting with 'Head'. "
+ (f"Predicting opponent starts with 'Tail' (alternating)." if self.prediction else "")
)
return move, prediction, reasoning
# Get last move you played and the opponent's last move
last_agent_move = self.history[-1]["Agent Move"]
last_opponent_move = self.history[-1]["Opponent Move"]
# Alternate your move from last time
move = "Tail" if last_agent_move == "Head" else "Head"
# Prediction: Suppose opponent is also alternating
if self.prediction:
prediction = "Tail" if last_opponent_move == "Head" else "Head"
else:
prediction = "None"
reasoning = (
f"Last round I played {last_agent_move}, opponent played {last_opponent_move}. "
f"I'm alternating my move to '{move}'. "
+ (
f"Predicting opponent will alternate to '{prediction}'."
if self.prediction else "No prediction mode."
)
)
return move, prediction, reasoning
outcome = self.determine_winner(move, opponent_move) else:
self.update_score(outcome) # Use the correct outcome here opponent_move = self.opponent_strategy_fn(self.history)
return move, reasoning # Default: at random
move = random.choice(["Head", "Tail"])
reasoning = "Choosing randomly."
outcome = self.determine_winner(move, opponent_move)
self.update_score(outcome) # Use the correct outcome here
return move, prediction, reasoning
@staticmethod @staticmethod
def determine_winner(player_move: str, opponent_move: str) -> int: def determine_winner(player_move: str, opponent_move: str) -> int:
...@@ -243,12 +289,12 @@ class MP: ...@@ -243,12 +289,12 @@ class MP:
# Runner # Runner
async def main(): async def main():
game = MP( game = MP(
model="qwen3", # "gpt-4.5-preview-2025-02-27", "qwen3", "llama3", "llama3.3", "mixtral", "mistral-small", "deepseek-r1" model="gpt-4.5-preview-2025-02-27", # "gpt-4.5-preview-2025-02-27", "qwen3", "llama3", "llama3.3", "mixtral", "mistral-small", "deepseek-r1"
temperature=0.7, temperature=0.7,
game_id=1, game_id=1,
prediction=True, prediction=True,
opponent_strategy_fn=lambda history: "Tail", opponent_strategy_fn=lambda history: "Tail" if len(history) % 2 == 0 else "Head",
strategy=False # or True for rule-based strategy=True # or True for rule-based
) )
num_rounds = 10 num_rounds = 10
for round_id in range(1, num_rounds + 1): for round_id in range(1, num_rounds + 1):
......
...@@ -4,7 +4,7 @@ import matplotlib.pyplot as plt ...@@ -4,7 +4,7 @@ import matplotlib.pyplot as plt
import numpy as np import numpy as np
# Path to the CSV file # Path to the CSV file
CSV_FILE_PATH = "../../data/mp/mp.csv" CSV_FILE_PATH = "../../data/mp/mp_.csv"
FIGURE_DIR = "../../figures/mp" FIGURE_DIR = "../../figures/mp"
os.makedirs(FIGURE_DIR, exist_ok=True) os.makedirs(FIGURE_DIR, exist_ok=True)
......
...@@ -7,7 +7,7 @@ from http.cookiejar import debug ...@@ -7,7 +7,7 @@ from http.cookiejar import debug
from mp import MP from mp import MP
from typing import Callable from typing import Callable
CSV_FILE_PATH = "../../data/mp/mp.csv" CSV_FILE_PATH = "../../data/mp/mp_.csv"
class MPExperiment: class MPExperiment:
def __init__(self): def __init__(self):
......
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