#!/usr/bin/env python3"""Example script for running the Mastermind game.This script demonstrates how to initialize and run the Mastermind game with variousconfiguration options."""importargparseimportrandomimportsysfromhaive.games.mastermind.agentimportMastermindAgentfromhaive.games.mastermind.configimportMastermindConfig
[docs]defparse_args():"""Parse command line arguments."""parser=argparse.ArgumentParser(description="Run the Mastermind game")parser.add_argument("--codemaker",choices=["player1","player2"],default="player1",help="Player who creates the secret code (default: player1)",)parser.add_argument("--max-turns",type=int,default=10,help="Maximum number of turns (default: 10)",)parser.add_argument("--visualize",action="store_true",default=True,help="Enable visualization (default: True)",)parser.add_argument("--rich-ui",action="store_true",default=True,help="Use Rich UI if available (default: True)",)parser.add_argument("--random-code",action="store_true",default=True,help="Use a random secret code (default: True)",)returnparser.parse_args()
[docs]defmain():"""Run the Mastermind game with the specified configuration."""args=parse_args()# Define available colorsavailable_colors=["red","blue","green","yellow","purple","orange"]# Generate a random secret code or use a fixed oneifargs.random_code:secret_code=random.sample(available_colors,4)print(f"Generated random secret code: {secret_code}")else:# Fixed code for testingsecret_code=["red","blue","green","yellow"]print(f"Using fixed secret code: {secret_code}")# Create configconfig=MastermindConfig(codemaker=args.codemaker,max_turns=args.max_turns,visualize=args.visualize,colors=available_colors,secret_code=secret_code,enable_analysis=True,)# Create and run agentagent=MastermindAgent(config=config)# Run with Rich UI if requestedifargs.rich_ui:agent.run_game_with_ui()else:agent.run_game(visualize=args.visualize)return0