atropos/environments/dynastai/test_dynastai_env.py
Earl Potters 7101aad190 Add DynastAI integration documentation and setup scripts
- Introduced `ATROPOS_INTEGRATION.md` for detailed instructions on using DynastAI with Atropos.
- Added `INSTALL_AND_RUN.md` to guide users through installation and running the game.
- Created `run_dynastai.py` for a simplified testing experience without full Atropos setup.
- Implemented `setup.py` to manage dependencies and ensure compatibility.
- Updated `requirements.txt` to include additional dependencies and version constraints.
- Enhanced `README.md` with new sections on installation, running the game, and integration with Atropos.
- Added installation verification script `verify_install.py` to check for required packages.
- Updated game logic to support local card generation and improved API integration.
- Enhanced web interface with new features for user interaction and game metrics display.
2025-05-18 21:59:12 +00:00

102 lines
3 KiB
Python
Executable file

#!/usr/bin/env python3
"""
DynastAI Test Script
This script tests the basic functionality of the DynastAI environment:
- Game state initialization
- Card generation
- Choice processing
- Game over conditions
- Reward calculation
"""
import os
import sys
import asyncio
import json
import random
from dotenv import load_dotenv
# Ensure the src directory is in path
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
from src.dynastai_env import DynastAIEnv, DynastAIEnvConfig
from atroposlib.envs.server_handling.server_baseline import ServerBaseline
# Load environment variables
load_dotenv()
async def test_environment():
"""Test the DynastAI environment"""
print("Initializing DynastAI environment...")
# Create config and environment
config = DynastAIEnvConfig()
server_config = ServerBaseline()
env = DynastAIEnv(config, server_config)
# Reset the environment
print("Resetting environment...")
state = await env.reset()
session_id = state["session_id"]
print(f"Session ID: {session_id}")
print(f"Initial metrics: {state['metrics']}")
# Run a simulated game
done = False
total_reward = 0
steps = 0
print("\nStarting simulated game...")
while not done and steps < 20: # Cap at 20 steps to avoid infinite loop
# Generate a card (direct method call for testing)
state["current_card"] = env.game_states[session_id].current_card = env._generate_card_internal(
env.game_states[session_id].get_metrics(),
env.category_weights
)
# Choose a random action
choice = random.choice(["yes", "no"])
action = {"session_id": session_id, "choice": choice}
print(f"\nStep {steps+1}:")
print(f"Card: {state['current_card']['text']}")
print(f"Choice: {choice}")
# Take the action
state, reward, done, info = await env.step(action)
# Print the results
print(f"New metrics: {state['metrics']}")
print(f"Reward: {reward}")
print(f"Done: {done}")
total_reward += reward
steps += 1
if done:
print("\nGame Over!")
print(f"Final metrics: {state['metrics']}")
print(f"Total reward: {total_reward}")
print(f"Steps: {steps}")
break
print("\nTesting complete!")
return True
def _generate_card_internal(self, metrics, category_weights):
"""Internal method for card generation during testing"""
from src.game_logic import generate_card
# Use the main card generator which now checks cards.json first
return generate_card(metrics, category_weights)
# Add the test method to the environment class
DynastAIEnv._generate_card_internal = _generate_card_internal
if __name__ == "__main__":
print("DynastAI Environment Test")
print("=========================")
# Run the test
asyncio.run(test_environment())