cs 232 review materials with answers [part...

11
CS 232 Review Materials with Answers [Part 1] Q1: Foodie Pacman There are two kinds of food pellets, each with a different color (red and blue). Pacman is only interested in tasting the two different kinds of food: the game ends when he has eaten 1 red pellet and 1 blue pellet (though Pacman may eat more than one of each pellet). Pacman has four actions: moving up, down, left, or right, and does not have a “stay” action. There are K red pellets and K blue pellets, and the dimensions of the board are N by M. (a) Give an efficient state space formulation of this problem. Specify the domain of each variable in your state space. b) Give a tight upper bound on the size of the state space. (c) Give a tight upper bound on the branching factor of the search problem. (d) Assuming Pacman starts the game in position (x,y), what is the initial state? (e) Define a goal test for the problem. (f) For each of the following heuristics, indicate (yes/no) whether or not it is admissible. Heuristic Admissible The number of pellets remaining F 1

Upload: others

Post on 22-Jun-2020

40 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: CS 232 Review Materials with Answers [Part 1]cs.wellesley.edu/~cs232/2015/pages/ReviewMaterial1with...Q7: Alpha beta pruning For each of the game trees shown below, state for which

CS 232 Review Materials with Answers [Part 1]  Q1: Foodie Pacman  There are two kinds of food pellets, each with a different color (red and blue). Pacman is only interested in tasting the two different kinds of food: the game ends when he has eaten 1 red pellet and 1 blue pellet (though Pacman may eat more than one of each pellet). Pacman has four actions: moving up, down, left, or right, and does not have a “stay” action. There are K red pellets and K blue pellets, and the dimensions of the board are N by M. 

  (a) Give an efficient state space formulation of this problem. Specify the domain of each variable in your state space. 

  b) Give a tight upper bound on the size of the state space. 

 (c) Give a tight upper bound on the branching factor of the search problem. 

 (d) Assuming Pacman starts the game in position (x,y), what is the initial state? 

 (e) Define a goal test for the problem. 

 (f) For each of the following heuristics, indicate (yes/no) whether or not it is admissible.  

Heuristic  Admissible 

The number of pellets remaining  F 

Page 2: CS 232 Review Materials with Answers [Part 1]cs.wellesley.edu/~cs232/2015/pages/ReviewMaterial1with...Q7: Alpha beta pruning For each of the game trees shown below, state for which

The smallest Manhattan distance to any remaining pellet  T 

The maximum Manhattan distance between any two remaining pellets  F 

The minimum Manhattan distance between any two remaining pellets of opposite colors  F 

  Q2: Surrealist Pacman  In the game of Surrealist Pacman, Pacman plays against a moving wall . On Pacman’s turn, Pacman must move in one of the four cardinal directions, and must move into an unoccupied square. On the wall’s turn, the wall must move in one of the four cardinal directions, and must move into an unoccupied square. The wall cannot move into a dot­containing square. Staying still is not allowed by either player. Pacman’s score is always equal to the number of dots he has eaten.  The first game begins in the configuration shown below. Pacman moves first.  

 (a) Draw a game tree with one move for each player. Draw only the legal moves. 

 

Page 3: CS 232 Review Materials with Answers [Part 1]cs.wellesley.edu/~cs232/2015/pages/ReviewMaterial1with...Q7: Alpha beta pruning For each of the game trees shown below, state for which

  b) According to the depth­limited game tree you drew above what is the value of the game? Use Pacman’s score as your evaluation function. 

 c) If we were to consider a game tree with ten moves for each player (rather than just one), what would be the value of the game as computed by minimax? 

  A second game is played on a more complicated board. A partial game tree is drawn, and leaf nodes have been scored using an (unknown) evaluation function e.   (d) In the dashed boxes, fill in the values of all internal nodes using the minimax algorithm.   (e) Cross off any nodes that are not evaluated when using alpha­beta pruning (assuming the standard left­to­right traversal of the tree).  

 

Page 4: CS 232 Review Materials with Answers [Part 1]cs.wellesley.edu/~cs232/2015/pages/ReviewMaterial1with...Q7: Alpha beta pruning For each of the game trees shown below, state for which

 

             

Page 5: CS 232 Review Materials with Answers [Part 1]cs.wellesley.edu/~cs232/2015/pages/ReviewMaterial1with...Q7: Alpha beta pruning For each of the game trees shown below, state for which

Q3: Expectimax  Your little brother Timmy has a birthday and he was promised a toy. However, Timmy has been misbehaving lately and Dad thinks he deserves the least expensive present. Timmy, of course, wants the most expensive toy. Dad will pick the city from which to buy the toy, Timmy will pick the store and you get to pick the toy itself. You don’t want to take sides so you decide to pick a toy at random. All prices (including X and Y) are assumed to be nonnegative.  

  

(a)  Fill in the values of all the nodes that don’t depend on X or Y. [see tree above]  (b) What values of X will make Dad pick Emeryville regardless of the price of Y?  

   (c) We know that Y is at most $30. What values of X will result in a toy from Games of Berkeley regardless of the exact price of Y? 

 d) Normally, alpha­beta pruning is not used with expectimax. However, with some additional information, it is possible to do something similar. Which one of the following conditions on a problem is required to perform pruning with expectimax?  1. The children of the expectation node are leaves.  2. All values are positive.  3. The children of the expectation node have specified ranges.  

Page 6: CS 232 Review Materials with Answers [Part 1]cs.wellesley.edu/~cs232/2015/pages/ReviewMaterial1with...Q7: Alpha beta pruning For each of the game trees shown below, state for which

4. The child to prune is last. 

  Q4: Search  The following implementation of graph search may be incorrect. Circle all the problems with the code.  

  1. Nodes may be expanded twice.  2. The algorithm is no longer complete.  3. The algorithm could return an incorrect solution.  4. None of the above. 

   Q5: Search with Slugs  You are once again tasked with planning ways to get various insects out of a maze. This time, it’s slugs! As shown in the diagram below to the left, two slugs A and B want to exit a maze via their own personal exits. In each time step, both slugs move, though each can choose to either stay in place or move into an adjacent free square. The slugs cannot move into a square that the other slug is moving into. In addition, the slugs leave behind a sticky, poisonous substance and so they cannot move into any square that either slug has ever been in. For example, if both slugs move right twice, the maze is as shown in the diagram below to right, with the x squares unpassable to either slug.  

Page 7: CS 232 Review Materials with Answers [Part 1]cs.wellesley.edu/~cs232/2015/pages/ReviewMaterial1with...Q7: Alpha beta pruning For each of the game trees shown below, state for which

   a) How many states are there in a minimal representation of the space? Justify with a brief description of the components of your state space. 

 b) What is the branching factor? Justify with a brief description of the successor function. 

  c) Give a non­trivial admissible heuristic for this problem. [Clarification: In Math, non­trivial means: having some variables or terms that are not equal to zero or an identity.] 

  Q6: Variants of Trees  (a) Pacman is going to play against a careless ghost, which makes a move that is optimal for Pacman 1/3 of the time, and makes a move that that minimizes Pacman’s utility the other 2/3 of the time.  (i) Fill in the correct utility values in the game tree below where Pacman is the maximizer: 

Page 8: CS 232 Review Materials with Answers [Part 1]cs.wellesley.edu/~cs232/2015/pages/ReviewMaterial1with...Q7: Alpha beta pruning For each of the game trees shown below, state for which

 To see how the values were calculated, check out the tree in point (ii).   (ii) Draw a complete game tree for the game above that contains only max nodes, min nodes, and chance nodes.  

   Q7: Alpha­beta pruning  For each of the game­trees shown below, state for which values of x the dashed branch with the scissors will be pruned. If the pruning will not happen for any value of x write “none”. If pruning will happen for all values of x write “all”.  

Page 9: CS 232 Review Materials with Answers [Part 1]cs.wellesley.edu/~cs232/2015/pages/ReviewMaterial1with...Q7: Alpha beta pruning For each of the game trees shown below, state for which

  

       

Page 10: CS 232 Review Materials with Answers [Part 1]cs.wellesley.edu/~cs232/2015/pages/ReviewMaterial1with...Q7: Alpha beta pruning For each of the game trees shown below, state for which

    Q8: InvisiPac  

 

Pacman finds himself to have an invisible “friend”, InvisiPac. Whenever InvisiPac visits a square with a food pellet, InvisiPac will eat that food pellet—giving away its location at that time. Suppose the maze’s size is MxN and there are F food pellets at the beginning. Pacman and InvisiPac alternate moves. Pacman can move to any adjacent square (including the one where InvisiPac is) that are not walls, just as in the regular game. After Pacman moves, InvisiPac can teleport into any of the four squares that are adjacent to Pacman, as marked with the dashed circle in the graph. InvisiPac can occupy wall squares.  

 (a) For this subquestion, whenever InvisiPac moves, it chooses randomly from the squares adjacent to Pacman. The dots eaten by InvisiPac don’t count as Pacman’s score. Pacman’s task is to eat as many food pellets as possible.   (i) Which of the following is best suited to model this problem from Pacman’s perspective?  state space search           CSP            minimax game            MDP                 RL  InvisiPac moves to each adjacent square randomly with probability 1/4 . From pacman’s point of view, it is a MDP problem with the transition function reflecting this uncertainty.  (ii) What is the size of a minimal state space for this problem? Give your answer as a product of factors that reference problem quantities such as M, N, F, etc. as appropriate. Below each factor, state the information it encodes. For example, you might write 4 × MN and write number of directions underneath the first term and Pacman’s position under the second. 

 (b) For this subquestion, whenever InvisiPac moves, it always moves into the same square relative to Pacman. For example, if InvisiPac starts one square North of Pacman, InvisiPac will always move into the square North of Pacman. Pacman knows that InvisiPac is stuck this way, but doesn’t know which of the four relative locations he is stuck in. As before, if InvisiPac ends up being in a square with a food pellet, it will eat it and Pacman will thereby find out InvisiPac’s location. Pacman’s task is to find a strategy that minimizes the worst­case number of moves it could take before Pacman knows InvisiPac’s location.   (i)  Which of the following is best suited to model this problem from Pacman’s perspective?  state space search           CSP            minimax game            MDP                 RL  

10 

Page 11: CS 232 Review Materials with Answers [Part 1]cs.wellesley.edu/~cs232/2015/pages/ReviewMaterial1with...Q7: Alpha beta pruning For each of the game trees shown below, state for which

The invisiPac will be stuck in one of the four squares relative to Pacman. It is a search problem and the state space includes the boolean vector for which each of the four locations invisiPac might be. The goal is to reach a state in which there is only one possible location the invisiPac can be.  (ii) What is the size of a minimal state space for this problem? Give your answer as a product of factors that reference problem quantities such as M, N, F, etc. as appropriate. Below each factor, state the information it encodes.  

 Another acceptable solution is to replace 2^4 with 4. In general, one can say that because there are four locations (N,S,E,W) and invisiPac can or cannot be there, so each variable can be 0 or 1, then we get 2^4. However, in this case, we know that since invisiPac can be only in one location at a time, there can be only four configurations of the boolean vector: [1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1].  (c) For this subquestion, whenever InvisiPac moves, it can choose freely between any of the four squares adjacent to Pacman. InvisiPac tries to eat as many food pellets as possible. Pacman’s task is to eat as many food pellets as possible.   (i) Which of the following is best suited to model this problem from Pacman’s perspective?  state space search           CSP            minimax game            MDP                 RL  InvisiPac tries to eat as many food pellets as possible, thus plays adversarially. It is a minimax game problem.  (ii) What is the size of a minimal state space for this problem? Give your answer as a product of factors that reference problem quantities such as M, N, F, etc. as appropriate. Below each factor, state the information it encodes.  

 

11