CornerStone is a complete, playable desktop Othello (Reversi) game with a formidable AI opponent named "FlipFish." This project was built from the ground up to implement and showcase advanced artificial intelligence search algorithms in a polished, user-friendly package.
- Multiple Game Modes:
- Player vs. AI: Challenge the highly intelligent FlipFish engine.
- Player vs. Player: Enjoy a classic match with a friend on the same machine.
- AI vs. AI: Watch two instances of the FlipFish engine battle for supremacy to observe its strategies.
- Intelligent AI Opponent: "FlipFish" is a challenging opponent that uses a combination of modern AI techniques to find the optimal move.
- Polished User Interface: Built with Pygame, the interface is designed to be clean and responsive, featuring smooth piece-flipping animations and highlighted valid moves.
- In-Game Hint System: At any point during a match, the player can request a suggested move from the AI.
- Dynamic Strategy: The AI's evaluation function is not static; it adapts as the game progresses, shifting its focus from board control in the opening to a pure piece-count advantage in the endgame.
The heart of CornerStone is the FlipFish
AI. It finds the optimal move by performing a deep search of millions of possible future game states. Here are the key concepts that power its intelligence:
-
Minimax with Alpha-Beta Pruning: The core search algorithm explores the tree of possible moves. Alpha-beta pruning intelligently prunes entire branches of the search tree that are guaranteed not to contain the best move, allowing the AI to search much deeper within a given time limit.
-
Iterative Deepening: Instead of choosing a fixed search depth, FlipFish starts by searching to a depth of 1, then 2, then 3, and so on. This "anytime" algorithm ensures it always has a good move ready, even if the time limit is reached unexpectedly.
-
Transposition Table: A hash map that stores the evaluation of previously analyzed game states. This powerful form of memoization prevents the AI from re-calculating the same position if it is reached through a different sequence of moves, saving enormous amounts of computation.
-
Advanced Evaluation Heuristics: The AI's decision-making is guided by a weighted evaluation function that considers multiple strategic factors:
- Positional Value: Pieces in corners and on stable edges are weighted far more heavily.
- Mobility: Maximizing its own number of available moves while minimizing the opponent's is a key strategic driver.
- Piece Stability: It identifies "stable" pieces that can never be flipped back by the opponent.
- Corner Control: It understands the supreme strategic importance of capturing the board's corners.
-
Quiescence Search: To avoid the "horizon effect" (where a critical capture is just beyond the main search depth), the AI performs a shallow, secondary search on "volatile" positions to ensure its evaluation is stable and accurate.
-
Perfect Endgame Solver: For the final 12 moves of the game, the search depth is sufficient to solve the game state perfectly, allowing FlipFish to play flawlessly until the end.
- Language: Python
- Library: Pygame (for the game engine, UI, and graphics)
- Python 3.8 or newer
- Pygame
-
Clone the repository to your local machine:
git clone https://github.com/mohamadhabibimanesh/CornerStone.git cd CornerStone
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the game:
python main.py
This project is licensed under the MIT License. See the LICENSE file for more details.