Skip to content
MariusfaitducodePublic

About

Pac-Man AI agents: A* search, Minimax/H-Minimax and Bayes filter ghost tracking (ULiège INFO8006 course)

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

48 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PacManAI

Intelligent agents for the game of Pac-Man: search, adversarial search and probabilistic tracking, built for the INFO8006 Introduction to Artificial Intelligence course at the University of Liège.

Pac-Man game

What we implemented

The project has three parts, each in its own folder with the original assignment in its README.

  • Project 0: search. Pac-Man must eat all the food dots as fast as possible. Implemented breadth-first search (bfs.py) and A* (astar.py) with a heuristic based on the remaining food and capsules; a DFS agent was provided as a starting point.
  • Project 1: adversarial search. Pac-Man must now eat the dots while a ghost chases him. Implemented Minimax (minimax.py) and depth-limited H-Minimax (hminimax.py), whose evaluation function uses maze distances precomputed with Floyd-Warshall (closest food, distances between food dots, distance to the ghost) and adds loop avoidance.
  • Project 2: Bayes filter. Ghosts become invisible and Pac-Man only gets a noisy distance reading to each of them. Implemented the transition model, the observation model (binomial sensor noise) and the Bayes filter update in bayesfilter.py, plus a controller that picks a ghost from the belief state and hunts it with A*/BFS path planning.

Tech stack

Python 3, NumPy, SciPy (project 2). The game engine and Tkinter graphics come from the UC Berkeley CS188 Pac-Man framework.

Run it locally

Create an environment with conda (tested by the course staff on Windows, Linux and macOS):

$ conda create --name pacman python=3.8
$ conda activate pacman
$ conda install numpy scipy

Then go into a project folder and use run.py:

  • --agent: start the game with a given Pac-Man agent
    $ python run.py --agent astar --layout medium
  • --ghost (projects 1 and 2): choose the ghost agent (dumby, greedy or smarty in project 1; afraid, fearless or terrified in project 2)
    $ python run.py --agent hminimax --ghost greedy --layout medium_adv
  • --layout: choose a maze from pacman_module/layouts
  • --nographics: disable the graphical interface
    $ python run.py --agent bfs --nographics
  • --seed: change the random seed (projects 1 and 2)

Project 2 example:

$ cd project2
$ python run.py --ghost afraid --nghosts 1 --layout large_filter --seed 42

Game score

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

Agents must win the game while maximizing this score.

Agent API

Agents are written as a PacmanAgent class (template in pacmanagent.py) whose get_action(state) returns the next move. Useful state methods:

  • s.generatePacmanSuccessors() / s.generateGhostSuccessors(agentIndex): successor states and moves (required for every node expansion).
  • s.getLegalActions(agentIndex): legal moves (0 is always Pac-Man).
  • s.getPacmanPosition(), s.getGhostPosition(agentIndex), s.getGhostDirection(agentIndex)
  • s.getScore(), s.getFood(), s.getNumFood(), s.getWalls(), s.getCapsules()
  • s.isWin(), s.isLose()

If an agent returns an illegal move, the previous move is repeated when still legal; otherwise Pac-Man stays in place.

Context

Group project for INFO8006 Introduction to Artificial Intelligence at the University of Liège (fall 2024), by Marius Diguat, Hugo Beaubrun (@hug0be) and @Pierre-Hala.

Credits

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

About

Pac-Man AI agents: A* search, Minimax/H-Minimax and Bayes filter ghost tracking (ULiège INFO8006 course)

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages