def successor(self, agent_index, action): """ Returns the the state that results when the given action is applied. (State, int, str) -> State """ # Check that successors exist if self.terminal: raise Exception('Can\'t generate a successor of a terminal state.') # Copy current state state = self.deepcopy() # Let agent's logic deal with its action's effects on the board if agent_index == 0: from game_rules import RedBirdRules RedBirdRules.apply_action(state, action) else: from game_rules import BlackBirdRules BlackBirdRules.apply_action(state, action) # Book keeping state._agent_moved = agent_index state.score += state.score_change return state
def get_legal_actions(self, agent_index=0): """ Returns the legal actions for the agent specified (0 is red_bird) (State, int) -> [Action] """ if self.terminal: return [] if agent_index == 0: from game_rules import RedBirdRules return RedBirdRules.get_legal_actions(self) else: from game_rules import BlackBirdRules return BlackBirdRules.get_legal_actions(self)