agents.dummy_agent
1import asyncio 2import random 3from typing import List, Optional, Tuple, Union 4 5from agents.base_agent import BaseBSAgent 6 7 8class DummyBSAgent(BaseBSAgent): 9 """ 10 A simple automated Battleship agent that selects targets randomly. 11 """ 12 13 async def deliberate( 14 self, 15 my_ships: List[List[Union[int, str]]], 16 my_shots: List[List[int]], 17 valid_actions: List[List[int]], 18 ) -> Optional[Union[List[int], Tuple[int, int]]]: 19 r""" 20 Picks a random target from the available valid actions. 21 22 Selects $(x, y) \sim \mathcal{U}(A)$, where $A$ is the set of valid actions. 23 24 Args: 25 my_ships: 10x10 grid with your ship names. 26 my_shots: 10x10 grid with your shot history. 27 valid_actions: List of coordinates [x, y] that haven't been targeted yet. 28 29 Returns: 30 A random [x, y] coordinate. 31 """ 32 # Add a tiny delay so human observers can watch the game unfold 33 await asyncio.sleep(0.1) 34 35 # Pick a random un-shot [x, y] coordinate 36 chosen_target = random.choice(valid_actions) 37 return chosen_target 38 39 40if __name__ == "__main__": 41 agent = DummyBSAgent() 42 asyncio.run(agent.run())
9class DummyBSAgent(BaseBSAgent): 10 """ 11 A simple automated Battleship agent that selects targets randomly. 12 """ 13 14 async def deliberate( 15 self, 16 my_ships: List[List[Union[int, str]]], 17 my_shots: List[List[int]], 18 valid_actions: List[List[int]], 19 ) -> Optional[Union[List[int], Tuple[int, int]]]: 20 r""" 21 Picks a random target from the available valid actions. 22 23 Selects $(x, y) \sim \mathcal{U}(A)$, where $A$ is the set of valid actions. 24 25 Args: 26 my_ships: 10x10 grid with your ship names. 27 my_shots: 10x10 grid with your shot history. 28 valid_actions: List of coordinates [x, y] that haven't been targeted yet. 29 30 Returns: 31 A random [x, y] coordinate. 32 """ 33 # Add a tiny delay so human observers can watch the game unfold 34 await asyncio.sleep(0.1) 35 36 # Pick a random un-shot [x, y] coordinate 37 chosen_target = random.choice(valid_actions) 38 return chosen_target
A simple automated Battleship agent that selects targets randomly.
async def
deliberate( self, my_ships: List[List[Union[str, int]]], my_shots: List[List[int]], valid_actions: List[List[int]]) -> Union[List[int], Tuple[int, int], NoneType]:
14 async def deliberate( 15 self, 16 my_ships: List[List[Union[int, str]]], 17 my_shots: List[List[int]], 18 valid_actions: List[List[int]], 19 ) -> Optional[Union[List[int], Tuple[int, int]]]: 20 r""" 21 Picks a random target from the available valid actions. 22 23 Selects $(x, y) \sim \mathcal{U}(A)$, where $A$ is the set of valid actions. 24 25 Args: 26 my_ships: 10x10 grid with your ship names. 27 my_shots: 10x10 grid with your shot history. 28 valid_actions: List of coordinates [x, y] that haven't been targeted yet. 29 30 Returns: 31 A random [x, y] coordinate. 32 """ 33 # Add a tiny delay so human observers can watch the game unfold 34 await asyncio.sleep(0.1) 35 36 # Pick a random un-shot [x, y] coordinate 37 chosen_target = random.choice(valid_actions) 38 return chosen_target
Picks a random target from the available valid actions.
Selects $(x, y) \sim \mathcal{U}(A)$, where $A$ is the set of valid actions.
Args: my_ships: 10x10 grid with your ship names. my_shots: 10x10 grid with your shot history. valid_actions: List of coordinates [x, y] that haven't been targeted yet.
Returns: A random [x, y] coordinate.