diff --git a/grading.pyc b/grading.pyc new file mode 100644 index 0000000..5b28137 Binary files /dev/null and b/grading.pyc differ diff --git a/multiAgents.py b/multiAgents.py index 9e2c709..6f02ff1 100644 --- a/multiAgents.py +++ b/multiAgents.py @@ -77,10 +77,10 @@ class ReflexAgent(Agent): newGhostStates = successorGameState.getGhostStates() newScaredTimes = [ ghostState.scaredTimer for ghostState in newGhostStates] - print(newPos) - print(newFood) - print(newGhostStates) - print(newScaredTimes) + # print(newPos) + # print(newFood) + # print(newGhostStates) + # print(newScaredTimes) # make is so that if it is closer to a ghost then reduce the score # increase if closer to food @@ -163,7 +163,81 @@ class MinimaxAgent(MultiAgentSearchAgent): Returns whether or not the game state is a losing state """ "*** YOUR CODE HERE ***" - util.raiseNotDefined() + # Use function for min and max of node + # need same args to call main_delegation again after agents turn + # mechanism to keep track with agenCount whether ghost or pacman + def min_recurse(depth, agentCount, gameState): + # action value pair + best_action = "" + best_value = 1000 + node_actions = gameState.getLegalActions(agentCount) + # base + if not node_actions: + # print(self.depth) + return self.evaluationFunction(gameState) + + for successor in node_actions: + curr_succ = gameState.generateSuccessor(agentCount, successor) + + value_node = main_delegation(depth, agentCount + 1, curr_succ) + + if type(value_node) is list: + updated_action = value_node[1] + else: + updated_action = value_node + # update best_action + if updated_action < best_value: + best_action = successor + best_value = updated_action + return [best_action, best_value] + + def max_recurse(depth, agentCount, gameState): + # action value pair + best_action = "" + best_value = -1000 + node_actions = gameState.getLegalActions(agentCount) + + # base + if not node_actions: + # print(self.depth) + return self.evaluationFunction(gameState) + + for successor in node_actions: + curr_succ = gameState.generateSuccessor(agentCount, successor) + + value_node = main_delegation(depth, agentCount + 1, curr_succ) + + if type(value_node) is list: + updated_action = value_node[1] + else: + updated_action = value_node + # update best_action + if updated_action > best_value: + best_action = successor + best_value = updated_action + return [best_action, best_value] + + + # main recurring function depending on who the player is + def main_delegation(depth, agentCount, gameState): + # see if all ghosts or agent recursed this time + iterAgentCount = gameState.getNumAgents() + if iterAgentCount <= agentCount: + agentCount = 0 + depth += 1 + + # stopping mechanisms + if depth == self.depth: + return self.evaluationFunction(gameState) + if gameState.isWin() or gameState.isLose(): + return self.evaluationFunction(gameState) + + if agentCount == 0: + return max_recurse(depth, agentCount, gameState) + else: + return min_recurse(depth, agentCount, gameState) + + return main_delegation(0, 0, gameState)[0] class AlphaBetaAgent(MultiAgentSearchAgent): diff --git a/multiAgents.pyc b/multiAgents.pyc new file mode 100644 index 0000000..931f718 Binary files /dev/null and b/multiAgents.pyc differ diff --git a/pacman.pyc b/pacman.pyc new file mode 100644 index 0000000..02effae Binary files /dev/null and b/pacman.pyc differ diff --git a/projectParams.pyc b/projectParams.pyc new file mode 100644 index 0000000..9729ca4 Binary files /dev/null and b/projectParams.pyc differ diff --git a/util.pyc b/util.pyc new file mode 100644 index 0000000..0e126e6 Binary files /dev/null and b/util.pyc differ