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.
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.
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
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
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
- Clone the repository:
git clone https://github.com/Amirbehnam1009/Pacman.git cd Pacman - Ensure you have Python 3.x installed
- 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
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 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-graphicsRun 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 smallGridEach 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
This project is based on the UC Berkeley Pacman Projects, adapted for educational purposes at Amirkabir University of Technology.
-
UC Berkeley CS188 for the original Pacman projects
-
Amirkabir University of Technology for the course structure
-
Professor Mahdi Javanmardi for guidance and supervision