chessai.agents.aggressive
1import chessai.core.action 2import chessai.core.agent 3import chessai.core.gamestate 4 5class AggressiveAgent(chessai.core.agent.Agent): 6 """ An agent that just takes a stochastic agressive action. """ 7 8 def get_action(self, 9 state: chessai.core.gamestate.GameState) -> chessai.core.action.Action: 10 """ 11 Returns a stochastic aggressive action based on the game state. 12 """ 13 14 # Prioritize movement actions. 15 legal_actions = state.get_legal_move_actions() 16 17 # Fall back to all legal actions if there are no legal movement actions. 18 if (len(legal_actions) == 0): 19 legal_actions = state.get_legal_actions() 20 21 # Introduce stochasticity into the aggressive agent. 22 self.rng.shuffle(legal_actions) 23 for action in legal_actions: 24 if (state.is_capture(action)): 25 return action 26 27 # If we couldn't find an action that is a capture, return a random action. 28 if (len(legal_actions) > 0): 29 return legal_actions[0] 30 31 return chessai.core.action.NoneAction()
6class AggressiveAgent(chessai.core.agent.Agent): 7 """ An agent that just takes a stochastic agressive action. """ 8 9 def get_action(self, 10 state: chessai.core.gamestate.GameState) -> chessai.core.action.Action: 11 """ 12 Returns a stochastic aggressive action based on the game state. 13 """ 14 15 # Prioritize movement actions. 16 legal_actions = state.get_legal_move_actions() 17 18 # Fall back to all legal actions if there are no legal movement actions. 19 if (len(legal_actions) == 0): 20 legal_actions = state.get_legal_actions() 21 22 # Introduce stochasticity into the aggressive agent. 23 self.rng.shuffle(legal_actions) 24 for action in legal_actions: 25 if (state.is_capture(action)): 26 return action 27 28 # If we couldn't find an action that is a capture, return a random action. 29 if (len(legal_actions) > 0): 30 return legal_actions[0] 31 32 return chessai.core.action.NoneAction()
An agent that just takes a stochastic agressive action.
9 def get_action(self, 10 state: chessai.core.gamestate.GameState) -> chessai.core.action.Action: 11 """ 12 Returns a stochastic aggressive action based on the game state. 13 """ 14 15 # Prioritize movement actions. 16 legal_actions = state.get_legal_move_actions() 17 18 # Fall back to all legal actions if there are no legal movement actions. 19 if (len(legal_actions) == 0): 20 legal_actions = state.get_legal_actions() 21 22 # Introduce stochasticity into the aggressive agent. 23 self.rng.shuffle(legal_actions) 24 for action in legal_actions: 25 if (state.is_capture(action)): 26 return action 27 28 # If we couldn't find an action that is a capture, return a random action. 29 if (len(legal_actions) > 0): 30 return legal_actions[0] 31 32 return chessai.core.action.NoneAction()
Returns a stochastic aggressive action based on the game state.