Git Product home page Git Product logo

ai_pacman's Introduction

Pacman programming project

The goal of this programming project is to implement intelligent agents for the game of Pacman. The project is divided into three parts:

  • Project 0: Implementation of a Search agent for eating all the food dots as quickly as possible.
  • Project I: Implementation of a Minimax agent for eating all the food dots as quickly as possible, while avoiding the ghost enemies that are chasing you.
  • Project II: Implementation of a Bayes filter for tracking all the non-visible ghosts' positions.

Table of contents


Usage

Start the game with a Pacman agent controlled by the keyboard (keys j, l, i, k or arrow keys):

python run.py

Options:

--agentfile: Start the game with a Pacman agent following a user-defined control policy:

python run.py  --agentfile randomagent.py

--ghostagent: Start the game with a ghost agent (either dumbyd, greedy or smarty):

python run.py  --ghostagent=greedy

--silentdisplay: Disable the graphical user interface:

python run.py --silentdisplay

--layout: Start the game with a user-specifed layout for the maze (see the /pacman_module/layouts/ folder):

python run.py --layout medium

--ghostagent: Start the game with a user-specifed ghost agent (see project I):

python run.py --ghostagent greedy

-h: For further details, check the command-line help section:

python run.py -h

FAQ

Game score

The score function of the game is computed as follows:

score = -#time steps + 10*#number of eaten food dots - 5*#number of eaten capsules + 200*#number of eaten ghost + (-500 if #losing end) + (500 if #winning end).

We have implemented agents that win the game while maximizing their score.

API

Useful methods of the state are specified below:

  • s.generatePacmanSuccessors() : Returns a list of pairs of successor states and moves given the current state s for the pacman agent.
    • This method must be called for any node expansion for pacman agent.
  • s.generateGhostSuccessors(agentIndex) : Returns a list of pairs of successor states and moves given the current state s for the ghost agent indexed by agentIndex>0.
    • This method must be called for any node expansion for ghost agent.
  • s.getLegalActions(agentIndex) : Returns a list of legal moves given the state s and the agent indexed by agentIndex. 0 is always the Pacman agent.
  • s.getPacmanPosition() : Returns the Pacman position in a (x,y) pair.
  • s.getScore() : Returns the total score of a state (as defined above).
  • s.getFood() : Returns a boolean matrix which gives the position of all food dots.
  • s.getNumFood() : Returns a scalar which gives the number of food dots remaining.
  • s.getWalls() : Returns a boolean matrix which gives the position of all walls.
  • s.getGhostPosition(agentIndex) : Returns the position of the ghost agent indexed by agentIndex>0.
  • s.getGhostDirection(agentIndex) : Returns the direction of the ghost agent indexed by agentIndex>0.
  • s.getCapsules() : Returns a list of positions of the remaining capsules in the maze.
  • s.isWin() : Returns True if the state is in a winning end.
  • s.isLose() : Returns True if the state is in a losing end.

Implementation examples are provided in humanagent.py and randomagent.py.

Illegal moves

The agent always returns a legal move. If it is not the case, the previous move is repeated if it is still legal. Otherwise, it remains in the same location.


Credits

The programming projects are adapted from CS188 (UC Berkeley).


Authors

ai_pacman's People

Contributors

andrea-liliana avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

carjcc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.