墨尔本大学COMP20003Assignment2课业解析

  • May 15, 2020

墨尔本大学COMP20003Assignment2课业解析 题意: 为Pacman吃豆人游戏实现AI算法寻找得分最高的策略 解析: 原游戏中,玩家控制Pacman在没有出口的迷宫里收集豆子dot(C表示玩家,‘.’表示豆子),尽可能得到更高的分。同时要躲避四个不同颜色的幽灵(&代表),碰到它们就会死亡(玩家有3条生命),敌人不会摧毁豆子,但会暂时占据豆子的位置,幽灵自动追杀Pacman。玩家并不是待宰的羔羊,迷宫里散布着一些水果(*表示),Pacman吃下水果后变身超人,在一定时间内所有幽灵会变成深蓝色并逃离Pacman,但它们速度更慢,Pacman可以杀死它们并获得高额奖励分。同一个水果持续的超人时间内,连续击杀幽灵奖励翻倍,第一个幽灵200分,第四个幽灵就是1600分。现在要求你实现给出的GraphSearch算法,为Pacman找到得分最高的路径。 涉及知识点:Dijkstra算法、图、队列 更多可加微信讨论 微信号g19963812037pdf 

COMP20003 Algorithms and Data StructuresSecond (Spring) Semester 2019[Assignment 2]Solving Pac-Man:online Graph SearchHanded out: Thursday, 10 of OctoberDue: 00:00, Thursday, 24 of OctoberPurposeThe purpose of this assignment is for you to:• Increase your proficiency in C programming, your dexterity with dynamic memory allocation andyour understanding of data structures, through programming a search algorithm over Graphs.• Gain experience with applications of graphs and graph algorithms to solving games, one form ofartificial intelligence.Assignment descriptionIn this programming assignment you’ll be expected to build an AI algorithm to solve Pac-Man. Thegame invented in 1980 is one of the classics among arcade games. You can play the game compilingthe code given to you using the keyboard, or using this web implementation.The code in this assignment was adapted from the open-source terminal version made available byMike Billars1 and the original version can be installed as a standard package in Ubuntu2.The Pac-Man gameAs explained in the wikipedia entry, The player navigates Pac-Man through a maze with no deadends. The maze is filled with Pac-Dots, and includes four roving multi-colored ghosts: Blinky, Pinky,Inky, and Clyde.The objective of the game is to accumulate as many points as possible by eating dots, fruits, andghosts. When all of the dots in a stage are eaten, that stage is completed, and the player will advanceto the next. The four ghosts roam the maze and chase Pac-Man. If any of the ghosts touches Pac-Man,a life is lost. When all lives have been lost, the game is over.Pac-Man can eat a fruit first and then eat the ghosts for a fixed period of time to earn bonus points.The enemies turn deep blue, reverse direction and move away from Pac-Man, and usually move moreslowly. When an enemy is eaten, its eyes return to the center ghost box where the ghost is regeneratedin its normal color. The bonus score earned for eating a blue ghost increases exponentially for eachconsecutive ghost eaten while a single energizer is active: a score of 200 points is scored for eating oneghost, 400 for eating a second ghost, 800 for a third, and 1600 for the fourth.The level id and a scoreboard can be found on the lower part. The information in the last three linesof the screen reveals information about the algorithm execution.The game is won when all dots have been eaten. An AI agent or human player can change the directionof Pac-Man movements.1https://sites.google.com/site/doctormike/pacman.html2https://packages.ubuntu.com/xenial/games/pacman4consoleFigure 1: The UI of the Terminal version. c is pacman, & are ghosts, * are fruits, and . is a regularfood.The AlgorithmEach possible configuration of the Pac-Man game 29×28 grid and other relevant information such asthe direction of pacman movements, number of lives left, etc. is called a state. The Pac-Man GraphG = hV; Ei is implicitly defined. The vertex set V is defined as all the possible configurations (states),and the edges E connecting two vertexes are defined by the legal movements (right, left, up, down).Your task is to find the path leading to the highest score, i.e. leading to the most rewarding vertex(state). A path is a sequence of movements. You are going to use a variant of Dijkstra to explorethe most rewarding path first, up to a maximum budget B of expanded/explored nodes (nodes forwhich you’ve already generated its children).Every time the game asks you for a movement (action), you should explore all possible paths untilconsuming the budget B if possible. Once you finished generating all the paths, you should return thefirst action only of the path leading to the highest score vertex. This action will then be executedby the game engine.You might have multiple paths with the same maximum score. If more than one action (left,right,upor down) begins paths with the same maximum score, you’ll have to break ties randomly.Make sure you manage the memory well. Everytime you finish running the algorithm, you have tofree all the nodes from the memory, otherwise you are going to run out of memory fairly fast or causememory leaks.GraphSearch(Graph; start; budget)1 node start2 explored empty Array3 frontier priority Queue Containing node Only4 while frontier 6= empty5 do6 node frontier:pop()7 explored:add(node)8 if size(explored) < budget9 then10 for each APPLICABLE action a 2 fLeft; Right; Up; Downg11 do12 newNode applyAction(node)13 propagateBackScoreToFirstAction(newNode)14 if lostLife(newNode)15 then16 delete newNode17 else18 frontier:add(newNode)1920 freeMemory(explored)21 bestAction select best action breaking ties randomly22 return bestActionFigure 2: Online Graph algorithm variant of DijkstraEvery time that you consider all the actions that can be applied for a given node, only use the onesthat will face Pac-Man towards a free tile. For example, in Figure 1 you should only consider theactions Left, and Right.When you applyAction you have to create a new node, that1. points to the parent,2. updates the state with the action chosen,3. updates the priority (used by the priority queue) of the node to be the negative node’s depth d(if the node is the dth step of the path, then its priority is -d). This ensures the expansion ofthe shortest paths first, as the priority queue provided is a max heap;4. updates the reward to be r(n) = (h(n) + score(n) - score(nParent)) × γd(a) the heuristic value h(n) that biases the reward to account for losing lives and eating fruits,plus(b) the change in score from the current node and the parent node(c) times a discount factor of γ = 0:99d, where d is the depth of the node,5. updates the accumulated reward from the initial node up to the current node, and6. updates any other auxiliary data in the node.The heuristic function is h(n) = i - l - g, where i = 10 if Pac-Man has eaten a fruit and becomesinvincible in that state; l = 10 if a life has been lost in that state; and g = 100 if the game is over.Otherwise i = l = g = 0.You are going to need some auxiliary data structures to update the scores of the first 4 applicableactions. The function propagateBackScoreToFirstAction takes the score of the newly generatednode, and propagates back the score to the first action of the path.This propagation can be either Maximize or Average :• If you Maximize, you have to make sure that the first action is updated to reflect the maximumscore of any of its children.• If you Average, you have to make sure that the first action is updated to reflect the averagescore taking into account all its children.Deliverables, evaluation and delivery rulesDeliverable 1 { Solver source codeYou are expected to hand in the source code for your solver, written in C. Obviously, your source codeis expected to compile and execute flawlessly using the following makefile command: make generatingan executable called pacman. Remember to compile using the optimization flag gcc -O3 for doingyour experiments, it will run twice faster than compiling with the debugging flag gcc -g. For thesubmission, please submit your makefile with gcc -g option, as our scripts need this flag fortesting. Your program must not be compiled under any flags that prevents it from working under gdbor valgrindYour implementation should work well over the standard levels, but might fail to perform well in someof our provided t *.dat levels. The t * levels are specifically designed to test challenging situations.Try different budgets and explain why your agent works well (or doesn’t) in each of the test cases.Base CodeYou are given a base code. You can compile the code and play with the keyboard. The default solverchooses an action randomly. You are going to have to program your solver in the file ai.c. Look at thefile pacman.c (MainLoop function) to know which function is called to select an action to execute.You are given the structure of a node, the state, and also a priority queue implementation. Look intothe utils.* files to know about the functions you can call to apply an action to update a game state.You are free to change any file.InputYou can play the game with the keyboard by executing./pacman where level 2 f0; : : : ; 9g for standard levels, or the path to a file.dat levelIn order to execute your solver use the following command:./pacman Where ai pause calls your algorithm and pauses the game to allow playing one step at a time. is either max or avg, to select the 2 options for propagating scores, and is aninteger number indicating the budget of your search.for example:./pacman 3 ai max 1000Will run max updates after expanding a 1000 nodes on Levels/level03.dat file../pacman LevelsTest/t buridans ass.dat ai pause avg 1000Will run average updates after expanding a 1000 nodes on LevelsTest/t buridans ass.dat file,and pause.OutputYour solver will print into an output.txt file the following information:1. Max Depth2. Number of generated nodes.3. Number of expanded nodes.4. Number of expanded nodes per second.5. Total Search Time, in seconds.6. Maximum value in the board.7. ScoreFor example, the output of your solver ./pacman ai max 1000 could be:Propagation=MaxBudget=1000MaxDepth = 8TotalGenerated = 499,911TotalExpanded = 253,079Time = 7.05 secondsExpanded/Second = 35,897Score=543These numbers are made up. MaxDepth stands for the node with maximum depth generated byyour algorithm across the game. Expanded/Second can be computed by dividing the total number ofexpanded nodes by the time it took to play the game. A node is expanded if it was popped out fromthe priority queue, and a node is generated if it was created using the applyAction function. You canprint all this information in the function ExitProgram in pacman.cDeliverable 2 { ExperimentationBesides handing in the solver source code, you’re required to provide a table with the mean score anddeviation (if any), mean expanded/second and deviation, and total execution time for each type ofpropagation (max/avg) you implement and each max budget of 10,100,1000,2000.In order to test your solver, you have to average over multiple runs because pacman has a randomcomponent: the movement of the ghosts. A sample of 3 runs is enough for the purpose of thisassignment. Test at least 3 different Levels.For each propagation type, plot a figure where the x axis is the budget, and y is the mean score.Explain your results using your figures and tables. Which max/avg budget works best? Is it betterto propagate max or avg?If you do any of the optimizations for the extra mark, please report and discuss it inyour experimentation.Answer concisely. Please include your Username, Student ID and Full Name in your Document.EvaluationAssignment marks will be divided into three different components.1. Solver (11)2. Code Style (1)3. Experimentation (3)Please note that you should be ready to answer any question we might have on the details of yourassignment solution by e{mail, or even attending a brief interview with me, in order to clarify anydoubts we might have.Code StyleYou can improve the base code according to the guidelines given in the first assignments. Feel freeto add comments wherever you find convenient. From your comments it should be very clear exactlywhich lines implement each line of the pseudocode. The base code was minimally modified to alloweasy deployment of your AI algorithm and the coding style belongs to the original author.Delivery rulesYou will need to make two submissions for this assignment:• Your C code files (including your Makefile) will be submitted through the LMS page for thissubject: Assignments ! Assignment 2 ! Assignment 2: Code.• Your experiments report file will be submitted through the LMS page for this subject: Assignments ! Assignment 2 ! Assignment 2: Experimentation. This file can be of any format, e.g..pdf, text or other.Program files submitted (Code)Submit the program files for your assignment and your Makefile.Your programs must compile and run correctly on the JupyterHub server. You may have developedyour program in another environment, but it still must run on the JupyterHub server at submissiontime. For this reason, and because there are often small, but significant, differences between compilers,it is suggested that if you are working in a different environment, you upload and test your code onthe JupyterHub server at reasonably frequent intervals.valgrind will report a memory leak as still reachable memory. This is a known issue with ncursesand won’t count as a leak. Make sure you maintain the other sections under Leak summary downto 0.A common reason for programs not to compile is that a file has been inadvertently omitted from thesubmission. Please check your submission, and resubmit all files if necessary.To compile in your local machine you need to install the library ncurses. Ncurses is needed for theterminal UI. If you are using WSL or Ubuntu, type the following command:sudo apt-get install libncurses5-dev libncursesw5-devPlagiarismThis is an individual assignment. The work must be your own.While you may discuss your program development, coding problems and experimentation with yourclassmates, you must not share files, as this is considered plagiarism.If you refer to published work in the discussion of your experiments, be sure to includea citation to the publication or the web link.\Borrowing” of someone else’s code without acknowledgement is plagiarism, e.x. taking code from a book without acknowledgement. Plagiarism is considered a serious offense at theUniversity of Melbourne. You should read the University code on Academic honesty and details onplagiarism. Make sure you are not plagiarizing, intentionally or unintentionally.You are also advised that there will be a C programming component (on paper, not on a computer) onthe final examination. Students who do not program their own assignments will be at a disadvantagefor this part of the examination.Administrative issuesWhen is late? What do I do if I am late? The due date and time are printed on the frontof this document. The lateness policy is on the handout provided at the first lecture and also available on the subject LMS page. If you decide to make a late submission, you should send an emaildirectly to the lecturer as soon as possible and he will provide instructions for making a late submission.What are the marks and the marking criteria Recall that this project is worth 15% of yourfinal score. There is also a hurdle requirement: you must earn at least 15 marks out of a subtotal of30 for the projects to pass this subject.Finally Despite all these stern words, we are here to help! There is information about getting helpin this subject on the LMS pages. Frequently asked questions about the project will be answered inthe LMS discussion group.Have Fun!COMP20003 team.  

LATEST POSTS
MOST POPULAR

ezAce多年来为广大留学生提供定制写作、留学文书定制、语法润色以及网课代修等服务,超过200位指导老师为您提供24小时不间断地服务。