-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_ai_controller.py
More file actions
86 lines (64 loc) · 3.03 KB
/
multi_ai_controller.py
File metadata and controls
86 lines (64 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
"""
Multi-AI Controller for Grok Plays Pokémon
Run this script to control the game with multiple AIs.
"""
import time
import argparse
import logging
from ai_controller import AIManager, get_game_status, get_game_state, execute_action, start_game
# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
def parse_args():
"""Parse command-line arguments."""
parser = argparse.ArgumentParser(description="Multi-AI Controller for Grok Plays Pokémon")
parser.add_argument("--player", choices=["grok", "claude"], default="grok",
help="Which AI should control player movement (default: grok). In single mode, this AI controls everything.")
parser.add_argument("--pokemon", choices=["grok", "claude"], default="claude",
help="Which AI should control Pokémon battles (default: claude)")
parser.add_argument("--mode", choices=["single", "dual"], default="dual",
help="Run in single or dual AI mode (default: dual). In single mode, only the player AI is used for everything.")
parser.add_argument("--steps", type=int, default=100,
help="Number of steps to run (default: 100)")
parser.add_argument("--delay", type=float, default=1.0,
help="Delay between actions in seconds (default: 1.0)")
return parser.parse_args()
def main():
"""Main function to run the multi-AI controller."""
args = parse_args()
logger.info(f"Starting Multi-AI Controller")
logger.info(f"Player AI: {args.player}")
logger.info(f"Pokémon AI: {args.pokemon}")
logger.info(f"Mode: {args.mode}")
# Create AI manager
manager = AIManager()
# Configure AIs based on arguments
manager.set_active_player_ai(args.player)
manager.set_active_pokemon_ai(args.pokemon)
manager.set_dual_mode(args.mode == "dual")
# Start the game if not running
status = get_game_status()
if status.get("status") != "running":
logger.info("Starting the game")
start_game()
time.sleep(2) # Wait for game to initialize
# Run the AIs for specified steps
logger.info(f"Running for {args.steps} steps with {args.delay}s delay")
for step in range(args.steps):
# Get current game state
state = get_game_state()
# Get AI's decision
action, commentary = manager.get_action(state)
# Execute the action
result = execute_action(action, commentary)
# Log the step
logger.info(f"Step {step+1}/{args.steps}: {action} - {commentary}")
# Check if action failed
if not result.get("success", False):
logger.warning(f"Action failed: {result.get('error', 'Unknown error')}")
# Wait before next action
time.sleep(args.delay)
logger.info("Multi-AI controller run completed")
if __name__ == "__main__":
main()