A1

pdf

School

San Diego State University *

*We aren’t endorsed by this school

Course

150

Subject

Computer Science

Date

Feb 20, 2024

Type

pdf

Pages

5

Uploaded by JudgeDeerMaster402

Report
CS 450 A RTIFICIAL I NTELLIGENCE P ROFESSOR Y U , C OURTESY OF P ROFESSOR R OCH 1 Part I Do this part on your own. Remember, that as always, you must write answers in your own words. Failure to do so is plagiarism. Questions 1-3,7, 10 points each, 4-6 are 20 points each 1. Williams and Kessler state that most defects in work produced by pair programmers occurs under what circumstances? 2. What is the role suggested by Williams and Kessler for the person who is not currently using the keyboard? 3. Williams and Kessler state that extreme programmers have “slide the keyboard/don’t move the chairs rule.” Why is the ability to slide the keyboard back and forth advantageous? 4. What kind of agent is the Pacman agent described in Part II? Looking at the elements of a learning agent, what part of a learning agent do the requirements specified in Part II implement? Justify your answer briefly. 5. Put yourself in the position of a learning element. Propose one change that you might propose for the Pacman agent of part II. For up to 5 points extra credit, write pseudocode that describes how your agent would be modified. (You might have fun actually implementing this as a different agent type, but do not modify the behavior of the specified for TimidAgent as you will lose points for implementing something that does not match the specified behavior.) 6. A cash register is equipped with a learning agent that scans bills that are put in the cash drawer for counterfeit bills. Is such an agent most likely to be an episodic or a sequential agent? Justify your answer. 7. Describe the difference between goal-based and utility-based agents. Part II Getting your feet wet with Python & Agents (100 points) You may pair program (teams of two people) in this part. You must have read Williams and Kessler before starting to pair program. In this assignment, you will use a Pacman framework developed by UC Berkeley to implement a simple agent that will manage to evade Pacman ghosts. If you have never played Pacman, a brief synopsis is available on Wikipedia . The Berkeley version implements a variant of the game and may be downloaded from the assignment page on Canvas. Your task in this assignment is to implement a simple agent to help avoid the ghosts. Part of this assignment will be reading other people’s code. The pacman game can be started by executing pacman.py, e.g. python pacman.py. Pacman supports a wide variety of arguments, most of which you will not be needing in this assignment. For this assignment you only need to use one argument, the --pacman argument which specifies the name of your agent class. In this case, you will write an agent class called TimidAgent that must be stored in myAgents.py. It is suggested that you look at one reflex agent that is provided for you, the LeftTurnAgent that is stored in pacmanagents.py. Try running it and look at the code to see what it is doing. It will probably be helpful to use a symbolic debugger to set breakpoints and examine values. Note
CS 450 A RTIFICIAL I NTELLIGENCE P ROFESSOR Y U , C OURTESY OF P ROFESSOR R OCH 2 that in most IDEs, you need to configure the IDE to start the program with your desired options. Here’s an example in PyCharm for running LeftTurnAgent: Figure 1 - Configuring command line options in PyCharm. Dialog is accessed from the project dropdown above the code window or through the menu Run Edit Configurations. Other IDEs have similar methods. You may also need to configure which Python to use, see the last few minutes of the Quick and Dirty Python video for help with configuring this. Here’s an example in VSCode for running LeftTurnAgent:
CS 450 A RTIFICIAL I NTELLIGENCE P ROFESSOR Y U , C OURTESY OF P ROFESSOR R OCH 3 Note that this execution configuration sets the Pacman’s board layout as well. It is not required, but you can play with any of the configurations in the layouts directory. Just for fun, you can specify KeyboardAgent (from keyboardAgents.py) if you want to play the game yourself using the keyboard cursor arrow keys. TimidAgent should be based on the LeftTurnAgent with one difference. Each time the game invokes nextAction, nextAction will make a call for each ghost to see if the pacman is in danger. Your method TimidAgent.inDanger must have the signature in the skeleton code that is provided for you. It takes two formal arguments and one optional one. The first agent should be an AgentState representing the pacman. The second agent should be an AgentState of one of the ghosts. The last argument, dist, specifies how close ghosts must be to the pacman before it is considered to be in danger and this value defaults to 3 if keyword formal argument is not passed. We consider the pacman to be in danger when both of the following conditions are met: 1. The ghost and the pacman are in the same row or column. 2. The ghost is within dist units (formal argument to the method) of the pacman. 3. The ghost is not frightened (see the Ghost state for how to check for this). When the pacman is in danger, inDanger returns the compass direction from the pacman to the ghost (Figure 2). Method inDanger returns the Directions.Stop when the pacman is not in danger. Figure 2 - Pacman is in danger from the East. inDanger() would return Directions.East when invoked with the pacman state and the blue ghost state. If the blue ghost was scared or if the ghost was farther than dist units away, inDanger would return Directions.Stop which indicates that no evasive action needs to be taken.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
CS 450 A RTIFICIAL I NTELLIGENCE P ROFESSOR Y U , C OURTESY OF P ROFESSOR R OCH 4 Method getAction should check for the pacman being in danger from each of the ghosts using inDanger. The states can be obtained from the GameState object that will be bound to getAction’s formal argument state. See methods getPacmanState() and getGhostStates() in pacman.GameState which will be helpful for finding the agent states. Note that getGhostStates() returns a list of states. As inDanger checks for one ghost at a time, you will need to process the ghost states sequentially in the same order as they are returned by getGhostStates(). The first time the pacman is in danger, a decision is made. Based on the direction from which the pacman is in danger, we select a new direction. We check for legal directions in the following order: reversing the current direction, turning to the left, then turning to the right. If none of these are legal, we continue in the direction of the danger, or stop if no move is legal (only possible in contrived boards). In the example above, the pacman is in danger from the East. Reversing the danger direction is not legal, nor is heading North (left turn from East), but the right turn to the danger direction (South) is possible and TimidAgent should return Directions.South for this case. When the pacman is not in danger, it should function n the same manner as the LeftTurnAgent. That is, it turns left whenever possible. If a left turn is not possible it continues straight until it can’t go any further in the current direction . When the pacman cannot go left or forward, then it tries to turn right, and if necessary turns around. If no action is possible, getAction returns Directions.Stop. There is a lot of code that is designed for scaffolding that you do not need to read. You should concentrate on reading and understanding the following files: pacman.py This is the program’s entry module. When pacma n.py is given as an argument to python, it will start executing code in the “if __name__ == ‘’__main__’’ block. Get a feeling for GameState, there are useful get methods such as getGhostStates. You might want to read some of the other code here as well. game.py The Agent, AgentState and Directions classes are relevant to your assignment. Your TimidAgent should be derived from Agent, and both AgentState and Directions are useful for solving the problem. pacmanAgent.py Read LeftTurnAgent. For an example of what I consider to be an appropriate level of commenting, please read LeftTurnAgent. Most of this code was written by others and the code is commented. Not all of this is at the level of commenting that I would like to see. However, experience on very large software projects has led me to see the value in good commenting and I have commented LeftTurnAgent to the level at which I would like to see you comment your code. What to turn in: Part I: Submit your answers as a Word or PDF document to Canvas A1 Part I. Remember that everyone must work individually and that penalties will be applied as
CS 450 A RTIFICIAL I NTELLIGENCE P ROFESSOR Y U , C OURTESY OF P ROFESSOR R OCH 5 outlined in the syllabus should you plagiarize. If you have any concerns about what plagiarism means, take the SDSU plagiarism tutorial . Part II: Submit two files to gradescope via the Canvas link: o Your solo or pair affidavit, see Assignments-CS450-2024.pdf on Canvas or visit submitting work for details. o Your myAgents.py file. Do not submit the rest of the Pacman program. Your file must be interpretable by Python, as it will be uploaded to a virtual machine that will check your assignment for correct output. It is critical that you stick to the provided interfaces as these will be called directly to test your code. If you modify the interface, the tests will break, and you will not receive credit. Warning: It is not difficult to make a smarter agent than this one, but you will be graded on TimidAgent being implemented to the specification above. If you are having fun and want to write a smarter agent, write another class (e.g., EinsteinAgent). We will be learning things throughout the semester that can help you make a smarter agent than this one.