This project mainly focuses on discovering an FSM application in Pac-Man. FSM is primarily used on defining ghost behavior including chasing, dodging, surrounding, etc. The game includes five different types of ghosts which reproduce the classical Pac-Man ghost behavior and also a highly custom ghost. Four different kinds of player mode are also included: Random mode which basically just does a random walk in the game, Greedy mode which uses the classical greedy algorithm in order to collect as many pellets as they can, Coward mode which is set to avoid ghosts as the primary goal, and Player mode which allows player to have full control of Pac-Man. The game is using Unity and you can find the source code here.
Instruction
In the Admin Gameobject, you can change the number and type of ghosts by editing the Ghost under GhostManager.
For the player behavior pattern, you need you replace the Agent GameObject in Scene1 with the agent in the Pacman Agents folder.
The ghost behavior system in this Pac-Man project is structured entirely around a classic Finite State Machine (FSM). Each ghost—whether Pinky, Clyde, or a custom-designed agent—functions as an autonomous state machine whose behavior depends on its current “state” and transitions between states. At the foundation of this system is the abstract State class, which defines a consistent interface for all ghost behaviors. Every state—such as Scatter, Frightened, Eyes, or any custom chase behavior—implements three core methods: EnterState, Update, and ExitState. These methods respectively set up the behavior when the state is entered, execute the logic that runs each frame, and clean up when switching to a new state.