ó
ðè9Qc           @   sœ  d  Z  d d l m Z d d l m Z d d l m Z d d l Z d d l Z d d l Z d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ	 d
 e j
 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e	 f d „  ƒ  YZ i  d „ Z i  d „ Z d e j
 f d „  ƒ  YZ d „  Z d e	 f d „  ƒ  YZ d d# d „  ƒ  YZ d e	 f d „  ƒ  YZ d „  Z d e	 f d „  ƒ  YZ d e f d „  ƒ  YZ d  e f d! „  ƒ  YZ d" „  Z d S($   s«  
This file contains all of the agents that can be selected to
control Pacman.  To select an agent, use the '-p' option
when running pacman.py.  Arguments can be passed to your agent
using '-a'.  For example, to load a SearchAgent that uses
depth first search (dfs), run the following command:

> python pacman.py -p SearchAgent -a fn=depthFirstSearch

Commands to invoke other search strategies can be found in the
project description.

Please only change the parts of the file you are asked to.
Look for the lines that say

"*** YOUR CODE HERE ***"

The parts you fill in start about 3/4 of the way down.  Follow the
project description for details.

Good luck and happy searching!
iÿÿÿÿ(   t
   Directions(   t   Agent(   t   ActionsNt   GoWestAgentc           B   s   e  Z d  Z d „  Z RS(   s'   An agent that goes West until it can't.c         C   s'   t  j | j ƒ  k r t  j St  j Sd S(   s6   The agent receives a GameState (defined in pacman.py).N(   R    t   WESTt   getLegalPacmanActionst   STOP(   t   selft   state(    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyt	   getAction+   s    (   t   __name__t
   __module__t   __doc__R	   (    (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR   (   s   t   SearchAgentc           B   s2   e  Z d  Z d d d d „ Z d „  Z d „  Z RS(   s’  
    This very general search agent finds a path using a supplied search algorithm for a
    supplied search problem, then returns actions to follow that path.

    As a default, this agent runs DFS on a PositionSearchProblem to find location (1,1)

    Options for fn include:
      depthFirstSearch or dfs
      breadthFirstSearch or bfs


    Note: You should NOT change any code in SearchAgent
    t   depthFirstSearcht   PositionSearchProblemt   nullHeuristicc            s$  | t  t ƒ k r" t | d ‚ n  t t | ƒ ‰ d ˆ j j k rX d | GHˆ |  _ nz | t ƒ  j ƒ  k r} t ƒ  | ‰  n1 | t  t ƒ k r¡ t t | ƒ ‰  n t | d ‚ d | | f GH‡  ‡ f d †  |  _ | t ƒ  j ƒ  k s÷ | j	 d ƒ rt | d ‚ n  t ƒ  | |  _
 d	 | GHd  S(
   Ns'    is not a search function in search.py.t	   heuristics   [SearchAgent] using function s3    is not a function in searchAgents.py or search.py.s0   [SearchAgent] using function %s and heuristic %sc            s   ˆ |  d ˆ  ƒS(   NR   (    (   t   x(   t   heurt   func(    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyt   <lambda>Y   s    t   Problems1    is not a search problem type in SearchAgents.py.s!   [SearchAgent] using problem type (   t   dirt   searcht   AttributeErrort   getattrt	   func_codet   co_varnamest   searchFunctiont   globalst   keyst   endswitht
   searchType(   R   t   fnt   probR   (    (   R   R   sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyt   __init__F   s"    	%c         C   s˜   |  j  d k r t d ‚ n  t j ƒ  } |  j | ƒ } |  j  | ƒ |  _ | j |  j ƒ } d | t j ƒ  | f GHd t | ƒ k r” d | j GHn  d S(   sF  
        This is the first time that the agent sees the layout of the game board. Here, we
        choose a path to the goal.  In this phase, the agent should compute the path to the
        goal and store it in a local variable.  All of the work is done in this method!

        state: a GameState object (pacman.py)
        s+   No search function provided for SearchAgents0   Path found with total cost of %d in %.1f secondst	   _expandeds   Search nodes expanded: %dN(	   R   t   Nonet	   Exceptiont   timeR!   t   actionst   getCostOfActionsR   R%   (   R   R   t	   starttimet   problemt	   totalCost(    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyt   registerInitialStatea   s      c         C   sa   d t  |  ƒ k r d |  _ n  |  j } |  j d 7_ | t |  j ƒ k  rV |  j | St j Sd S(   sÕ   
        Returns the next action in the path chosen earlier (in registerInitialState).  Return
        Directions.STOP if there is no further action to take.

        state: a GameState object (pacman.py)
        t   actionIndexi    i   N(   R   R/   t   lenR)   R    R   (   R   R   t   i(    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR	   q   s     	(   R
   R   R   R$   R.   R	   (    (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR   7   s   	R   c           B   sM   e  Z d  Z d „  d d	 e e d „ Z d „  Z d „  Z d „  Z d „  Z	 RS(
   sc  
    A search problem defines the state space, start state, goal test,
    successor function and cost function.  This search problem can be
    used to find paths to a particular point on the pacman board.

    The state space consists of (x,y) positions in a pacman game.

    Note: this search problem is fully specified; you should NOT change it.
    c         C   s   d S(   Ni   (    (   R   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR   ‹   s    i   c         C   s¢   | j  ƒ  |  _ | j ƒ  |  _ | d k r6 | |  _ n  | |  _ | |  _ | |  _ | r | j ƒ  d k sy | j	 | Œ  r d GHn  i  g  d |  _
 |  _ |  _ d S(   sÙ   
        Stores the start and goal.

        gameState: A GameState object (pacman.py)
        costFn: A function from a search state (tuple) to a non-negative number
        goal: A position in the gameState
        i   s6   Warning: this does not look like a regular search mazei    N(   t   getWallst   wallst   getPacmanPositiont
   startStateR&   t   goalt   costFnt	   visualizet
   getNumFoodt   hasFoodt   _visitedt   _visitedlistR%   (   R   t	   gameStateR7   R6   t   startt   warnR8   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR$   ‹   s     			(c         C   s   |  j  S(   N(   R5   (   R   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyt   getStartStateŸ   s    c         C   s   | |  j  k } | r} |  j r} |  j j | ƒ d d  l } d t | ƒ k r} d t | j ƒ k rz | j j |  j ƒ qz q} n  | S(   Niÿÿÿÿt   _displayt   drawExpandedCells(   R6   R8   R<   t   appendt   __main__R   RA   RB   (   R   R   t   isGoalRD   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyt   isGoalState¢   s    c         C   sø   g  } x­ t  j t  j t  j t  j g D] } | \ } } t j | ƒ \ } } t | | ƒ t | | ƒ } }	 |  j | |	 s% | |	 f }
 |  j	 |
 ƒ } | j
 |
 | | f ƒ q% q% W|  j d 7_ | |  j k rô t |  j | <|  j j
 | ƒ n  | S(   s«  
        Returns successor states, the actions they require, and a cost of 1.

         As noted in search.py:
             For a given state, this should return a list of triples,
         (successor, action, stepCost), where 'successor' is a
         successor to the current state, 'action' is the action
         required to get there, and 'stepCost' is the incremental
         cost of expanding to that successor
        i   (   R    t   NORTHt   SOUTHt   EASTR   R   t   directionToVectort   intR3   R7   RC   R%   R;   t   TrueR<   (   R   R   t
   successorst   actionR   t   yt   dxt   dyt   nextxt   nextyt	   nextStatet   cost(    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyt   getSuccessors¯   s    %!c         C   s¡   | d k r d S|  j ƒ  \ } } d } xr | D]j } t j | ƒ \ } } t | | ƒ t | | ƒ } } |  j | | r€ d S| |  j | | f ƒ 7} q/ W| S(   sˆ   
        Returns the cost of a particular sequence of actions.  If those actions
        include an illegal move, return 999999
        i?B i    N(   R&   R@   R   RJ   RK   R3   R7   (   R   R)   R   RO   RU   RN   RP   RQ   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR*   Í   s     ! (   i   i   N(
   R
   R   R   R&   RL   R$   R@   RF   RV   R*   (    (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR   €   s   				t   StayEastSearchAgentc           B   s   e  Z d  Z d „  Z RS(   sÄ   
    An agent for position search with a cost function that penalizes being in
    positions on the West side of the board.

    The cost function for stepping into a position (x,y) is 1/2^x.
    c            s+   t  j |  _ d „  ‰  ‡  f d †  |  _ d  S(   Nc         S   s   d |  d S(   Ng      à?i    (    (   t   pos(    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR   æ   s    c            s   t  |  ˆ  ƒ S(   N(   R   (   R   (   R7   (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR   ç   s    (   R   t   uniformCostSearchR   R!   (   R   (    (   R7   sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR$   ä   s    	(   R
   R   R   R$   (    (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyRW   Ý   s   t   StayWestSearchAgentc           B   s   e  Z d  Z d „  Z RS(   sÂ   
    An agent for position search with a cost function that penalizes being in
    positions on the East side of the board.

    The cost function for stepping into a position (x,y) is 2^x.
    c            s+   t  j |  _ d „  ‰  ‡  f d †  |  _ d  S(   Nc         S   s   d |  d S(   Ni   i    (    (   RX   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR   ò   s    c            s   t  |  ˆ  ƒ S(   N(   R   (   R   (   R7   (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR   ó   s    (   R   RY   R   R!   (   R   (    (   R7   sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR$   ð   s    	(   R
   R   R   R$   (    (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyRZ   é   s   c         C   s;   |  } | j  } t | d | d ƒ t | d | d ƒ S(   s<   The Manhattan distance heuristic for a PositionSearchProblemi    i   (   R6   t   abs(   t   positionR,   t   infot   xy1t   xy2(    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyt   manhattanHeuristicõ   s    	c         C   s;   |  } | j  } | d | d d | d | d d d S(   s<   The Euclidean distance heuristic for a PositionSearchProblemi    i   i   g      à?(   R6   (   R\   R,   R]   R^   R_   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyt   euclideanHeuristicû   s    	t   CornersProblemc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s’   
    This search problem finds paths through all four corners of a layout.

    You must select a suitable state space and successor function
    c         C   s½   | j  ƒ  |  _ | j ƒ  |  _ |  j j d |  j j d } } d d | f | d f | | f f |  _ x2 |  j D]' } | j | Œ  sp d t | ƒ GHqp qp Wd |  _	 |  j |  j f |  _
 d S(   sK   
        Stores the walls, pacman's starting position and corners.
        i   i   s   Warning: no food in corner i    N(   i   i   (   R2   R3   R4   t   startingPositiont   heightt   widtht   cornersR:   t   strR%   R5   (   R   t   startingGameStatet   topt   rightt   corner(    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR$     s    !'	c         C   s   |  j  S(   sN   Returns the start state (in your state space, not the full Pacman state space)(   R5   (   R   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR@     s    c         C   s   d GHt  | d ƒ d k S(   s@   Returns whether this search state is a goal state of the problems   -------------i   i    (   R0   (   R   R   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyRF   #  s    c            s  g  } xë t  j t  j t  j t  j g D]Ë } | d \ } } t j | ƒ \ } } t | | ƒ t | | ƒ f \ } }	 |  j | |	 }
 |
 t	 k rð | |	 f ‰  t
 ‡  f d †  | d Dƒ ƒ } ˆ  | f } d } | | | f } | j | ƒ n  q% W|  j d 7_ | Sd G| GHd GH(   s«  
        Returns successor states, the actions they require, and a cost of 1.

         As noted in search.py:
             For a given state, this should return a list of triples,
         (successor, action, stepCost), where 'successor' is a
         successor to the current state, 'action' is the action
         required to get there, and 'stepCost' is the incremental
         cost of expanding to that successor
        i    c         3   s!   |  ] } | ˆ  k r | Vq d  S(   N(    (   t   .0Rk   (   t   nextPosition(    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pys	   <genexpr>O  s    i   s   successors:s/   ###############################################(   R    RG   RH   RI   R   R   RJ   RK   R3   t   Falset   tupleRC   R%   (   R   R   RM   RN   R   RO   RP   RQ   RR   RS   t   hitsWallt   nextCornersRT   t   stept   nextSuccessor(    (   Rm   sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyRV   )  s"    %& 	c         C   s…   | d k r d S|  j \ } } xY | D]Q } t j | ƒ \ } } t | | ƒ t | | ƒ } } |  j | | r& d Sq& Wt | ƒ S(   s§   
        Returns the cost of a particular sequence of actions.  If those actions
        include an illegal move, return 999999.  This is implemented for you.
        i?B N(   R&   Rc   R   RJ   RK   R3   R0   (   R   R)   R   RO   RN   RP   RQ   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR*   ^  s     ! (   R
   R   R   R$   R@   RF   RV   R*   (    (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyRb     s   				5c         C   s\   | j  } | j } d } |  d } x- |  d D]! } t t j | | ƒ | ƒ } q- W| } | S(   sª  
    A heuristic for the CornersProblem that you defined.

      state:   The current search state
               (a data structure you chose in your search problem)

      problem: The CornersProblem instance for this layout.

    This function should always return a number that is a lower bound
    on the shortest path from the state to a goal of the problem; i.e.
    it should be admissible (as well as consistent).
    i    i   (   Rf   R3   t   maxt   utilt   manhattanDistance(   R   R,   Rf   R3   t   maxDistanceR\   Rk   t   result(    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyt   cornersHeuristicl  s    		
t   AStarCornersAgentc           B   s   e  Z d  Z d „  Z RS(   sC   A SearchAgent for FoodSearchProblem using A* and your foodHeuristicc         C   s   d „  |  _  t |  _ d  S(   Nc         S   s   t  j |  t ƒ S(   N(   R   t   aStarSearchRy   (   R#   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR   Š  s    (   R   Rb   R!   (   R   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR$   ‰  s    (   R
   R   R   R$   (    (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyRz   ‡  s   t   FoodSearchProblemc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   su  
    A search problem associated with finding the a path that collects all of the
    food (dots) in a Pacman game.

    A search state in this problem is a tuple ( pacmanPosition, foodGrid ) where
      pacmanPosition: a tuple (x,y) of integers specifying Pacman's position
      foodGrid:       a Grid (see game.py) of either True or False, specifying remaining food
    c         C   sI   | j  ƒ  | j ƒ  f |  _ | j ƒ  |  _ | |  _ d |  _ i  |  _ d  S(   Ni    (   R4   t   getFoodR>   R2   R3   Rh   R%   t   heuristicInfo(   R   Rh   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR$   –  s
    		c         C   s   |  j  S(   N(   R>   (   R   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR@     s    c         C   s   | d j  ƒ  d k S(   Ni   i    (   t   count(   R   R   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyRF      s    c         C   sÜ   g  } |  j  d 7_  xÀ t j t j t j t j g D]  } | d \ } } t j | ƒ \ } } t | | ƒ t | | ƒ } }	 |  j	 | |	 s4 | d j
 ƒ  }
 t |
 | |	 <| j | |	 f |
 f | d f ƒ q4 q4 W| S(   sD   Returns successor states, the actions they require, and a cost of 1.i   i    (   R%   R    RG   RH   RI   R   R   RJ   RK   R3   t   copyRn   RC   (   R   R   RM   t	   directionR   RO   RP   RQ   RR   RS   t   nextFood(    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyRV   £  s    %!)c         C   s†   |  j  ƒ  d \ } } d } xc | D][ } t j | ƒ \ } } t | | ƒ t | | ƒ } } |  j | | rt d S| d 7} q# W| S(   sv   Returns the cost of a particular sequence of actions.  If those actions
        include an illegal move, return 999999i    i?B i   (   R@   R   RJ   RK   R3   (   R   R)   R   RO   RU   RN   RP   RQ   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR*   ±  s    !(   R
   R   R   R$   R@   RF   RV   R*   (    (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR|     s   				t   AStarFoodSearchAgentc           B   s   e  Z d  Z d „  Z RS(   sC   A SearchAgent for FoodSearchProblem using A* and your foodHeuristicc         C   s   d „  |  _  t |  _ d  S(   Nc         S   s   t  j |  t ƒ S(   N(   R   R{   t   foodHeuristic(   R#   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR   Â  s    (   R   R|   R!   (   R   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR$   Á  s    (   R
   R   R   R$   (    (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyRƒ   ¿  s   c         C   s   |  \ } } | j  ƒ  S(   sç  
    Your heuristic for the FoodSearchProblem goes here.

    This heuristic must be consistent to ensure correctness.  First, try to come up
    with an admissible heuristic; almost all admissible heuristics will be consistent
    as well.

    If using A* ever finds a solution that is worse uniform cost search finds,
    your heuristic is *not* consistent, and probably not admissible!  On the other hand,
    inadmissible or inconsistent heuristics may find optimal solutions, so be careful.

    The state is a tuple ( pacmanPosition, foodGrid ) where foodGrid is a
    Grid (see game.py) of either True or False. You can call foodGrid.asList()
    to get a list of food coordinates instead.

    If you want access to info like walls, capsules, etc., you can query the problem.
    For example, problem.walls gives you a Grid of where the walls are.

    If you want to *store* information to be reused in other calls to the heuristic,
    there is a dictionary called problem.heuristicInfo that you can use. For example,
    if you only want to count the walls once and store that value, try:
      problem.heuristicInfo['wallCount'] = problem.walls.count()
    Subsequent calls to this heuristic can access problem.heuristicInfo['wallCount']
    (   R   (   R   R,   R\   t   foodGrid(    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR„   Å  s    t   ClosestDotSearchAgentc           B   s    e  Z d  Z d „  Z d „  Z RS(   s0   Search for all food using a sequence of searchesc         C   sÎ   g  |  _  | } x | j ƒ  j ƒ  d k r® |  j | ƒ } |  j  | 7_  x` | D]X } | j ƒ  } | | k r• t | ƒ t | ƒ f } t d | ‚ n  | j d | ƒ } qO Wq Wd |  _ d t	 |  j  ƒ GHd  S(   Ni    s5   findPathToClosestDot returned an illegal move: %s!
%ss   Path found with cost %d.(
   R)   R}   R   t   findPathToClosestDott   getLegalActionsRg   R'   t   generateSuccessorR/   R0   (   R   R   t   currentStatet   nextPathSegmentRN   t   legalt   t(    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR.   ä  s    		c         C   s>   | j  ƒ  } | j ƒ  } | j ƒ  } t | ƒ } t j ƒ  d S(   sN   Returns a path (a list of actions) to the closest dot, starting from gameStateN(   R4   R}   R2   t   AnyFoodSearchProblemRu   t   raiseNotDefined(   R   R=   t   startPositiont   foodR3   R,   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR‡   ó  s
    (   R
   R   R   R.   R‡   (    (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR†   â  s   	RŽ   c           B   s    e  Z d  Z d „  Z d „  Z RS(   sù  
      A search problem for finding a path to any food.

      This search problem is just like the PositionSearchProblem, but
      has a different goal test, which you need to fill in below.  The
      state space and successor function do not need to be changed.

      The class definition above, AnyFoodSearchProblem(PositionSearchProblem),
      inherits the methods of the PositionSearchProblem.

      You can use this search problem to help you fill in
      the findPathToClosestDot method.
    c         C   sZ   | j  ƒ  |  _ | j ƒ  |  _ | j ƒ  |  _ d „  |  _ i  g  d |  _ |  _ |  _	 d S(   sF   Stores information from the gameState.  You don't need to change this.c         S   s   d S(   Ni   (    (   R   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR     s    i    N(
   R}   R‘   R2   R3   R4   R5   R7   R;   R<   R%   (   R   R=   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR$     s
    c         C   s   | \ } } t  j ƒ  d S(   s‚   
        The state is Pacman's position. Fill this in with a goal test
        that will complete the problem definition.
        N(   Ru   R   (   R   R   R   RO   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyRF     s    (   R
   R   R   R$   RF   (    (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyRŽ   þ  s   	t   ApproximateSearchAgentc           B   s    e  Z d  Z d „  Z d „  Z RS(   sG   Implement your contest entry here.  Change anything but the class name.c         C   s   d S(   s0   This method is called before any moves are made.N(    (   R   R   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR.   )  s    c         C   s   t  j ƒ  d S(   s   
        From game.py:
        The Agent will receive a GameState and must return an action from
        Directions.{North, South, East, West, Stop}
        N(   Ru   R   (   R   R   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR	   -  s    (   R
   R   R   R.   R	   (    (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyR’   &  s   	c   	   
   C   s™   |  \ } } | \ } } | j  ƒ  } | | | s@ t d |  ‚ | | | sb t d t | ƒ ‚ t | d |  d | d t d t ƒ} t t j | ƒ ƒ S(   sR  
    Returns the maze distance between any two points, using the search functions
    you have already built.  The gameState can be any game state -- Pacman's position
    in that state is ignored.

    Example usage: mazeDistance( (2,4), (5,6), gameState)

    This might be a useful helper function for your ApproximateSearchAgent.
    s   point1 is a wall: s   point2 is a wall: R>   R6   R?   R8   (   R2   t   AssertionErrorRg   R   Rn   R0   R   t   bfs(	   t   point1t   point2R=   t   x1t   y1t   x2t   y2R3   R#   (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyt   mazeDistance6  s    
"$(    (   R   t   gameR    R   R   Ru   R(   R   R   R   t   SearchProblemR   RW   RZ   R`   Ra   Rb   Ry   Rz   R|   Rƒ   R„   R†   RŽ   R’   R›   (    (    (    sf   C:\Users\user\Desktop\Studies\02 BerkeleyX cs188x\05 Projects\01 Search Project\search\searchAgents.pyt   <module>    s.   I]
g	2	(