Skip to content

๐Ÿ‘พ A Python-based Pac-Man game implementing AI agents with intelligent decision-making and pathfinding algorithm for strategic gameplay.

Notifications You must be signed in to change notification settings

Amirbehnam1009/Pacman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Pacman AI Projects

A Python implementation of artificial intelligence search algorithms to solve problems within the Berkeley Pac-Man environment. The Pac-Man Projects, developed at UC Berkeley, apply Artificial Intelligence concepts to the famous arcade game.

Pacman Python License

๐Ÿ“‹ About

Under The Supervision of Prof. Mahdi Javanmardi
Fall 2021 | Amirkabir University of Technology

This repository contains implementations of various AI algorithms applied to the classic Pacman game. Each project builds upon the previous one, introducing more complex AI concepts and challenges.

๐Ÿš€ Projects

1. ๐Ÿ” Search Algorithms

Implemented classic search algorithms for pathfinding in Pacman mazes:

  • Depth-First Search (DFS) - depthFirstSearch
  • Breadth-First Search (BFS) - breadthFirstSearch
  • Uniform Cost Search - uniformCostSearch
  • A * Search - aStarSearch

Key Features:

  • ๐Ÿงญ Pathfinding in various maze configurations
  • ๐Ÿ“ Heuristic functions (Manhattan distance, custom heuristics)
  • ๐ŸŽฏ Corner finding problem solution
  • ๐ŸŽ Food collection search

2. ๐Ÿ‘ฅ Multi-Agent Search

Implemented adversarial search algorithms for Pacman vs Ghosts scenarios:

  • Minimax - MinimaxAgent
  • Alpha-Beta Pruning - AlphaBetaAgent
  • Expectimax - ExpectimaxAgent
  • Evaluation Functions - Custom heuristic evaluation

Key Features:

  • ๐ŸŽฒ Probabilistic reasoning for ghost movements
  • โœ‚๏ธ Efficient pruning of search trees
  • ๐Ÿง  Sophisticated evaluation functions
  • ๐Ÿ† Performance optimization for various game scenarios

3. ๐Ÿค– Reinforcement Learning

Implemented model-based and model-free reinforcement learning algorithms:

  • Value Iteration - ValueIterationAgent
  • Q-Learning - QLearningAgent
  • Approximate Q-Learning - ApproximateQAgent
  • Epsilon-Greedy Action Selection
  • Bridge Crossing Analysis

Key Features:

  • ๐Ÿ“Š Policy evaluation and improvement
  • ๐ŸŽฏ Reward maximization strategies
  • ๐Ÿ”ง Parameter tuning for optimal performance
  • ๐Ÿงฎ Function approximation for large state spaces

๐Ÿ› ๏ธ Installation & Setup

  1. Clone the repository:
    git clone https://github.com/Amirbehnam1009/Pacman.git
    cd Pacman
  2. Ensure you have Python 3.x installed
  3. Run the projects:
    # Project 1: Search
    python pacman.py
    
    # Project 2: Multi-Agent Search
    python pacman.py -p MinimaxAgent
    
    # Project 3: Reinforcement Learning
    python gridworld.py -a q -k 100

๐Ÿ“ Project Structure

Pacman/
โ”‚
โ”œโ”€โ”€ search.py              # Search algorithms implementation
โ”œโ”€โ”€ searchAgents.py        # Search agents and problems
โ”œโ”€โ”€ multiAgents.py         # Multi-agent algorithms
โ”œโ”€โ”€ valueIterationAgents.py # Value iteration agents
โ”œโ”€โ”€ qlearningAgents.py     # Q-learning agents
โ”œโ”€โ”€ analysis.py            # Analysis and answers
โ”œโ”€โ”€ game.py               # Game engine
โ”œโ”€โ”€ pacman.py             # Main Pacman executable
โ”œโ”€โ”€ gridworld.py          # Gridworld environment
โ”œโ”€โ”€ util.py               # Utility functions
โ””โ”€โ”€ test_cases/           # Test cases for autograder  

๐Ÿงช Testing

Use the autograder to test your implementations:

# Test all questions
python autograder.py

# Test specific question
python autograder.py -q q2

# Test with no graphics
python autograder.py -q q2 --no-graphics

๐ŸŽฎ How to Play

Run the game with different agents:

# Run with specific layout and agent
python pacman.py -l mediumClassic -p MinimaxAgent -a depth=3

# Run with faster animation
python pacman.py --frameTime 0 -p ExpectimaxAgent -k 2

# Run Q-learning agent
python pacman.py -p PacmanQAgent -x 2000 -n 2010 -l smallGrid

๐Ÿ“Š Performance Metrics

Each project includes evaluation criteria:

  • ๐ŸŽฏ Solution optimality (path length, score)

  • โšก Algorithm efficiency (nodes expanded, time)

  • ๐Ÿง  Heuristic quality (admissibility, consistency)

  • ๐Ÿ† Win rates against ghosts

  • ๐Ÿ“š Learning Concepts This repository demonstrates:

  • State space representation

  • Search algorithm properties (completeness, optimality)

  • Adversarial search techniques

  • Reinforcement learning principles

  • Heuristic function design

  • Performance optimization

๐Ÿ“„ License

This project is based on the UC Berkeley Pacman Projects, adapted for educational purposes at Amirkabir University of Technology.

๐Ÿ™ Acknowledgments

  • UC Berkeley CS188 for the original Pacman projects

  • Amirkabir University of Technology for the course structure

  • Professor Mahdi Javanmardi for guidance and supervision

About

๐Ÿ‘พ A Python-based Pac-Man game implementing AI agents with intelligent decision-making and pathfinding algorithm for strategic gameplay.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages