Answered step by step
Verified Expert Solution
Question
1 Approved Answer
python Introduction In this project, your Pac-Man agent will find paths through his maze world, to reach a particular location and (optionally) to collect food
python
Introduction In this project, your Pac-Man agent will find paths through his maze world, to reach a particular location and (optionally) to collect food efficiently. You will build general search algorithms and apply them to Pac-Man scenarios. The code for this project consists of several Python files, some of which you will need to read and understand in order to complete the assignment, and some of which you can ignore. Files you'll edit: Where all of your search algorithms will reside. If you attempt the extra credit. Files you might want to look at: Where all of the search-based agents reside. The main file that runs Pac-Man games. This file describes a Pac-Man GameState type, which you use in this project. The logic behind how the Pac-Man world works. This file describes several supporting types like AgentState, Agent, Direction, and Grid. Useful data structures for implementing search algorithms. Supporting files you can ignore: Graphics for Pac-Man Support for Pac-Man graphics ASCII graphics for Pac-Man Agents to control ghosts Keyboard interfaces to control Pac-Man What to submit: You will fill in portions of (search.py and pitchers.py (optionally, for extra credit) during the assignment. You should submit nothing other than these one/two files. If you have trouble with the graphics and want to run your code without it, add a "- q " to the command line strings Warning: DO NOT import anything. Your code must not depend on any library not already included/imported. Also do not change the names of any provided functions or classes within the code. Welcome to Pac-Man After downloading the code (search.zip ), unzipping it and changing to the search directory, you should be able to play a game of Pac-Man by typing the following at the commanniline: python pacman.py Pac-Man lives in a shiny blue world of twisting corridors and tasty round treats. Navigating this world efficiently will be Pac-Man's first step in mastering his domain. The simplest agent in is called the which always goes West (a trivial reflex agent). This agent can occasionally win: python pacman.py --layout testlkaze -- pacman GoinestAgent But, things get ugly for this agent when turning is required: If pacman gets stuck, you can exit the game by typing CTRL-c into your terminal. Soon, your agent will solve not only but any maze you want. Note that supports a number of options that can each be expressed in a long way (e.g.4 lor a short way (e.g., You can see the list of all options and their default values via: python pacmon, py h In you'll find a fully implemented , which plans out a path through Pac-Man's world and then executes that path step-by-step. The search algorithms for formulating a plan are not implemented - that's your job. As you work through the following questions, you might need to refer to this glossary of objects in the code. First, test that the is working correctly by running: python pacnan.py 1 tinymaze -p Searchagent - a fn-tinyMazeSearch The command above tells the to use as its search algorithm, which is implemented in Pac-Man should navigate the maze successfully. Now it's time to write full-fledged generic search functions to help Pac-Man plan routes! Pseudocode for the search algorithms you'll write can be found in the lecture slides and textbook. I have already defined a node data type that contains not only a state but also the information necessary to reconstruct the path (plan) which gets to that state. Important note: All of your search functions need to return a list of actions that will lead the agent from the start to the goal. These actions all have to be legal moves (valid directions, no moving through walls). Hint: Each algorithm is very similar. Algorithms for DFS, BFS, UCS, and A differ only in the details of how the fringe is managed. So, concentrate on getting DFS right and the rest should be relatively straightforward. Indeed, one possible implementation requires only a single generic search method which is configured with an algorithm-specific queuing strategy. (Your implementation need not be of this form to receive full credit). Hint: Make sure to check out the and types provided to you in Question 1 (10 points) Implement the depth-first search (DFS) algorithm in the function in To make your algorithm complete, write the graph search version of DFS, which avoids expanding any already visited states (textbook section 3.5). Your code should quickly find a solution for: python pacman.py 1 tinymaze - p Searchagent python pacman, py 1 medivekaze p SearchAgent Expected results: Pathcost will probably be 10 in tinyMaze, 130 in mediumMaze, 210 in bigMaze. The Pac-Man board will show an overlay of the states explored, and the order in which they were explored (brighter red means earlier exploration). Is the exploration order what you would have expected? Does Pac-Man actually go to all the explored squares on his way to the goal? Hint: If you use a Stack as your data structure, the solution found by your DFS algorithm for should have a length of 130 (provided you push successors onto the fringe in the order provided by getSuccessors; you might get 246 if you push them in the reverse order). Is this a least cost solution? If not, think about what depth-first search is doing wrong. Question 2 (10 point) Implement the breadth-first search (BFS) algorithm in the function in Again, write a graph search algorithm that avoids expanding any already visited states. Test your code the same way you did for depth-first search. python pacman,py 1 mediumaze -p Searchigent a fnobfs python pacman.py l biglaze p SearchAgent a fn=bfs z.5 Expected results: Pathcost should be 68 in mediumMaze, 210 in bigMaze. Does BFS find a least cost solution? If not, check your implementation. Hint: If Pac-Man moves too slowly for you, try the option Note: If you've written your search code generically, your code should work equally well for the eight-puzzle search problem (textbook section 3.2 ) without any changes. python eightpuzzle.py A search Question 3 (20 points) Implement A*" graph search (see slide 17, chapter03b) in the empty function in A takes a heuristic function as an argument. Heuristics take two arguments: a state in the search problem (the main argument), and the problem itself (for reference information). The heuristic function in is a trivial example. Object Glossary Here's a glossary of the key objects in the code base related to search problems, for your reference: SearchProblem (search.py) A SearchProblem is an abstract object that represents the state space, successor function, costs, and goal state of a problem. You will interact with any SearchProblem only through the methods defined at the top of A specific type of SearchProblem that you will be working with -.. it corresponds to searching for a single pellet in a maze. A specific type of SearchProblem that you will define ... it corresponds to searching for a path through all four corners of a maze. A specific type of SearchProblem that you will be working with ... it corresponds to searching for a way to eat all the pellets in a maze. Search Function A search function is a function which takes an instance of SearchProblem as a parameter, runs some algorithm, and returns a sequence of actions that lead to a goal. Example of search functions are and which you have to write. You are provided which is a very bad search function that only works correctly on is a class which implements an Agent (an object that interacts with the world) and does its planning through a search function. The first uses the search function provided to make a plan of actions to take to reach the goal state, and then executes the actions one at a time. Introduction In this project, your Pac-Man agent will find paths through his maze world, to reach a particular location and (optionally) to collect food efficiently. You will build general search algorithms and apply them to Pac-Man scenarios. The code for this project consists of several Python files, some of which you will need to read and understand in order to complete the assignment, and some of which you can ignore. Files you'll edit: Where all of your search algorithms will reside. If you attempt the extra credit. Files you might want to look at: Where all of the search-based agents reside. The main file that runs Pac-Man games. This file describes a Pac-Man GameState type, which you use in this project. The logic behind how the Pac-Man world works. This file describes several supporting types like AgentState, Agent, Direction, and Grid. Useful data structures for implementing search algorithms. Supporting files you can ignore: Graphics for Pac-Man Support for Pac-Man graphics ASCII graphics for Pac-Man Agents to control ghosts Keyboard interfaces to control Pac-Man What to submit: You will fill in portions of (search.py and pitchers.py (optionally, for extra credit) during the assignment. You should submit nothing other than these one/two files. If you have trouble with the graphics and want to run your code without it, add a "- q " to the command line strings Warning: DO NOT import anything. Your code must not depend on any library not already included/imported. Also do not change the names of any provided functions or classes within the code. Welcome to Pac-Man After downloading the code (search.zip ), unzipping it and changing to the search directory, you should be able to play a game of Pac-Man by typing the following at the commanniline: python pacman.py Pac-Man lives in a shiny blue world of twisting corridors and tasty round treats. Navigating this world efficiently will be Pac-Man's first step in mastering his domain. The simplest agent in is called the which always goes West (a trivial reflex agent). This agent can occasionally win: python pacman.py --layout testlkaze -- pacman GoinestAgent But, things get ugly for this agent when turning is required: If pacman gets stuck, you can exit the game by typing CTRL-c into your terminal. Soon, your agent will solve not only but any maze you want. Note that supports a number of options that can each be expressed in a long way (e.g.4 lor a short way (e.g., You can see the list of all options and their default values via: python pacmon, py h In you'll find a fully implemented , which plans out a path through Pac-Man's world and then executes that path step-by-step. The search algorithms for formulating a plan are not implemented - that's your job. As you work through the following questions, you might need to refer to this glossary of objects in the code. First, test that the is working correctly by running: python pacnan.py 1 tinymaze -p Searchagent - a fn-tinyMazeSearch The command above tells the to use as its search algorithm, which is implemented in Pac-Man should navigate the maze successfully. Now it's time to write full-fledged generic search functions to help Pac-Man plan routes! Pseudocode for the search algorithms you'll write can be found in the lecture slides and textbook. I have already defined a node data type that contains not only a state but also the information necessary to reconstruct the path (plan) which gets to that state. Important note: All of your search functions need to return a list of actions that will lead the agent from the start to the goal. These actions all have to be legal moves (valid directions, no moving through walls). Hint: Each algorithm is very similar. Algorithms for DFS, BFS, UCS, and A differ only in the details of how the fringe is managed. So, concentrate on getting DFS right and the rest should be relatively straightforward. Indeed, one possible implementation requires only a single generic search method which is configured with an algorithm-specific queuing strategy. (Your implementation need not be of this form to receive full credit). Hint: Make sure to check out the and types provided to you in Question 1 (10 points) Implement the depth-first search (DFS) algorithm in the function in To make your algorithm complete, write the graph search version of DFS, which avoids expanding any already visited states (textbook section 3.5). Your code should quickly find a solution for: python pacman.py 1 tinymaze - p Searchagent python pacman, py 1 medivekaze p SearchAgent Expected results: Pathcost will probably be 10 in tinyMaze, 130 in mediumMaze, 210 in bigMaze. The Pac-Man board will show an overlay of the states explored, and the order in which they were explored (brighter red means earlier exploration). Is the exploration order what you would have expected? Does Pac-Man actually go to all the explored squares on his way to the goal? Hint: If you use a Stack as your data structure, the solution found by your DFS algorithm for should have a length of 130 (provided you push successors onto the fringe in the order provided by getSuccessors; you might get 246 if you push them in the reverse order). Is this a least cost solution? If not, think about what depth-first search is doing wrong. Question 2 (10 point) Implement the breadth-first search (BFS) algorithm in the function in Again, write a graph search algorithm that avoids expanding any already visited states. Test your code the same way you did for depth-first search. python pacman,py 1 mediumaze -p Searchigent a fnobfs python pacman.py l biglaze p SearchAgent a fn=bfs z.5 Expected results: Pathcost should be 68 in mediumMaze, 210 in bigMaze. Does BFS find a least cost solution? If not, check your implementation. Hint: If Pac-Man moves too slowly for you, try the option Note: If you've written your search code generically, your code should work equally well for the eight-puzzle search problem (textbook section 3.2 ) without any changes. python eightpuzzle.py A search Question 3 (20 points) Implement A*" graph search (see slide 17, chapter03b) in the empty function in A takes a heuristic function as an argument. Heuristics take two arguments: a state in the search problem (the main argument), and the problem itself (for reference information). The heuristic function in is a trivial example. Object Glossary Here's a glossary of the key objects in the code base related to search problems, for your reference: SearchProblem (search.py) A SearchProblem is an abstract object that represents the state space, successor function, costs, and goal state of a problem. You will interact with any SearchProblem only through the methods defined at the top of A specific type of SearchProblem that you will be working with -.. it corresponds to searching for a single pellet in a maze. A specific type of SearchProblem that you will define ... it corresponds to searching for a path through all four corners of a maze. A specific type of SearchProblem that you will be working with ... it corresponds to searching for a way to eat all the pellets in a maze. Search Function A search function is a function which takes an instance of SearchProblem as a parameter, runs some algorithm, and returns a sequence of actions that lead to a goal. Example of search functions are and which you have to write. You are provided which is a very bad search function that only works correctly on is a class which implements an Agent (an object that interacts with the world) and does its planning through a search function. The first uses the search function provided to make a plan of actions to take to reach the goal state, and then executes the actions one at a time Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started