A complete implementation of the classic Othello (Reversi) board game built with Unity, featuring an intelligent AI opponent powered by the Minimax algorithm with alpha-beta pruning.
Othello (also known as Reversi) is a classic strategy board game for two players. This project implements the complete game with an AI opponent that uses the Minimax algorithm with alpha-beta pruning to provide a challenging gameplay experience.
The game is built entirely in Unity and includes support for three game modes:
- Human vs Human
- Human vs AI
- AI vs AI (watch the AI play against itself!)
- Intelligent AI Opponent: Implements Minimax algorithm with alpha-beta pruning at depth 4
- Multiple Game Modes: Play against a friend, challenge the AI, or watch two AIs compete
- Visual Feedback:
- Valid moves are highlighted in real-time
- Last move indicator
- Piece count display for both players
- Full Game Rules Implementation:
- Automatic piece flipping in all 8 directions
- Pass detection when no valid moves available
- Game end detection (board full, no pieces, or double pass)
- Winner determination
- User-Friendly Interface:
- Clean 3D board representation
- Easy-to-use mouse controls
- Play again functionality without restarting
- Unity 2018.3.6f1 or compatible version
- Basic understanding of Unity interface
-
Clone the repository:
git clone https://github.com/almiab1/OthelloAI.git
-
Open the project in Unity:
- Launch Unity Hub
- Click "Add" and select the cloned project folder
- Open the project with Unity 2018.3.6f1
-
Load the game scene:
- Navigate to
Assets/Scenes/ - Open
SampleScene.unity
- Navigate to
-
Run the game:
- Press the Play button in Unity Editor
- Or build the project for your target platform (File → Build Settings)
Othello is played on an 8×8 board with pieces that are black on one side and white on the other:
- The game starts with 4 pieces in the center (2 black, 2 white)
- Black always moves first
- Players must place a piece to flank one or more opponent pieces
- All flanked opponent pieces are flipped to the current player's color
- Flanking can occur in any of the 8 directions (horizontal, vertical, diagonal)
- If a player has no valid moves, they must pass
- The game ends when:
- The board is full
- One player has no pieces remaining
- Both players pass consecutively
- The player with the most pieces wins
You can configure game modes by editing the Constants.cs file:
public const string Player1 = "HUMAN"; // Options: "HUMAN" or "AI"
public const string Player2 = "AI"; // Options: "HUMAN" or "AI"
public const int Start = 1; // 1 for Black, -1 for White- Human vs AI:
Player1 = "HUMAN",Player2 = "AI" - Human vs Human:
Player1 = "HUMAN",Player2 = "HUMAN" - AI vs AI:
Player1 = "AI",Player2 = "AI"
public const int Black = 1;
public const int White = -1;
public const int PassTime = 2; // Seconds to wait when a player passesThe AI uses a Minimax algorithm with alpha-beta pruning to make intelligent decisions:
- Search Depth: 4 levels deep
- Pruning: Alpha-beta pruning for optimization
- Evaluation Function: Based on the number of pieces that would be flipped by each move
- Node Structure: Game tree with MIN and MAX nodes alternating by level
- Tree Generation: The AI generates a game tree of possible moves up to depth 4
- Evaluation: Each leaf node is evaluated based on potential piece captures
- Minimax:
- MAX nodes try to maximize the score (AI's moves)
- MIN nodes try to minimize the score (opponent's moves)
- Alpha-Beta Pruning: Cuts off branches that won't affect the final decision
- Move Selection: The AI selects the move with the best evaluated outcome
- Player.cs: Contains the AI logic and Minimax implementation
- Node class: Represents nodes in the game tree with board state and utility values
- BoardManager.cs: Handles board logic, move validation, and piece flipping
OthelloAI/
├── Assets/
│ ├── Materials/ # Materials for pieces and board
│ │ ├── Black.mat # Black piece material
│ │ ├── White.mat # White piece material
│ │ └── Tile_*.mat # Board tile materials
│ ├── Prefabs/ # Game object prefabs
│ │ ├── Piece.prefab # Othello piece prefab
│ │ └── LastMovement Variant.prefab
│ ├── Scenes/ # Unity scenes
│ │ └── SampleScene.unity
│ └── Scripts/ # C# game scripts
│ ├── Constants.cs # Game constants and configuration
│ ├── Controller.cs # Main game controller
│ ├── Player.cs # AI logic (Minimax)
│ ├── BoardManager.cs # Board state management
│ ├── Tile.cs # Tile data structure
│ └── TileBehaviour.cs # Tile interaction handling
├── ProjectSettings/ # Unity project settings
├── LICENSE # GPL-3.0 License
└── README.md # This file
- Constants.cs: Defines game constants (board size, player types, colors)
- Controller.cs: Manages game flow, UI updates, and player turns
- Player.cs: Implements AI decision-making with Minimax algorithm
- BoardManager.cs: Core game logic (valid moves, piece flipping, board state)
- Tile.cs: Data structure representing a board tile
- TileBehaviour.cs: Handles mouse input on tiles
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
Project Link: https://github.com/almiab1/OthelloAI
Made with ❤️ and Unity