An interactive implementation of the classic Game of Nim featuring multiple AI difficulties and strategic gameplay mechanics.
This project implements the Game of Nim, a mathematical strategy game where two players take turns removing marbles from their opponent's pile. The game features:
- Multiple AI difficulty levels (Easy/Hard)
- Interactive console-based gameplay
- Customizable player names
- Turn order randomization or selection
- Real-time game state visualization
- Each player starts with a randomly generated pile of marbles (20-95)
- Players take turns removing marbles from their opponent's pile
- On each turn, a player can remove up to half of the opponent's current marbles (rounded up)
- The player whose pile gets depleted first wins
-
Two AI Difficulty Levels:
- Easy (Random Strategy): Makes random valid moves
- Hard (Smart Strategy): Uses strategic pile targeting for more challenging gameplay
-
Interactive Gameplay:
- Custom player names
- Choice of first player or random selection
- Real-time marble count display
- Move validation and error handling
- Java Development Kit (JDK) 8 or higher
- Java Runtime Environment (JRE)
- Clone the repository
git clone https://github.com/[your-username]/game-of-nim.git
- Navigate to the project directory
cd game-of-nim
- Compile the Java files
javac Main.java
- Run the game
java Main
- Launch the game
- Enter your name and your opponent's name
- Choose difficulty level (A: Easy or B: Hard)
- Decide turn order (Random or Choose)
- Take turns removing marbles from your opponent's pile
- Try to force your opponent to deplete their pile first
The project uses:
- Object-Oriented Programming principles
- Interface-based design
- Strategy pattern for AI implementations
- Input validation and error handling
- Resource management mechanics
Main.java
: Game entry point and main loopNim.java
: Core game mechanics and state managementGamer.java
: Interface for player implementationsStudent.java
: Human player implementationBelowAveragePC.java
: Easy AI implementationSmartPC.java
: Hard AI implementationPile.java
: Marble pile management
This project is licensed under the MIT License - see the LICENSE file for details