Course: Artificial Intelligence (5DV243)
Author: Michail Pettas
A competitive Othello (Reversi) game engine that uses Alpha-Beta pruning with Iterative Deepening Search (IDS) to select optimal moves within time constraints. The engine is designed to outperform a naive fixed-depth implementation.
Othello/
├── Introduction.txt # Assignment specifications
├── report.tex # LaTeX report
├── Python/
│ ├── Othello.py # Main entry point
│ ├── AlphaBeta.py # Alpha-Beta search implementation
│ ├── OthelloPosition.py # Game state representation
│ ├── OthelloAction.py # Move representation
│ ├── OthelloAlgorithm.py # Algorithm interface
│ ├── OthelloEvaluator.py # Evaluator interface
│ ├── CountingEvaluator.py # Basic piece-count heuristic
│ ├── ImprovedEvaluator.py # Advanced position-weighted heuristic
│ ├── FastEvaluator.py # Optimized evaluation
│ └── othello.sh # Execution script
└── test_code/
├── othellostart.sh # Game runner script
└── othello_naive.sh # Naive opponent
Othello is played on an 8×8 board:
- White (O) always starts (MAX player)
- Black (X) is the MIN player
- Players place pieces to capture opponent's pieces
- Game ends when no legal moves exist for both players
- Winner has the most pieces
- Minimax search with alpha-beta cutoffs
- Significantly reduces search space
- Starts at depth 1, incrementally increases
- Returns best move from last completed depth
- Guarantees a move within time limit
Corner weights: 120 (highly valuable)
Edge weights: 20 (moderately valuable)
X-squares: -20 (dangerous positions)
C-squares: -40 (very dangerous)
- Transposition tables: Cache evaluated positions
- Move ordering: Examine promising moves first
- History heuristics: Learn from successful moves
# Navigate to Python directory
cd Othello/Python
# Run with position string and time limit
python Othello.py "WEEEEEEEEEEEEEEEEEEEEEEEEEEEOXEEEEEEXOEEEEEEEEEEEEEEEEEEEEEEEEEEE" 5
# Using the shell script
bash othello.sh "WEEEEEEEEEEEEEEEEEEEEEEEEEEEOXEEEEEEXOEEEEEEEEEEEEEEEEEEEEEEEEEEE" 5 0-
Position string (65 chars):
- First char:
W(White to move) orB(Black to move) - Next 64 chars: Board state (
E=empty,O=white,X=black) - Reading order: top-left to bottom-right, row by row
- First char:
-
Time limit: Seconds allowed for move computation
- Move in format
(row,column)using 1-based indexing passif no legal moves exist
# Play your engine (white) vs naive (black)
bash test_code/othellostart.sh Python/othello.sh test_code/othello_naive.sh 5
# Play naive (white) vs your engine (black)
bash test_code/othellostart.sh test_code/othello_naive.sh Python/othello.sh 5The engine must outperform the naive Alpha-Beta player:
- Time limits: 2-10 seconds
- Tested as both White and Black
- Naive uses fixed depth 7 with simple piece-count evaluation
- Python 3.10+
- No external dependencies (pure Python implementation)
| Class | Description |
|---|---|
Othello |
Main program, handles I/O and time control |
AlphaBeta |
Alpha-Beta search with IDS |
OthelloPosition |
Board state, move generation |
OthelloAction |
Move representation |
ImprovedEvaluator |
Position-weighted heuristic |
- Russell, S., & Norvig, P. (2020). Artificial Intelligence: A Modern Approach
- Othello Rules (Wikipedia)