Licensing Information: You are free to use or extend these projects for educational purposes provided that (1) you do not distribute or publish solutions, (2) you retain this notice, and (3) you provide clear attribution to UC Berkeley, including a link to http://ai.berkeley.edu.
Attribution Information: The Pacman AI projects were developed at UC Berkeley. The core projects and autograders were primarily created by John DeNero (denero@cs.berkeley.edu) and Dan Klein (klein@cs.berkeley.edu). Student side autograding was added by Brad Miller, Nick Hay, and Pieter Abbeel (pabbeel@cs.berkeley.edu).
This version was modified by Christian Shelton (cshelton@cs.ucr.edu) on June 23, 2020 to run under Python 3.
And then, the project has been updated for CAU CSE 17182 course (Artificial Intelligence).
run python capture.py
make your agents by modifying myTeam.py
run python capture.py --red=myTeam to test your team as Red
run python capture.py --help to see other options
최종 제출 대상은 루트의 myTeam.py입니다. createTeam()의 기본값은 AdaptiveAgent 두 명이며, 지금까지 구현한 상대 적응형 전략, 수비 추론, tactical safety, endgame policy는 모두 myTeam.py 안에 들어 있습니다.
agents.md와 ADAPTIVEAGENTPLAN.md는 개발 지침과 단계별 구현 기록입니다. run_league.py, analyze_replays.py, frozenTeams/, tune_weights.py는 로컬 검증용 도구이며 과제 제출 파일은 아닙니다.
코드를 수정한 뒤 가장 먼저 실행합니다.
python3 -m py_compile myTeam.py그래픽으로 움직임을 보려면 --frameTime을 줍니다.
python3 capture.py -r myTeam -b baselineTeam --frameTime 0.2빠르게 결과만 보려면 quiet mode를 사용합니다.
python3 capture.py -r myTeam -b baselineTeam -q
python3 capture.py -r baselineTeam -b myTeam -q여러 판을 한 번에 돌릴 수도 있습니다.
python3 capture.py -r myTeam -b baselineTeam -q -n 10
python3 capture.py -r baselineTeam -b myTeam -q -n 10baseline qualification 확인용입니다.
python3 autograder.py -q최근 검증 기준으로 myTeam.py는 baseline 상대로 20/20을 달성했습니다.
frozenTeams/에는 baseline, balanced, pressure, hard defense, capsule rush, food rush, passive stall, ambush defender 계열의 독립 검증 상대가 들어 있습니다.
기본 layout에서 red/blue 양방향 단판 리그:
python3 run_league.py --games 1 --time 700 --layouts defaultCapture --roles both --fix-seed여러 layout 샘플 검증:
python3 run_league.py --games 1 --time 700 --layouts defaultCapture,RANDOM1,RANDOM2 --roles both --fix-seed특정 상대만 골라서 검증:
python3 run_league.py --opponents frozenTeams/frozen_pressure,frozenTeams/frozen_capsule_rush --games 3 --time 700 --layouts defaultCapture --roles both --fix-seed결과 파일을 남기려면 --jsonl, --csv를 지정합니다.
python3 run_league.py --games 3 --time 700 --layouts defaultCapture,RANDOM1,RANDOM2 --roles both --jsonl league_results.jsonl --csv league_results.csv기본적으로 run_league.py는 새로 생성된 replay를 지웁니다. replay를 남기고 싶으면 --keep-replays를 추가합니다.
특정 경기를 기록하려면 capture.py에 --record를 붙입니다.
python3 capture.py -r myTeam -b frozenTeams/frozen_pressure --red-name myTeam --blue-name frozen_pressure -q -i 700 -f --record생성된 replay를 분석합니다.
python3 analyze_replays.py 'replay/*.replay' --team myTeam --jsonl replay_analysis.jsonl --csv replay_analysis.csv분석기는 food/capsule 획득, death, carrying death, border loop, defense tracking 실패, low food pressure 같은 원인 label을 출력합니다.
기록된 경기를 다시 보려면 다음처럼 실행합니다.
python3 capture.py --replay replay/<파일명>.replay --frameTime 0.2tune_weights.py는 여러 weight 조합을 자동 실험해 _tuneTeam.py, tuning_results.jsonl, tuning_best.json을 생성합니다. 이 파일들은 로컬 실험 산출물이므로 .gitignore에 포함되어 있습니다.
짧은 실험:
python3 tune_weights.py --minutes 5 --quick-games 1 --layouts defaultCapture여러 layout을 포함한 실험:
python3 tune_weights.py --minutes 30 --quick-games 1 --layouts defaultCapture,RANDOM1,RANDOM2튜닝 결과를 그대로 제출하지 말고, 좋은 값이 확인되면 myTeam.py 내부 상수에 직접 반영한 뒤 다시 autograder와 리그 검증을 실행합니다.
python3 -m py_compile myTeam.py
python3 autograder.py -q
python3 run_league.py --games 1 --time 700 --layouts defaultCapture --roles both --fix-seed제출 또는 대회용 핵심 파일은 myTeam.py입니다. GitHub에는 검증 도구와 문서를 같이 올릴 수 있지만, replay, cache, tuning 결과, PDF 원본, 임시 팀 파일은 .gitignore로 제외합니다.
The challenge is to design agents to play Capture-the-Flag in a Pacman-like arena.
Layout: The Pacman map is divided into two halves: blue (right) and red (left). Red agents (which all have even indices) must defend the red food while trying to eat the blue food. When on the red side, a red agent is a ghost. When crossing into enemy territory, the agent becomes a Pacman.
Scoring: When a Pacman eats a food dot, it earns one point per food pellet. Red team scores are positive, while Blue team scores are negative.
Eating Pacman: When a Pacman is eaten by an opposing ghost, the Pacman returns to its starting position (as a ghost). Three points are awarded for eating an opponent.
Power capsules: If Pacman eats a power capsule, agents on the opposing team become “scared” for the next 40 moves, or until they are eaten and respawn, whichever comes sooner. Agents that are “scared” are susceptible while in the form of ghosts (i.e. while on their own team’s side) to being eaten by Pacman. Specifically, if Pacman collides with a “scared” ghost, Pacman can eat the ghost (and earn three points), and the ghost respawns at its starting position (no longer in the “scared” state).
Turn Order: In each game, agents act in the following fixed order: Red Agent 1 → Blue Agent 1 → Red Agent 2 → Blue Agent 2. Therefore, the Red team always moves slightly earlier than the Blue team.
Observations: Agents can only observe an opponent's configuration (position and direction) if they or their teammate is within 5 squares (Manhattan distance). In addition, an agent always gets a noisy distance reading for each agent on the board, which can be used to approximately locate unobserved opponents.
Winning: A game ends when one team eats all but two of the opponents' dots. Games are also limited to 3000 agent moves (750 moves per each of the four agents). If this move limit is reached, whichever team has eaten the most food wins. If the score is zero (i.e., tied) this is recorded as a tie game.
Computation Time: Each agent has 1 second to return each action. Each move which does not return within one second will incur a warning. After three warnings, or any single move taking more than 3 seconds, the game is forfeit. There will be an initial start-up allowance of 5 seconds (use the registerInitialState method). If you agent times out or otherwise throws an exception, an error message will be present in the log files, which you can download from the results page (see below).
CaptureAgent (in captureAgent.py) is a useful base class for your agents.
It has a variety of methods that can return useful information. This includes a distancer field that contains a distanceCalculator object that can automatically calculate (and cache) the distances between every two points in the maze.
GameState (in capture.py) has still more information that can be queried. A current GameState object is passed into your agents' chooseAction methods. Note that GameState objects can return the set of legal actions for an agent and can generate new GameState s that would result from any action.
game.py has code that defines Directions, Configurations, AgentState, and a Grid, all of which might be handy and save extra work on your part.
util.py has code that might prove helpful. Of particular note is the Counter class which implements a dictionary, but where unused keys default to mapping to 0 (instead of undefined). A Counter mapping positions (integer pairs) to a real value can be used with CaptureAgent.displayDistributionsOverPositions to color the cells on the map with debugging information.
myTeam.py has skeleton code for generating a team of agents. Its format should not be changed and needs to have the function createTeam as specified. You should copy this file, change its name, and use it to build your own team.