Authors: Jierui Xu, and Edison Chen
Time: Summer 2022
Course: CS 188 Introduction to Artificial Intelligence, taught at UC Berkeley
Achievement: Our team scored 1st out of a total of 5 teams in the final contest.
Multi-Agent Adversarial Pacman Project
Overview
This mini-contest involves a multi-player capture-the-flag variant of Pacman, where agents control both Pacman and ghosts in coordinated team-based strategies. Each team will try to eat the food on the far side of the map, while defending the food on their home side.
Each team's agents are in the form of ghosts on their home side and Pacmen on the opponent’s side. Also, team is now able to eat their opponent when the agent is a ghost. If a Pacman is eaten by a ghost before reaching his own side of the board, he will explode into a cloud of food dots that will be deposited back onto the board.
THe ultimate goal is to reach as much points as possible while keep the other team's points as low as possible. Eventually, the team with highest points win the game.
Score Calculation
The score in this Pac-Man strategy is calculated based on a linear combination of features and their corresponding weights. The primary goal is to maximize the score by considering both offensive and defensive strategies.
Evaluation Function
- The
evaluate function computes the score for each action by combining various features with their respective weights.
- Formula:
score = features * weights
Features and Weights
- Different features are considered for scoring, including the number of remaining food pellets, distance to food, presence of invaders, and proximity to defenders.
- Example of offensive weights:
{'successorScore': 100, 'defense': 0, 'numInvaders': 0, 'distInvader': 0, 'nearDefender': -30, 'distFood': -1, 'carryingRisk': -5, 'distCapsule': -3, 'trap': 1, 'stop': -10, 'reverse': 0}
- Example of defensive weights:
{'successorScore': 0, 'defense': 100, 'numInvaders': -1000, 'distInvader': -10, 'nearDefender': 0, 'distFood': 0, 'carryingRisk': 0, 'distCapsule': 0, 'trap': 0, 'stop': -100, 'reverse': -2}
Detailed Explanation of Features
- successorScore: Measures the score of the game state after making a move. Higher scores indicate better states.
- defense: Indicates whether the agent is playing a defensive role. A value of 1 means the agent is defending, while 0 means it is not.
- numInvaders: Counts the number of enemy agents in the territory. Higher values indicate more invaders.
- distInvader: Measures the distance to the nearest enemy invader. Smaller distances are better for defense.
- nearDefender: Measures the proximity to enemy defenders. Smaller distances indicate closer defenders, which is risky for the agent.
- distFood: Measures the distance to the nearest food pellet. Smaller distances are better for collecting food.
- carryingRisk: Evaluates the risk based on the amount of food the agent is carrying and the distance to a safe zone. Higher values indicate greater risk.
- distCapsule: Measures the distance to the nearest power capsule. Smaller distances are better for collecting capsules.
- trap: Penalizes the agent if it is near a trap (surrounded by walls). A value of -1000 indicates a high penalty.
- stop: Penalizes the agent for stopping its movement. A value of 1 means the agent stopped, and it is penalized for it.
- reverse: Penalizes the agent for reversing its direction. A value of 1 means the agent reversed, and it is penalized for it.
Strategy Implementation
The author implements a hybrid strategy that switches between offensive and defensive roles based on the game state:
Offensive Strategy
- The agent seeks food and capsules to increase its score.
- It evaluates the distance to the nearest food and capsules and avoids defenders by using features like
distFood, distCapsule, and nearDefender.
- It considers the risk of being captured when carrying food (
carryingRisk).
Defensive Strategy
- When invaders are detected, the agent switches to defense.
- It evaluates features like
numInvaders and distInvader to focus on repelling enemy agents.
- It prioritizes returning to a safe position if carrying food or if the number of food pellets is low.
Differences Between Offensive and Defensive Agents
Offensive Agent
- Focuses on collecting food and capsules.
- Uses features that help it navigate towards food while avoiding defenders.
- Penalizes actions like stopping or moving in the reverse direction, which could make it easier for defenders to catch it.
Defensive Agent
- Focuses on preventing enemy agents from scoring.
- Uses features that help it locate and chase invaders.
- Penalizes stopping and reversing to ensure it stays proactive in defending the territory.
- Prioritizes actions that bring it closer to invaders and blocks them from reaching the food.