CMSC 372: Artificial Intelligence Lab#1: Designing Pac-Man Agents

Similar documents
ADVANCED TOOLS AND TECHNIQUES: PAC-MAN GAME

For slightly more detailed instructions on how to play, visit:

Activity 6: Playing Elevens

Introduction to Artificial Intelligence CS 151 Programming Assignment 2 Mancala!! Due (in dropbox) Tuesday, September 23, 9:34am

CS151 - Assignment 2 Mancala Due: Tuesday March 5 at the beginning of class

Project 2: Searching and Learning in Pac-Man

CS221 Project: Final Report Raiden AI Agent

Design task: Pacman. Software engineering Szoftvertechnológia. Dr. Balázs Simon BME, IIT

2048: An Autonomous Solver

The Kapman Handbook. Thomas Gallinari

CS 188: Artificial Intelligence Spring Announcements

Announcements. CS 188: Artificial Intelligence Spring Game Playing State-of-the-Art. Overview. Game Playing. GamesCrafters

Game Playing for a Variant of Mancala Board Game (Pallanguzhi)

Announcements. Homework 1. Project 1. Due tonight at 11:59pm. Due Friday 2/8 at 4:00pm. Electronic HW1 Written HW1

Mittwoch, 14. September The Pelita contest (a brief introduction)

Artificial Intelligence

Game Playing State-of-the-Art. CS 188: Artificial Intelligence. Behavior from Computation. Video of Demo Mystery Pacman. Adversarial Search

The Beauty and Joy of Computing Lab Exercise 10: Shall we play a game? Objectives. Background (Pre-Lab Reading)

CMSC 201 Fall 2018 Project 3 Sudoku

RoboMind Challenges. Line Following. Description. Make robots navigate by itself. Make sure you have the latest software

Creating PacMan With AgentCubes Online

Add Transparent Type To An Image With Photoshop

Clever Pac-man. Sistemi Intelligenti Reinforcement Learning: Fuzzy Reinforcement Learning

Your First Game: Devilishly Easy

CS 188: Artificial Intelligence. Overview

Assessment. Self Assessment. Teacher Assessment. Date Learning Objective(s) Achievement or. NC Level: Game Control Student Booklet P a g e 1

Unit 12: Artificial Intelligence CS 101, Fall 2018

CS 188 Introduction to Fall 2014 Artificial Intelligence Midterm

ADD TRANSPARENT TYPE TO AN IMAGE

Photoshop Exercise 2 Developing X

Creating PacMan With AgentCubes Online

NMC Second Life Educator s Skills Series: How to Make a T-Shirt

Learning to Play like an Othello Master CS 229 Project Report. Shir Aharon, Amanda Chang, Kent Koyanagi

RDworks and Basic Rabbit Laser Operation Tutorial

Star Defender. Section 1

Kodu Lesson 7 Game Design The game world Number of players The ultimate goal Game Rules and Objectives Point of View

How to Convert & Resize Images in Bulk

Creating a Slide Show with Background Music in Adobe Lightroom January 2017 Maryann Flick

2809 CAD TRAINING: Part 1 Sketching and Making 3D Parts. Contents

CS 5522: Artificial Intelligence II

CSC242 Intro to AI Spring 2012 Project 2: Knowledge and Reasoning Handed out: Thu Mar 1 Due: Wed Mar 21 11:59pm

Basic 2D drawing skills in AutoCAD 2017

Spring 06 Assignment 2: Constraint Satisfaction Problems

Kodu Game Programming

Administrivia. CS 188: Artificial Intelligence Spring Agents and Environments. Today. Vacuum-Cleaner World. A Reflex Vacuum-Cleaner

Comp th February Due: 11:59pm, 25th February 2014

CSE 40171: Artificial Intelligence. Adversarial Search: Games and Optimality

The Joy of SVGs CUT ABOVE. pre training series 3. svg design Course. Jennifer Maker. CUT ABOVE SVG Design Course by Jennifer Maker

Announcements. CS 188: Artificial Intelligence Fall Today. Tree-Structured CSPs. Nearly Tree-Structured CSPs. Tree Decompositions*

Spring 06 Assignment 2: Constraint Satisfaction Problems

In this project you ll learn how to create a game, in which you have to match up coloured dots with the correct part of the controller.

CS 229 Final Project: Using Reinforcement Learning to Play Othello

Assignment 1. Due: 2:00pm, Monday 14th November 2016 This assignment counts for 25% of your final grade.

CS 441/541 Artificial Intelligence Fall, Homework 6: Genetic Algorithms. Due Monday Nov. 24.

SolidWorks Tutorial 1. Axis

Swarmathon Module 5: Final Project

Adversarial Search. Read AIMA Chapter CIS 421/521 - Intro to AI 1


Creating Journey In AgentCubes

1. Creating geometry based on sketches 2. Using sketch lines as reference 3. Using sketches to drive changes in geometry

The purpose of this document is to help users create their own TimeSplitters Future Perfect maps. It is designed as a brief overview for beginners.

PUZZLE EFFECTS 3D User guide JIGSAW PUZZLES 3D. Photoshop CC actions. User Guide

CS Problem Solving and Structured Programming Lab 1 - Introduction to Programming in Alice designed by Barb Lerner Due: February 9/10

Make sure your name and FSUID are in a comment at the top of the file.

Project 1: Game of Bricks

Please note that this tutorial contains references to other chapters in the book!

Resizing Images for Competition Entry

Game Playing State-of-the-Art

Tac Due: Sep. 26, 2012

CS 188: Artificial Intelligence Fall AI Applications

Environmental Stochasticity: Roc Flu Macro

CS61B, Fall 2014 Project #2: Jumping Cubes(version 3) P. N. Hilfinger

To-Do List: Initial steps upon opening an.ai document that has been exported from ArcMap

33-2 Satellite Takeoff Tutorial--Flat Roof Satellite Takeoff Tutorial--Flat Roof

AutoCAD Line Types If AutoCAD linetypes are disabled during configuration, Slick! will only plot/print straight lines!

SAVING, LOADING AND REUSING LAYER STYLES

Practice Workbook. Cross Sections: Creating, Annotating, and Volumes

Informatics 2D: Tutorial 1 (Solutions)

CONCEPTS EXPLAINED CONCEPTS (IN ORDER)

CS 188: Artificial Intelligence

Alright! I can feel my limbs again! Magic star web! The Dark Wizard? Who are you again? Nice work! You ve broken the Dark Wizard s spell!

Rock, Paper, Scissors

CS180 Project 5: Centipede

Game Maker Tutorial Creating Maze Games Written by Mark Overmars

CS7032: AI & Agents: Ms Pac-Man vs Ghost League - AI controller project

we re doing all of the background, then we stop. We put on the borders and then we come back and we ll finish out the eagle.

Begin this assignment by first creating a new Java Project called Assignment 5.There is only one part to this assignment.

CS188: Artificial Intelligence, Fall 2011 Written 2: Games and MDP s

Tutorial: Creating maze games

FAQ for City of Tacoma employees

Instruction Manual. Pangea Software, Inc. All Rights Reserved Enigmo is a trademark of Pangea Software, Inc.

CS 1410 Final Project: TRON-41

Overview. The Game Idea

Revit Structure 2013 Basics

Final Project Due August 4, 2017

The University of Melbourne Department of Computer Science and Software Engineering Graphics and Computation

Addendum 18: The Bezier Tool in Art and Stitch

FINAL PROJECT ARTIFICIAL INTELLIGENCE VINDINIUM. Hosam Hakroush and Dmitry Levikov FOUR LEGENDARY HEROES, FIGHTING FOR THE LAND OF VINDINIUM

Sketch-Up Project Gear by Mark Slagle

Making Your World with the Aurora Toolset

Transcription:

CMSC 372: Artificial Intelligence Lab#1: Designing Pac-Man Agents Figure 1: The Pac-Man World Introduction In this project, you will familiarize yourself with the Pac-Man World. Over the next few assignments your Pac-Man agent will find paths through his maze world, both to reach a particular location and to collect food efficiently. You will also 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 assignments, and some of which you can ignore. The Pac-Man code was developed by John DeNero and Dan Klein at UC Berkeley. Before you begin, make sure that you have Python 2.7.X available on the computer/account you will be using. It is installed on all CS Lab computers (for Windows and Linux). You can check the version of Python by entering the command 1 : > python --version Python 2.7.11 1 On CS Linus machines, the command to start python 2.7.X is python2.7 1

Commands you enter will be shown in red, followed by the system response/output in blue. You will enter these commands in a command shell after going to the code directory where you downloaded the Pac-Man code files (see below). Step 1: Download Code You can download the code archive by clicking this link: http://cs.brynmawr.edu/courses/cs372/fall2017/code/search.zip Extract the files into a directory/folder on your computer (or in your Linux account). A folder called, search will be created and in it you will find several dozen files. To ensure that you have a working version of the files, run the following command: python pacman.py You should see a game screen pop up (see Figure 1). This is a basic Pac-Man game. In the game, you control the movements of Pac-Man using arrow keys on your keyboard. Go ahead and try it. The Pac-Man world is laid out as corridors (with shiny blue walls) where Pac-Man can move about. Little white pellets are sometimes littered throughout the corridors. This is food for Pac-Man (larger pellets are power food or capsules, try and figure out what those are for). In the world shown in Figure 1, Pac- Man has adversaries: colored ghosts that eat Pac-Man when it runs into them. Ghosts move about without eating any food. When Pac-Man is eaten, it dies and the game ends. The screen will disappear. Step 2: Pac-Man Agent In this and the next few assignments, you will be writing agent programs to control the actions of Pac- Man. That is, creating a Pac-Man agent. The code enables you to use different environments to try out your Pac-Man agent programs. To specify a specific environment, you use the command: python pacman.py - layout testmaze Go ahead and try it. It is simple maze with one corridor. Here is one you will use more often: python pacman.py - layout tinymaze 2

There are several other environments defined: mediummaze, bigmaze, opensearch, etc. You can also vary the scale of the screen by using the zoom option as shown below: python pacman.py layout tinymaze zoom 2 python pacman.py layout bigmaze zoom 0.5 All of these are single agent environments, the agent being Pac-Man. In these environments, Pan-Man always starts at the top right corner. At the bottom left corner is a single food pellet. The game ends when Pac-Man eats very last pellet (there can be pellets anywhere in its world). Step 3: Learning the Pac-Man Grid and Actions Grid: The environment is essentially a grid of squares. At any given time Pac-Man occupies a square and faces one of the four directions: North, South, East, or West. There may be walls in between the square (like the t-shaped wall in tinymaze) or entire squares might be blocked by walls (like the bottom right corner of tinymaze. regardless, the location of Pac-Man is determined by the x- and y- coordinates of the grid (as shown below): 3

Figure 2: The Pac-Man Grid. Pac-Man is at position (5, 5). Food pellet is at (1, 1) Actions Pac-Man can only carry out the following actions: North : go 1 step north South : go one step south East : go one step east West : go one step west Stop : stop, do not move Below, you will see how these are specified to be carried out. Step 4: Diving Into Some Code OK, now that you are familiar with the basic world, it is time to get familiar with some of the code. Start by looking at the contents of the file game.py. It defines several classes. In the code, you will see clearly marked sections: ####################### # Parts worth reading # ####################### 4

And #################################### # Parts you shouldn't have to read # #################################### Skim through the parts worth reading section of the code. Focus first on the following classes: Agent, Directions, and Configuration. Agent The Agent class is very simple. It is the class you will subclass to create your Pac-Man agent. For example, here is a very simple, and dumb, agent: from game import Agent from game import Directions class DumbAgent(Agent): "An agent that goes West until it can't." def getaction(self, state): "The agent always goes West. return Directions.WEST The way it is set up, when you specify to the game (see below) that the Pac-Man will be a DumbAgent, the action returned by the getaction() method will be carried out at each time step. Important things to note in the above code are: You should create a new file called, Agents.py, in the same directory/folder as the rest of the code base. Enter the code above exactly as shown. Be sure to save the file. Every subclass of Agent (like DumbAgent) is required to implement a getaction() method. This is the method called in each time step of the game and, as mentioned above, it should return a valid action for Pac-Man to carry out. Notice that we are importing the classes Agent and Directions from game.py The getaction() method is supplied a parameter: state, which it can use to find out about the current game state (more on this below). For now, we are ignoring it. Study the class Directions (defined in game.py). Step 5: Run the code Next run the Pac-Man game with its control as DumbAgent using the command: python pacman.py -layout tinymaze -pacman DumbAgent The command above is specifying to run the Pac-Man game using the tinymaze environment and the agent is controlled by the DumbAgent. What happens? 5

In the Pac-Man game, if the path to the grid is blocked and Pac-Man tries to go into it, the game crashes with an Illegal action exception. This is OK. After all, it is a dumb agent. We ll fix that next. Try the same agent in the mediummaze. Same result, right? Good! Step 6: Learning about GameState Next, lets us try and use the information present in the state parameter. This is an object of type GameState which is defined in the file pacman.py. Study the GameState class closely and note the methods defined. Using these, you can get all kinds of information about the current state of the game. Then you can base your agent s action accordingly. Below, we show how you can use some of these and prevent the game from crashing. class DumbAgent(Agent): "An agent that goes West until it can't." def getaction(self, state): "The agent receives a GameState (defined in pacman.py)." print "Location: ", state.getpacmanposition() print Actions available:, state.getlegalpacmanactions() if Directions.WEST in state.getlegalpacmanactions(): print Going West. return Directions.WEST else: print Going West. return Directions.STOP As in Step 4, save this version of your program in Agents.py and run it on tinymaze, as well as mediummaze. Observe the behavior. Try out some of the other methods defined in GameState to get an idea of what information is available to your agent. Step 7: A Random Agent OK, now it is time to write your own agent code. It will be simple in what it does: Based on the current options, pick a random action to carry out. Code the above in a new class called, RandomAgent (in the Agents.py file). Run your agent in the tinymaze environment as well as mediummaze environment. Observe the agent s behavior. Does it get to the food? Always? Without crashing? Etc. Step 8: Exploring Environments See the files in the folder/directory layouts. Environments are specified using simple text files (*.lay) which are then rendered nicely by the graphics modules in the code base. Examine several layout files to 6

see how to specify walls, ghosts, pacman, food, etc. Create a small environment of your own. Make sure it has walls and corridors, as well as some food. Save it as mylayout.lay in the layouts directory. Run your RandomAgent in this environment and observe how it does. Also, try your agent out in the opensearch environment (files are already provided in the layouts directory). Run your agent several times and record, on average, what score you get. Step 9: A Better Random Agent If you print put and look at the choice of actions at each step, you will notice that RandomAgent always includes a choice for the Stop action. This tends to slow it down. Stopping is needed in situations where you need to evade ghosts. For now, in environments without any ghosts, you can choose not to pick the Stop action. Modify the RandomAgent code so that it never chooses Stop as its action. Run the agent in opensearch and mylayout environments and observe how it does. Step 10: Reflex Agents: Adding Percepts What the Pac-Man agent can perceive is based on the methods of the GameState class which is defined in the file pacman.py. Open up this file and let's look through the options. Code Tip: The game has a number of different agents (Pac-Man and the ghosts). Each agent in the game has a unique index; Pac-Man is always index 0, with ghosts starting at index 1. Pac-Man can perceive: His position The position of all of the ghosts The locations of the walls The positions of the capsules The positions of each food pellet The total number of food pellets still available Whether he has won or lost the game His current score in the game In addition, Pac-Man can also determine given the action he chooses what the next state of the environment will be, by using the method generatepacmansuccessor(). It is clear from the methods available here that Pac-Man's environment is fully observable. Pac-Man's environment is also static because until he decides what to do and takes an action, the ghosts do not move. In the file Agents.py create a new agent called ReflexAgent. This agent should look at the possible legal actions, and if one of these actions would cause a food pellet to be eaten, it should choose that action. If 7

none of the immediate actions lead to food, it should choose randomly from the possibilities (excluding 'Stop'). Test your agent in both the opensearch and mylayout layouts. python pacman.py --l opensearch --p ReflexAgent What to hand in: Your submission should include the following: 1. Answers to the following questions: a. Describe the behavior of RandomAgent from Step 7 b. A screen shot of your mylayout environment from Step 8 c. Describe the behavior of RandomAgent from Step 9 d. Describe the behavior of ReflexAgent from Step 10 e. For each of the percepts listed in Step 10: Show what command/code enables you to access it. For example: His postion: gamestate.getpacmanposition() 2. A short reflection from doing this exercise. 3. A print out of the file Agents.py 4. Staple these together, put your name on the front page and hand it in at the start of class on the due date. 8