{"id":96,"date":"2025-02-08T10:42:14","date_gmt":"2025-02-08T02:42:14","guid":{"rendered":"http:\/\/www.csdaixie.com\/?p=96"},"modified":"2025-02-08T10:42:14","modified_gmt":"2025-02-08T02:42:14","slug":"pacman","status":"publish","type":"post","link":"http:\/\/www.csdaixie.com\/index.php\/2025\/02\/08\/pacman\/","title":{"rendered":"Pacman"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><em>Coursework 1<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(Version 1.6)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Overview<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For this coursework, you will have to implement a classifier. You will use this classifier in some code<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">that has to make a decision. The code will be controlling Pacman, in the classic game, and the<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">decision will be about how Pacman chooses to move. Your classifier probably won\u2019t help Pacman<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">to make particularly good decisions (I will be surprised if it helps Pacman win games, my version<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">certainly didn\u2019t), but that is not the point. The point is to write a classifier and use it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No previous experience with Pacman (either in general, or with the specific UC Berkeley AI imple\u0002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">mentation that we will use) is required.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This coursework is worth 10% of the marks for the module.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note: <\/strong>Failure to follow submission instructions will result in a deduction of 10% of the marks you<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">earn for this coursework.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Getting started<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2.1 Start with Pacman<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Pacman code that we will be using for the coursework was developed at UC Berkeley for their AI<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">course. The folk who developed this code then kindly made it available to everyone. The homepage<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">for the Berkeley AI Pacman projects is here:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">http:\/\/ai.berkeley.edu\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note that we will <strong>not <\/strong>be doing any of their projects. Note also that the code only supports Python<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3, so that is what we will use.1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You should:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(a) Download:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">pacman-cw1.zip<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">from KEATS.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(b) Save that file to your account at KCL (or to your own computer).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(c) Unzip the archive.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This will create a folder pacman<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you use anything other than Python 3, you are on your own in terms of support, and if the code you<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">submit does not work (which is likely), you will lose marks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">yuan-yannakoudakis-cocarascu-6ccs3ml1-cw1Figure 1: Pacman<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(d) From the command line (you will need to use the command line in order to use the various<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">options), switch to the folder pacman.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(e) Now type:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">python3 pacman.py<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This will open up a window that looks like that in Figure 1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(f) The default mode is for keyboard control, so you should be able to play this game out using<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">the arrow keys.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Playing Pacman is not the object here \u2014 don\u2019t worry if there is an issue with controlling Pacman<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">using the keys, that can happen on some platforms \u2014 but you will need to run this code to do the<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">coursework. So, if the code causes an error, get help.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you are tired of running Pacman, move on to the next section.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2.2<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code to control Pacman<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now we work towards controlling Pacman by writing code. The file sampleAgents.py contains<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">several simple pieces of code for controlling Pacman. You can see one of these run by executing:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">python3 pacman.py &#8211;pacman RandomAgent<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is not a good player (it is just picking from the available actions at random), but it shows you<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">a couple of things.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, you execute an agent that you write by using the &#8211;pacman option, followed by the name of<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">a Python class. The Pacman code looks for this class in files called:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&lt;something&gt;Agents.py<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">yuan-yannakoudakis-cocarascu-6ccs3ml1-cw1and, when it finds the class, will compile the relevant class. If the class isn\u2019t in an appropriately<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">named file, you will get the error:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Traceback (most recent call last):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">File &#8220;pacman.py&#8221;, line 679, in &lt;module&gt;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">args = readCommand( sys.argv[1:] ) # Get game components based on input<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">File &#8220;pacman.py&#8221;, line 541, in readCommand<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">pacmanType = loadAgent(options.pacman, noKeyboard)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">File &#8220;pacman.py&#8221;, line 608, in loadAgent<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">raise Exception(\u2018The agent \u2019 + pacman + \u2018 is not specified in any *Agents.py.\u2019)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now open your favourite editor and look at sampleAgents.py. If you look at RandomAgent you<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">will see that all it does is to define a function getAction(). This function is the only thing that is<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">required to control Pacman.2 The function is called by the game every time that it needs to know<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">what Pacman does \u2014 at every \u201ctick\u201d of the game clock \u2014 and what it needs to return is an action.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That means returning expressions that the rest of the code can interpret to tell Pacman what to do.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the basic Pacman game, getAction() returns commands like:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Directions.STOP<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">which tells Pacman to not move, or:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Directions.WEST<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">which tells Pacman to move towards the left side of its grid (North is up the grid).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, for your coursework, you have to pass this direction to the function api.makeMove() first,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">just as the classes in sampleAgents.py do.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sampleAgents.py contains a second agent, RandomishAgent. Try running it. RandomishAgent<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">picks a random action and then keeps doing that as long as it can.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2.3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Towards a classifier<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For this coursework you\u2019ll work from some skeleton code that is in the folder pacman-cw1. The file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">to look for is classifier.py which is used in classifierAgents.py. You will ONLY need to<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">modify classifier.py and no other file. Two things to note about this:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(a) The skeleton in classifier.py defines a class Classifier, and classifierAgents.py<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">defines a class ClassifierAgent. When we mark your coursework, we will do so by running<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">the ClassifierAgent class. If this doesn\u2019t exist (or, similarly, if class Classifier doesn\u2019t<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">exist, because you decided to rename things), we will mark your code as if it doesn\u2019t work.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So make life easy for yourself, and use the classes and functions provided as the basis for your<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">code. Again, you will ONLY need to modify \/ use the skeleton in classifier.py and no<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">other file. We cannot accept code after the deadline has passed even if errors are of accidental<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">nature.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Of course, controlling Pacman to do something well may require a number of functions in addition to<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">getAction().<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">yuan-yannakoudakis-cocarascu-6ccs3ml1-cw1(b) The ClassifierAgent class provides some simple data handling. It reads data from a file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">called good-moves.txt and turns it into arrays target and data which are similar to the<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ones you have used with scikit-learn. When we test your code, it will have to be able to<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">read data in the same format as good-moves.txt, from a file called good-moves.txt. If it<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">doesn\u2019t, we will mark your code as not working. So make life easy for yourself and stick to<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">the (admittedly, but intentionally, limited) data format that we have provided.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To run the code in classifierAgents.py, you use:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">python3 pacman.py &#8211;pacman ClassifierAgent<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note the difference in capitalisation between file name and class name.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now open your editor and take a look at the code for ClassifierAgent. There are six functions in it:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(a) __init__()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The constructor. Run when an instance of the class is created. Because the game doesn\u2019t<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">exist at this point, it is of limited use.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(b) loadData()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is a simple utility. The data in good-moves.txt is stored as a string. We need it as an<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">array of integers. This does the conversion.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(c) registerInitialState()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This function gets run once the game has started up. Unlike __init()__, because the game<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">has started, there is game state information available. Thus it is possible for Pacman to \u201clook\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">at the world around it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Right now this is the only function that is doing any real work. It opens the file good-moves.txt,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">and extracts the data from it, where data is parsed into the arrays data and target. These ar\u0002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">rays are accessible from any function. (They are data members of the class ClassifierAgent.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(d) final()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This function is run at the end of a game, when Pacman has either won or lost.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(e) convertNumberToMove()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Another simple utility. The data in good-moves.txt encodes moves that Pacman made in<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">the past using integers. What you need to do is to produce moves of the form:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Directions.NORTH<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">since that is the format which the game engine requires. This function converts from one to<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">the other in a way that respects the original conversion from moves to integers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(f) getAction()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This function is called by the game engine every time step. What it returns controls what<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pacman does. Right now it just returns Directions.EAST or a random move (see predict()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">in classifier.py). (The function also does some other stuff, but we will get to that later).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">yuan-yannakoudakis-cocarascu-6ccs3ml1-cw1<strong>3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>What you have to do (and what you aren\u2019t allowed to do)<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3.1 Write some code<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Your task in this coursework is to write a classifier using classifier.py which uses the data in<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">good-moves.txt to control Pacman. By \u201ccontrol Pacman\u201d we mean \u201cselect an action and return<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">it in the function getAction (the code is already set up for you this way). However, because this is<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">a module on machine learning, not a module on game programming, we are quite prescriptive about<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">how you go about doing this:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(a) Your code is only allowed limited access to information about the state of the game. What<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">you are allowed to access is the information provided by:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">api.getFeatureVector(state)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This returns a feature vector in the form of an array of 1s and 0s like this:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">[1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This records details of whether there are walls, food, and ghosts in the squares around Pacman.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You don\u2019t need to know what each number means (though if you want to know, look in<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">api.py). What you do need to know is that if your code uses any other information about<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">the game to decide what to do, you won\u2019t get any marks for the coursework.3<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(b) Your code should use a classifier to make a decision, based on the information in features, to<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">decide what to do. Thus the classifier should be trained using the information in self.data<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">and self.target, and should predict an action when passed the data in features (again,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">this is already set up).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(c) You are allowed to use a classifier from an external library such as scikit-learn. However,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">if you use a classifier from an external library, you will not get as many marks as if you write<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">a classifier yourself. (For details on exactly how we will mark your code, see the marksheet on<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">KEATS. Also ensure you read the coursework\u2019s FAQs on KEATS.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(d) If you do code your own classifier, it does not have to be complicated. It could be as simple<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">as a 1-nearest neighbour classifier. However, the more sophisticated the classifier, the more<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">marks you will get. (Again, for details you should see the marksheet and FAQs on KEATS.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(e) To get full marks, your code has to run until either Pacman wins a game, or until Pacman gets<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">eaten by a ghost (and loses a game). In other words, your code should not crash or otherwise<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">fail while we are running it. Losing a game is not failing. In fact, from the point of view of<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">marking, we don\u2019t care if your Pacman wins, loses, gets a high score or a low score. We only<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">care that your code successfully uses a classifier to decide what to do.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3.2 Things to know<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you look in good-moves.txt, you will see that each line contains a feature vector like the one<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">above, plus a final digit. (There are no brackets or commas, that is because good-moves.txt holds<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ok, that is not quite right. The code in getAction in the skeleton classifierAgent uses legal =<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">api.legalActions(state) to get a set of the legal moves at every step. That is technically information about<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">the game state, and it is both allowed, and sensible, since if you return an illegal action to the game engine, the<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">game crashes. The code is already set up to use this. Using any other information is, however, forbidden.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">yuan-yannakoudakis-cocarascu-6ccs3ml1-cw1strings not arrays.) The first digits are indeed a feature vector, and the last digit encodes an action.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When the data is read in by registerInitialState, the feature vector part is loaded into data,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">and the \u201caction\u201d is loaded into target such that the ith elements of data and target go together.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The data was collected from code that played Pacman. (Indeed, from some code that won games<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">of Pacman.) At each step, the feature vector and move were stored in good-moves.txt. And that<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">is exactly why you can create a classifier from it. If you train a classifier on the good-moves data,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">then that classifier should be able to predict a sensible move given a new feature vector.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note that while the good-moves data is what we will test your code with (or rather it is one of the<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">things we will test your code with), you may want to create some custom training data. To make<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">that easy, we have provided TraceAgent (in the file traceagents.py). If you run this using:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">python3 pacman.py &#8211;p TraceAgent<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">you will get the same keyboard controlled Pacman as you saw before, BUT one which outputs data<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">on your move and the corresponding feature vector. This data is written to moves.txt. (If a file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">already exists with that name, it is over-written, so be careful.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3.3 Limitations<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are some limitations on what you can submit.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(a) Your code should be in Python 3.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Code written in a language other than that will not be marked.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Code written in Python 2 is unlikely to run with the clean copy of pacman-cw1 that we will<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">test it against. If it doesn\u2019t run, you will lose marks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The reason for this is that we do not have the resources to deal with code written in multiple<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">languages, and to ensure that we can run code written in Python 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(b) Your code will be tested in the same environment as we have been using in the lab. That<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">is the standard Anaconda Python 3 distribution, with scikit-learn also installed (and the<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">scikit-learn distribution includes numpy). Code using libraries that are not in this collection<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>may <\/em>not run when we test it. If you choose to use such libraries and your code does not run<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">when we test it, you will lose marks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The reason for this is that we do not have the resources to deal with setting up arbitrarily<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">complex environments (with the possibility of libraries with arcane interactions) for every<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">submission.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(c) Your code must only interact with the Pacman environment by making calls through the version<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">of api.py supplied in pacman-cw1.zip. Code that finds other ways to access information<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">about the environment will lose marks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The idea here is to have everyone solve the same task.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(d) You are not allowed to modify any of the files in pacman-cw1.zip except classifier.py.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Similar to the previous point, the idea is that everyone solves the same problem \u2014 you can\u2019t<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">change the problem by modifying the base code that runs the Pacman environment. Also,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">your code will have to run against a clean version of the code in pacman-cw1 so you\u2019ll just be<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">making trouble for yourself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">6<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">yuan-yannakoudakis-cocarascu-6ccs3ml1-cw1(e) You are not allowed to copy, without credit, code that you might get from other students or find<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">lying around on the Internet. (This includes the use of code that was distributed as part of the<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">module \u2014 if you use code from files other than classifier.py and classifierAgent.py<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">without attribution, we will consider that to be plagiarism.) We will be checking.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is the usual plagiarism statement. When you submit work to be marked, you should only<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">seek to get credit for work you have done yourself. When the work you are submitting is code,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">you can use code that other people wrote, but you have to say clearly that the other person<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">wrote it \u2014 you do that by putting in a comment that says who wrote it. That way we can<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">adjust your mark to take account of the work that you didn\u2019t do. Please add any citations,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">descriptions, or whatever you want us to know in the python file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Please also ensure you familiarise yourselves with what constitutes plagiarism and collusion<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">and how to avoid them (ensure you read the information on KEATS); e.g. copying large parts<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">of code from others, even with attribution, is not allowed. We need to be able to assess your<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">OWN contribution.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(f) Your code must be based on using a classifier on the data in good-moves.txt. If you don\u2019t<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">submit a program that contains a recognisable classifier, you will lose marks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4 What you have to hand in<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Your submission should consist of a single ZIP file. (KEATS will be configured to only accept a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">single file.) This ZIP file must include a single Python file (your code): classifier.py.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The ZIP file must be named:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cw1-&lt;lastname&gt;-&lt;firstname&gt;.zip<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Remember that we are going to evaluate your code by running your code by using variations on<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">python3 pacman.py -p ClassifierAgent<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">and we will do this in a vanilla copy of the pacman-cw1 folder, so the base class for your agent must<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">be called ClassifierAgent and use class Classifier and the skeleton provided.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To streamline the marking of the coursework, you must put all your code in one file, and this file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">must be called classifier.py (which we provide).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do not just include the whole pacman-cw1 folder. You should only include the one file that includes<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">the code you have written. Do not modify any of the other files either when developing your code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Submissions that do not follow these instructions will lose marks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5 How your work will be marked<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There will be three main components of the mark for your work:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(a) Functionality<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We will test your code in classifier.py by running the classifierAgents.py file against<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">a clean copy of pacman-cw1.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As discussed above, for full marks for functionality, your code is required to run when we<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">invoke the command:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">7<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">yuan-yannakoudakis-cocarascu-6ccs3ml1-cw1python3 pacman.py &#8211;p ClassifierAgent<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">and run until the game is won or lost. Code that fails to meet these requirements will lose<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">marks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We will also look at your code for evidence of the use of a classifier. Code that does not use<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">a classifier will lose marks. Code that does not implement a classifier (that is, uses one from<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">an external library like scikit-learn) will lose marks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Code that implements more sophisticated classifiers will get more marks. So, my example<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(above) of using a 1-NN classifier, which is about the simplest possible classifier, would not<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">get as many marks as the implementation of a more sophisticated classifier.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(b) Style<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are no particular requirements on the way that your code is structured but you should<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ensure it follows standard good practice in software development and will be marked accord\u0002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ingly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Remember that your code is only allowed to interact with the Pacman environment through<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">api.py (the version in pacman-cw1), and is only allowed to use the environment information<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">provided to the Classifier class. Code that does not follow this rule will lose marks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(c) Documentation<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">All good code is well documented, and your work will be partly assessed by the comments you<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">provide in your code. If we cannot understand from the comments what your code does, then<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">you will lose marks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A copy of the marksheet, which shows the distribution of marks across the different elements of the<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">coursework, is available from KEATS, together with FAQs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">8<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">yuan-yannakoudakis-cocarascu-6ccs3ml1-cw1<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Coursework 1 (Versio [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[7],"tags":[],"class_list":["post-96","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/www.csdaixie.com\/index.php\/wp-json\/wp\/v2\/posts\/96","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.csdaixie.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.csdaixie.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.csdaixie.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.csdaixie.com\/index.php\/wp-json\/wp\/v2\/comments?post=96"}],"version-history":[{"count":1,"href":"http:\/\/www.csdaixie.com\/index.php\/wp-json\/wp\/v2\/posts\/96\/revisions"}],"predecessor-version":[{"id":97,"href":"http:\/\/www.csdaixie.com\/index.php\/wp-json\/wp\/v2\/posts\/96\/revisions\/97"}],"wp:attachment":[{"href":"http:\/\/www.csdaixie.com\/index.php\/wp-json\/wp\/v2\/media?parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.csdaixie.com\/index.php\/wp-json\/wp\/v2\/categories?post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.csdaixie.com\/index.php\/wp-json\/wp\/v2\/tags?post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}