A comprehensive C++ implementation of the classic Pacman game with advanced AI strategies, save/load functionality, and multi-level support.
This is a console-based Pacman game developed in C++ that features multiple game boards, intelligent ghost AI with different difficulty levels, and a complete game recording/playback system. The game supports both interactive play and automated replay of saved games.
- Multiple Game Modes: Normal play, Save gameplay, Load and replay saved games
- AI-Driven Ghost Strategies: Three difficulty levels with different AI algorithms
- Multiple Game Boards: Pre-designed levels with varying difficulty
- Color Support: Optional colorized console output
- Game Recording: Complete save/load system for gameplay analysis
- Cross-platform Design: Built for Windows console applications
- PacmanGame: Main game controller managing game flow, board initialization, and game states
- Board: Game field representation with collision detection and position management
- Creature Hierarchy: Base class for all moving entities (Pacman, Ghosts, Fruits)
- Strategy Pattern: Pluggable AI algorithms for ghost behavior
- Menu System: User interface for game configuration and navigation
- Strategy Pattern: Different AI behaviors for ghosts (Best, Good, Novice)
- Inheritance: Creature base class extended by Pacman, Ghost, and Fruit
- Template Method: Game loop structure with customizable behaviors
- State Pattern: Different game modes (Normal, Save, Load, Load Silent)
Creature (Base Class)
├── Pacman (Player character)
├── Ghost (AI-controlled enemies)
└── Fruit (Collectible items)
Strategy (Interface)
├── Best (Advanced AI using BFS)
├── Good (Intermediate AI with timing)
└── Novice (Basic AI behavior)
PacmanGame (Main Controller)
├── Board (Game field)
├── Menu (User interface)
└── Position (Coordinate system)
- Best Strategy: Uses Breadth-First Search (BFS) algorithm to find optimal paths to Pacman
- Good Strategy: Combines pathfinding with timing-based decisions
- Novice Strategy: Simple movement patterns with basic decision-making
- Normal Mode: Standard interactive gameplay
- Save Mode: Play while recording all moves to files
- Load Mode: Replay previously saved games with visual output
- Load Silent Mode: Replay games without visual output for analysis
- A or a: Move LEFT
- D or d: Move RIGHT
- W or w: Move UP
- X or x: Move DOWN
- S or s: STAY in place
- ESC: Pause game (press ESC again to resume)
Core Game Logic:
main.cpp- Entry point and command-line argument processingPacmanGame.cpp/h- Main game controller and logicBoard.cpp/h- Game board management and collision detection
Game Entities:
Creature.cpp/h- Base class for all moving entitiesPacman.cpp/h- Player character implementationGhost.cpp/h- Enemy character implementationFruit.cpp/h- Collectible fruit items
AI System:
Strategy.h- Strategy pattern interfaceBest.cpp/h- Advanced AI strategy using BFSGood.cpp/h- Intermediate AI strategyNovice.cpp/h- Basic AI strategyBFS.cpp/h- Breadth-First Search algorithm implementation
Utilities:
Position.cpp/h- 2D coordinate systemUtilities.cpp/h- Console manipulation and helper functionsMenu.cpp/h- User interface menusEnum.h- Game constants and enumerations
Board Files:
Pacman_A.screen- Level A layoutPacman_B.screen- Level B layoutPacman_C.screen- Level C layout
Recorded Gameplay:
Pacman_*.steps- Movement recordings for replayPacman_*.result- Game outcome data
file_format.txt- Detailed specification of save file formatsREADME.md- This comprehensive project documentation
- Windows Operating System (uses Windows Console API)
- Microsoft Visual Studio (2017 or later recommended)
- Windows SDK for console manipulation functions
-
Using Visual Studio:
Open "Pacman ex3.sln" in Visual Studio Build → Build Solution (Ctrl+Shift+B) -
Using MSBuild (Command Line):
msbuild "Pacman ex3.sln" /p:Configuration=Release
The project uses Windows-specific libraries:
windows.h- Console manipulationconio.h- Keyboard input handling- Standard C++ libraries (iostream, fstream, vector, etc.)
# Normal interactive game
PacmanGame.exe
# Save gameplay while playing
PacmanGame.exe -save
# Save gameplay in silent mode (no visual output)
PacmanGame.exe -save -silent
# Load and replay saved game
PacmanGame.exe -load
# Load and replay in silent mode
PacmanGame.exe -load -silent- Start the game: Run the executable
- Choose mode: Select from the main menu
- (1) Start with color support
- (2) Start without color support
- (8) View instructions
- (9) Exit
- Select difficulty: Choose AI strategy level
- (a) BEST - Advanced AI
- (b) GOOD - Intermediate AI
- (c) NOVICE - Basic AI
- Choose board: Select from available levels or play all sequentially
- Primary Goal: Eat all breadcrumbs (*) on the board
- Avoid: Getting caught by ghosts ($)
- Bonus: Collect fruits (5-9) for extra points
- Lives: Start with 3 lives, lose one when caught by ghost
- Winning: Clear all breadcrumbs to advance to next level
The game uses a sophisticated recording system documented in file_format.txt:
Steps Files (*.steps):
- Record every game action with timestamps
- Track creature movements and direction changes
- Support fruit appearance/disappearance events
- Enable precise gameplay reproduction
Result Files (*.result):
- Record game outcomes (win/lose conditions)
- Track timestamps of significant events
- Enable game analysis and statistics
Recording a game session:
PacmanGame.exe -save
# Creates Pacman_A.steps and Pacman_A.result filesReplaying recorded session:
PacmanGame.exe -load
# Replays using existing .steps and .result files- Real-time Gameplay: 100ms game loop cycle
- Ghost Movement: Every 2nd game cycle
- Fruit Logic: Every 10th game cycle
- Memory Usage: Efficient board representation (81x25 character array)
Best Strategy (BFS):
- Implements breadth-first search for optimal pathfinding
- Guarantees shortest path to player
- Higher computational complexity but optimal play
Good Strategy:
- Combines BFS with timing-based decisions
- Balances performance and challenge
- Adapts behavior based on game progression
Novice Strategy:
- Simple rule-based movement
- Predictable patterns for beginner-friendly gameplay
- Minimal computational overhead
This project was developed by:
- Ori Braverman
- Shachar Levy
This represents the third iteration of the Pacman game development, featuring:
- Complete object-oriented design
- Robust save/load functionality
- Multiple AI difficulty levels
- Comprehensive error handling
- Extensible architecture for future enhancements
This project is an academic implementation developed as part of a computer science curriculum. Please respect academic integrity guidelines when using this code.
For detailed technical specifications of file formats and internal APIs, please refer to file_format.txt and the source code documentation.