agents.manual_agent
1import asyncio 2import os 3import sys 4from typing import List, Optional 5 6# Add the parent directory to sys.path to allow running agents as scripts from the root 7sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 8 9from agents.base_agent import BaseC4Agent 10 11 12class ManualC4Agent(BaseC4Agent): 13 """ 14 A human-controlled agent using terminal inputs (0-6). 15 """ 16 17 async def deliberate(self, valid_actions: List[int]) -> Optional[int]: 18 """ 19 Asks the user to select a column from the list of valid actions. 20 21 Args: 22 valid_actions: A list of valid column indices where a piece can be dropped. 23 24 Returns: 25 The chosen column index. 26 """ 27 print(f"\n--- YOUR TURN (Player {self.player_id}) ---") 28 print(f"Valid columns: {valid_actions}") 29 30 while True: 31 # Use to_thread to prevent the asyncio loop from freezing 32 user_input: str = await asyncio.to_thread(input, "Select column (0-6): ") 33 34 try: 35 col: int = int(user_input.strip()) 36 if col in valid_actions: 37 return col 38 else: 39 print("Invalid column. Either it's full or out of bounds. Try again.") 40 except ValueError: 41 print("Invalid input. Please enter a number between 0 and 6.") 42 43 44if __name__ == "__main__": 45 agent = ManualC4Agent() 46 print("Starting Manual Connect 4 Agent...") 47 asyncio.run(agent.run())
13class ManualC4Agent(BaseC4Agent): 14 """ 15 A human-controlled agent using terminal inputs (0-6). 16 """ 17 18 async def deliberate(self, valid_actions: List[int]) -> Optional[int]: 19 """ 20 Asks the user to select a column from the list of valid actions. 21 22 Args: 23 valid_actions: A list of valid column indices where a piece can be dropped. 24 25 Returns: 26 The chosen column index. 27 """ 28 print(f"\n--- YOUR TURN (Player {self.player_id}) ---") 29 print(f"Valid columns: {valid_actions}") 30 31 while True: 32 # Use to_thread to prevent the asyncio loop from freezing 33 user_input: str = await asyncio.to_thread(input, "Select column (0-6): ") 34 35 try: 36 col: int = int(user_input.strip()) 37 if col in valid_actions: 38 return col 39 else: 40 print("Invalid column. Either it's full or out of bounds. Try again.") 41 except ValueError: 42 print("Invalid input. Please enter a number between 0 and 6.")
A human-controlled agent using terminal inputs (0-6).
async def
deliberate(self, valid_actions: List[int]) -> Optional[int]:
18 async def deliberate(self, valid_actions: List[int]) -> Optional[int]: 19 """ 20 Asks the user to select a column from the list of valid actions. 21 22 Args: 23 valid_actions: A list of valid column indices where a piece can be dropped. 24 25 Returns: 26 The chosen column index. 27 """ 28 print(f"\n--- YOUR TURN (Player {self.player_id}) ---") 29 print(f"Valid columns: {valid_actions}") 30 31 while True: 32 # Use to_thread to prevent the asyncio loop from freezing 33 user_input: str = await asyncio.to_thread(input, "Select column (0-6): ") 34 35 try: 36 col: int = int(user_input.strip()) 37 if col in valid_actions: 38 return col 39 else: 40 print("Invalid column. Either it's full or out of bounds. Try again.") 41 except ValueError: 42 print("Invalid input. Please enter a number between 0 and 6.")
Asks the user to select a column from the list of valid actions.
Args: valid_actions: A list of valid column indices where a piece can be dropped.
Returns: The chosen column index.