ó
.ŽKQc           @   sè   d  d l  m Z d  d l m Z d  d l Z d  d l  Z  d  d l m Z d e f d „  ƒ  YZ d „  Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ	 d e f d „  ƒ  YZ
 d e f d „  ƒ  YZ d „  Z e Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   manhattanDistance(   t
   DirectionsN(   t   Agentt   ReflexAgentc           B   s    e  Z d  Z d „  Z d „  Z RS(   s  
    A reflex agent chooses an action at each choice point by examining
    its alternatives via a state evaluation function.

    The code below is provided as a guide.  You are welcome to change
    it in any way you see fit, so long as you don't touch our method
    headers.
  c   	      C   s‰   | j  ƒ  } g  | D] } |  j | | ƒ ^ q } t | ƒ } g  t t | ƒ ƒ D] } | | | k rP | ^ qP } t j | ƒ } | | S(   s8  
    You do not need to change this method, but you're welcome to.

    getAction chooses among the best options according to the evaluation function.

    Just like in the previous project, getAction takes a GameState and returns
    some Directions.X for some X in the set {North, South, West, East, Stop}
    (   t   getLegalActionst   evaluationFunctiont   maxt   ranget   lent   randomt   choice(	   t   selft	   gameStatet
   legalMovest   actiont   scorest	   bestScoret   indext   bestIndicest   chosenIndex(    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyt	   getAction   s    
%5c         C   së  | j  | ƒ } | j ƒ  } | j ƒ  } | j ƒ  } g  | D] } | j ^ q: } | j ƒ  }	 | j ƒ  }
 | j ƒ  } g  | D] } | j ^ qz } | j ƒ  j ƒ  } t ƒ  } d } x% | D] } | j | ƒ | | 7} q· Wt ƒ  } x- | D]% } t	 j
 |	 | ƒ } | j | ƒ qè Wt	 j | ƒ } d } x | D] } t | | ƒ } q-Wt ƒ  } x1 | D]) } d t	 j
 |	 | ƒ } | j | ƒ qVWt	 j | ƒ } d } x | D] } t | | ƒ } qŸW| j ƒ  | | } d G| GHd G| GHd G| GH| S(   sc  
    Design a better evaluation function here.

    The evaluation function takes in the current and proposed successor
    GameStates (pacman.py) and returns a number, where higher numbers are better.

    The code below extracts some useful information from the state, like the
    remaining food (oldFood) and Pacman position after moving (newPos).
    newScaredTimes holds the number of moves that each ghost will remain
    scared because of Pacman having eaten a power pellet.

    Print out these variables to see what you're getting, then combine them
    to create a masterful evaluation function.
    i    i?B i   gñhãˆµøä>s   closestGhost: s   closestFood: s   score: (   t   generatePacmanSuccessort   getPacmanPositiont   getFoodt   getGhostStatest   scaredTimert   getGhostPositionst   asListt   listt   appendt   utilR    t	   normalizet   minR   t   getScore(   R   t   currentGameStateR   t   successorGameStatet   newPost   oldFoodt   newGhostStatest
   ghostStatet   newScaredTimest   pacmanPositiont   ghostStatest   ghostPositionst   scaredTimest   foodPositionst   ghostScaredTimest   totalScaredTimet
   scaredTimet   ghostDistancest   ghostPositiont   ghostDistancet   closestGhostt   foodDistancest   foodPositiont   foodDistancet   closestFoodt   score(    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyR   0   sH    						(   t   __name__t
   __module__t   __doc__R   R   (    (    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyR      s   	c         C   s
   |  j  ƒ  S(   sï   
    This default evaluation function just returns the score of the state.
    The score is the same one displayed in the Pacman GUI.

    This evaluation function is meant for use with adversarial search agents
    (not reflex agents).
  (   R!   (   R"   (    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyt   scoreEvaluationFunctionx   s    t   MultiAgentSearchAgentc           B   s   e  Z d  Z d d d „ Z RS(   sE  
    This class provides some common elements to all of your
    multi-agent searchers.  Any methods defined here will be available
    to the MinimaxPacmanAgent, AlphaBetaPacmanAgent & ExpectimaxPacmanAgent.

    You *do not* need to make any changes here, but you can if you want to
    add functionality to all your adversarial search agents.  Please do not
    remove anything, however.

    Note: this is an abstract class: one that should not be instantiated.  It's
    only partially specified, and designed to be extended.  Agent (game.py)
    is another abstract class.
  R=   t   2c         C   s4   d |  _  t j | t ƒ  ƒ |  _ t | ƒ |  _ d  S(   Ni    (   R   R   t   lookupt   globalsR   t   intt   depth(   R   t   evalFnRC   (    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyt   __init__‘   s    	(   R:   R;   R<   RE   (    (    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyR>   ‚   s   t   MinimaxAgentc           B   s   e  Z d  Z d „  Z RS(   s'   
    Your minimax agent (question 2)
  c         C   s   t  j ƒ  d S(   s  
      Returns the minimax action from the current gameState using self.depth
      and self.evaluationFunction.

      Here are some method calls that might be useful when implementing minimax.

      gameState.getLegalActions(agentIndex):
        Returns a list of legal actions for an agent
        agentIndex=0 means Pacman, ghosts are >= 1

      Directions.STOP:
        The stop direction, which is always legal

      gameState.generateSuccessor(agentIndex, action):
        Returns the successor game state after an agent takes an action

      gameState.getNumAgents():
        Returns the total number of agents in the game
    N(   R   t   raiseNotDefined(   R   R   (    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyR   ›   s    (   R:   R;   R<   R   (    (    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyRF   –   s   t   AlphaBetaAgentc           B   s   e  Z d  Z d „  Z RS(   s?   
    Your minimax agent with alpha-beta pruning (question 3)
  c         C   s   t  j ƒ  d S(   sS   
      Returns the minimax action using self.depth and self.evaluationFunction
    N(   R   RG   (   R   R   (    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyR   ·   s    (   R:   R;   R<   R   (    (    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyRH   ²   s   t   ExpectimaxAgentc           B   s   e  Z d  Z d „  Z RS(   s*   
    Your expectimax agent (question 4)
  c         C   s   t  j ƒ  d S(   s¸   
      Returns the expectimax action using self.depth and self.evaluationFunction

      All ghosts should be modeled as choosing uniformly at random from their
      legal moves.
    N(   R   RG   (   R   R   (    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyR   Ã   s    (   R:   R;   R<   R   (    (    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyRI   ¾   s   c         C   s   t  j ƒ  d S(   sµ   
    Your extreme ghost-hunting, pellet-nabbing, food-gobbling, unstoppable
    evaluation function (question 5).

    DESCRIPTION: <write something here so we know what you did>
  N(   R   RG   (   R"   (    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyt   betterEvaluationFunctionÍ   s    t   ContestAgentc           B   s   e  Z d  Z d „  Z RS(   s'   
    Your agent for the mini-contest
  c         C   s   t  j ƒ  d S(   s|  
      Returns an action.  You can use any method you want and search to any depth you want.
      Just remember that the mini-contest is timed, so you have to trade off speed and computation.

      Ghosts don't behave randomly anymore, but they aren't perfect either -- they'll usually
      just make a beeline straight towards Pacman (or away from him if they're scared!)
    N(   R   RG   (   R   R   (    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyR   ß   s    	(   R:   R;   R<   R   (    (    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyRK   Ú   s   (   R   R    t   gameR   R	   R   R   R=   R>   RF   RH   RI   RJ   t   betterRK   (    (    (    sh   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\00 Unofficial\02 multiagent\multiAgents.pyt   <module>	   s   i	
	