讲解:COMP 4200/5430、data、Python、PythonSQL|Database

Project 2 - Multi-Agent Search - COMP 4200/5430: Artificial Intelligence, Spring 20201/10Project 2: Multi-Agent Search (due 3/6 at 11:00pm)Table of ContentsIntroductionWelcomeQ1: Reflex AgentQ2: MinimaxQ3: Alpha-Beta PruningQ4: ExpectimaxQ5: Evaluation FunctionSubmissionPacman, now with ghosts.Minimax, Expectimax,EvaluationIntroductionIn this project, you will design agents for the classic version of Pacman, including ghosts.Along the way, you will implement both minimax and expectimax search and try your handat evaluation function design.The code base has not changed much from the previous project, but please start with afresh installation, rather than intermingling files from project 1.As in project 1, this project includes an autograder for you to grade your answers on yourmachine. This can be run on all questions with the command:https://inst.eecs.berkeley.edu/~cs188/sp19/project2.html2/20/20202/10python autograder.pyNote: If your python refers to Python 2.7, you may need to invoke python3autograder.py (and similarly for all subsequent Python invocations) or create a condaenvironment as described in Project 0 (project0.html#Installation).It can be run for one particular question, such as q2, by:python autograder.py -q q2It can be run for one particular test by commands of the form:python autograder.py -t test_cases/q2/0-small-treeBy default, the autograder displays graphics with the -t option, but doesnt with the -qoption. You can force graphics by using the --graphics flag, or force no graphics byusing the --no-graphics flag.See the autograder tutorial in Project 0 for more information about using the autograder.The code for this project contains the following files, available as a zip archive(assets/files/multiagent.zip).Files youll edit:multiAgents.py Where all of your multi-agent search agents will reside.Files you might want to look at:pacman.py The main file that runs Pacman games. This file alsodescribes a Pacman GameState type, which you will useextensively in this project.game.py The logic behind how the Pacman world works. This filedescribes several supporting types like AgentState, Agent,Direction, and Grid.util.py Useful data structures for implementing search algorithms.You dont need to use these for this project, but may findother functions defined here to be useful.Supporting files you can ignore:graphicsDisplay.py Graphics for PacmangraphicsUtils.py Support for Pacman graphics2/20/20203/10textDisplay.py ASCII graphics for PacmanghostAgents.py Agents to control ghostskeyboardAgents.py Keyboard interfaces to control Pacmanlayout.py Code for reading layout files and storing their contentsautograder.py Project autogradertestParser.py Parses autograder test and solution filestestClasses.py General autograding test classestest_cases/ Directory containing the test cases for each questionmultiagentTestClasses.py Project 2 specific autograding test classesFiles to Edit and Submit: You will fill in portions of multiAgents.py during theassignment. Once you have completed the assignment, you will submit a token generatedby submission_autograder.py . Please do not change the other files in this distributionor submit any of our original files other than this file.Evaluation: Your code will be autograded for technical correctness. Please do not changethe names of any provided functions or classes within the code, or you will wreak havocon the autograder. However, the correctness of your implementation -- not theautograders judgements -- will be the final judge of your score. If necessary, we willreview and grade assignments individually to ensure that you receive due credit for yourwork.Academic Dishonesty: We will be checking your code against other submissions in theclass for logical redundancy. If you copy someone elses code and submit it with minorchanges, we will know. These cheat detectors are quite hard to fool, so please dont try.We trust you all to submit your own work only; please dont let us down. If you do, we willpursue the strongest consequences available to us.Getting Help: You are not alone! If you find yourself stuck on something, contact thecourse staff for help. Office hours, section, and the discussion forum are there for yoursupport; please use them. If you cant make our office hours, let us know and we willschedule more. We want these projects to be rewarding and instructional, not frustratingand demoralizing. But, we dont know when or how to help unless you ask.Discussion: Please be careful not to post spoilers.Welcome to Multi-Agent PacmanFirst, play a game of classic Pacman by running the following command:2/20/20204/10python pacman.pyand using the arrow keys to move. Now, run the provided ReflexAgent inmultiAgents.pypython pacman.py -p ReflexAgentNote that it plays quite poorly even on simple layouts:python pacman.py -p ReflexAgent -l testClassicInspect its code (in multiAgents.py ) and make sure you understand what its doing.Question 1 (4 points): Reflex AgentImprove the ReflexAgent in multiAgents.py to play respectably. The provided reflexagent code provides some helpful examples of methods that query the GameState forinformation. A capable reflex agent will have to consider both food locations and ghostlocations to perform well. Your agent should easily and reliably clear the testClassiclayout:python pacman.py -p ReflexAgent -l testClassicTry out your reflex agent on the default mediumClassic layout with one ghost or two(and animation off to speed up the display):python pacman.py --frameTime 0 -p ReflexAgent -k 1python pacman.py --frameTime 0 -p ReflexAgent -k 2How does your agent fare? It will likely often die with 2 ghosts on the default board, unlessyour evaluation function is quite good.Note: Remember that newFood has the function asList()Note: As features, try the reciprocal of important values (such as distance to food) ratherthan just the values themselves.Note: The evaluation function youre writing is evaluating state-action pairs; in later partsof the project, youll be evaluating states.2/20/20205/10Note: You may find it useful to view the internal contents of various objects for debugging.You can do this by printing the objects string representations. For example, you can printnewGhostStates with print(newGhostStates) .Options: Default ghosts are random; you can also play for fun with slightly smarterdirectional ghosts using -g DirectionalGhost . If the randomness is preventing youfrom telling whether your agent is improving, you can use -f to run with a fixed randomseed (same random choices every game). You can also play multiple games in a row with-n . Turn off graphics with -q to run lots of games quickly.Grading: We will run your agent on the openClassic layout 10 times. You will receive 0points if your agent times out, or never wins. You will receive 1 point if your agent wins atleast 5 times, or 2 points if your agent wins all 10 games. You will receive an addition 1point if your agents average score is greater than 500, or 2 points if it is greater than1000. You can try your agent out under these conditions withpython autograder.py -q q1To run it without graphics, use:python autograder.py -q q1 --no-graphicsDont spend too much time on this question, though, as the meat of the project lies ahead.Question 2 (5 points): MinimaxNow you will write an adversarial search agent in the provided MinimaxAgent class stubin multiAgents.py . Your minimax agent should work with any number of ghosts, soyoull have to write an algorithm that is slightly more general than what youve previouslyseen in lecture. In particular, your minimax tree will have multiple min layers (one for eachghost) for every max layer.Your code should also expand the game tree to an arbitrary depth. Score the leaves ofyour minimax tree with the supplied self.evaluationFunction , which defaults toscoreEvaluationFunction . MinimaxAgent extends MultiAgentSearchAgent , whichgives access to self.depth and self.evaluationFunction . Make sure your minimaxcode makes reference to these two variables where appropriate as these variables arepopulated in response to command line options.Important: A single search ply is considered to be one Pacman move and all the ghostsresponses, so depth 2 search will involve Pacman and each ghost moving two times.Grading: We will be checking your code to determine whether it explores the correctnumber of game state代写COMP 4200/5430作业、代做data课程作业、代写Python实验作业、Python程序设计作业调试 代做s. This is the only reliable way to detect some very subtle bugs inimplementations of minimax. As a result, the autograder will be very picky about how2/20/20206/10many times you call GameState.generateSuccessor . If you call it any more or less thannecessary, the autograder will complain. To test and debug your code, runpython autograder.py -q q2This will show what your algorithm does on a number of small trees, as well as a pacmangame. To run it without graphics, use:python autograder.py -q q2 --no-graphicsHints and ObservationsHint: Implement the algorithm recursively using helper function(s).The correct implementation of minimax will lead to Pacman losing the game in sometests. This is not a problem: as it is correct behaviour, it will pass the tests.The evaluation function for the Pacman test in this part is already written( self.evaluationFunction ). You shouldnt change this function, but recognize thatnow were evaluating states rather than actions, as we were for the reflex agent. Lookaheadagents evaluate future states whereas reflex agents evaluate actions from thecurrent state.The minimax values of the initial state in the minimaxClassic layout are 9, 8, 7, -492 fordepths 1, 2, 3 and 4 respectively. Note that your minimax agent will often win (665/1000games for us) despite the dire prediction of depth 4 minimax.python pacman.py -p MinimaxAgent -l minimaxClassic -a depth=4Pacman is always agent 0, and the agents move in order of increasing agent index.All states in minimax should be GameStates , either passed in to getAction orgenerated via GameState.generateSuccessor . In this project, you will not beabstracting to simplified states.On larger boards such as openClassic and mediumClassic (the default), youll findPacman to be good at not dying, but quite bad at winning. Hell often thrash aroundwithout making progress. He might even thrash around right next to a dot without eating itbecause he doesnt know where hed go after eating that dot. Dont worry if you see thisbehavior, question 5 will clean up all of these issues.When Pacman believes that his death is unavoidable, he will try to end the game as soonas possible because of the constant penalty for living. Sometimes, this is the wrong thingto do with random ghosts, but minimax agents always assume the worst:python pacman.py -p MinimaxAgent -l trappedClassic -a depth=3Make sure you understand why Pacman rushes the closest ghost in this case.Question 3 (5 points): Alpha-Beta Pruning2/20/20207/10Make a new agent that uses alpha-beta pruning to more efficiently explore the minimaxtree, in AlphaBetaAgent . Again, your algorithm will be slightly more general than thepseudocode from lecture, so part of the challenge is to extend the alpha-beta pruninglogic appropriately to multiple minimizer agents.You should see a speed-up (perhaps depth 3 alpha-beta will run as fast as depth 2minimax). Ideally, depth 3 on smallClassic should run in just a few seconds per moveor faster.python pacman.py -p AlphaBetaAgent -a depth=3 -l smallClassicThe AlphaBetaAgent minimax values should be identical to the MinimaxAgent minimaxvalues, although the actions it selects can vary because of different tie-breaking behavior.Again, the minimax values of the initial state in the minimaxClassic layout are 9, 8, 7 and-492 for depths 1, 2, 3 and 4 respectively.Grading: Because we check your code to determine whether it explores the correctnumber of states, it is important that you perform alpha-beta pruning without reorderingchildren. In other words, successor states should always be processed in the orderreturned by GameState.getLegalActions . Again, do not callGameState.generateSuccessor more than necessary.You must not prune on equality in order to match the set of states explored by ourautograder. (Indeed, alternatively, but incompatible with our autograder, would be to alsoallow for pruning on equality and invoke alpha-beta once on each child of the root node,but this will not match the autograder.)The pseudo-code below represents the algorithm you should implement for this question.To test and debug your code, runpython autograder.py -q q3This will show what your algorithm does on a number of small trees, as well as a pacmangame. To run it without graphics, use:2/20/20208/10python autograder.py -q q3 --no-graphicsThe correct implementation of alpha-beta pruning will lead to Pacman losing some of thetests. This is not a problem: as it is correct behaviour, it will pass the tests.Question 4 (5 points): ExpectimaxMinimax and alpha-beta are great, but they both assume that you are playing against anadversary who makes optimal decisions. As anyone who has ever won tic-tac-toe can tellyou, this is not always the case. In this question you will implement theExpectimaxAgent , which is useful for modeling probabilistic behavior of agents whomay make suboptimal choices.As with the search and constraint satisfaction problems covered so far in this class, thebeauty of these algorithms is their general applicability. To expedite your owndevelopment, weve supplied some test cases based on generic trees. You can debug yourimplementation on small the game trees using the command:python autograder.py -q q4Debugging on these small and manageable test cases is recommended and will help youto find bugs quickly.Once your algorithm is working on small trees, you can observe its success in Pacman.Random ghosts are of course not optimal minimax agents, and so modeling them withminimax search may not be appropriate. ExpectimaxAgent , will no longer take the minover all ghost actions, but the expectation according to your agents model of how theghosts act. To simplify your code, assume you will only be running against an adversarywhich chooses amongst their getLegalActions uniformly at random.To see how the ExpectimaxAgent behaves in Pacman, run:python pacman.py -p ExpectimaxAgent -l minimaxClassic -a depth=3You should now observe a more cavalier approach in close quarters with ghosts. Inparticular, if Pacman perceives that he could be trapped but might escape to grab a fewmore pieces of food, hell at least try. Investigate the results of these two scenarios:python pacman.py -p AlphaBetaAgent -l trappedClassic -a depth=3 -q -n 10python pacman.py -p ExpectimaxAgent -l trappedClassic -a depth=3 -q -n 102/20/20209/10You should find that your ExpectimaxAgent wins about half the time, while yourAlphaBetaAgent always loses. Make sure you understand why the behavior here differsfrom the minimax case.The correct implementation of expectimax will lead to Pacman losing some of the tests.This is not a problem: as it is correct behaviour, it will pass the tests.Question 5 (6 points): Evaluation FunctionWrite a better evaluation function for pacman in the provided functionbetterEvaluationFunction . The evaluation function should evaluate states, ratherthan actions like your reflex agent evaluation function did. You may use any tools at yourdisposal for evaluation, including your search code from the last project. With depth 2search, your evaluation function should clear the smallClassic layout with one randomghost more than half the time and still run at a reasonable rate (to get full credit, Pacmanshould be averaging around 1000 points when hes winning).Grading: the autograder will run your agent on the smallClassic layout 10 times. We willassign points to your evaluation function in the following way:If you win at least once without timing out the autograder, you receive 1 points. Any agentnot satisfying these criteria will receive 0 points.+1 for winning at least 5 times, +2 for winning all 10 times+1 for an average score of at least 500, +2 for an average score of at least 1000 (includingscores on lost games)+1 if your games take on average less than 30 seconds on the autograder machine, whenrun with --no-graphics . The autograder is run on EC2, so this machine will have a fairamount of resources, but your personal computer could be far less performant (netbooks)or far more performant (gaming rigs).The additional points for average score and computation time will only be awarded if youwin at least 5 times.You can try your agent out under these conditions withpython autograder.py -q q5To run it without graphics, use:python autograder.py -q q5 --no-graphicsSubmissionIn order to submit your project, run python submission_autograder.py and submit thegenerated token file multiagent.token to the Project 2 assignment on Gradescope.转自:http://www.5daixie.com/contents/9/3136.html

你可能感兴趣的:(讲解:COMP 4200/5430、data、Python、PythonSQL|Database)