A modern, object-oriented Java implementation of the classic Reversi (Othello) strategy board game built using the Model-View-Controller (MVC) design pattern and Java Swing.
This application features a unique synchronized dual-window interface allowing two local players to play head-to-head with 180-degree view rotation for Player 2, an integrated Greedy AI bot for single-player practice, dynamic multi-directional capture flipping, and anti-aliased graphical rendering.
- Dual-Window Perspective Display: Renders simultaneous, synchronized viewports for Player 1 (White) and Player 2 (Black). Player 2's board is rotated 180° to reflect an authentic tabletop head-to-head orientation.
- Greedy AI Player: Integrated automated decision-making algorithm that evaluates all legal board positions and selects the move maximizing immediate piece captures.
- Anti-Aliased 2D Graphics: Custom Swing components with vector-based disc rendering, subtle drop shadows, crisp outlines, and classic green felt board styling.
- Multi-Directional Capture Engine: Complete move validation and piece-flipping logic checking all 8 compass directions (Horizontal, Vertical, Diagonal).
- Turn & End-Game Detection: Automatic handling of forced turn skips when a player has no valid moves, along with full-board and tie detection score calculations.
- CLI & GUI Viewports: Modular presentation layer supporting both rich Graphical UI (
GUIView) and Terminal/CLI text modes (TextView). - Diagnostic Test Suite: Built-in test harness (
SimpleTestModel) for simulating edge-case board configurations, full-board scenarios, and AI playout simulations.
The project strictly follows the Model-View-Controller (MVC) design pattern to decouple game logic, state management, and user interfaces:
+-------------------------+
| ReversiMain |
+------------+------------+
| (Wires components)
v
+---------------------+---------------------+
| |
v v
+-----------------+ Notifies / Refreshes +-----------------+
| IModel | <------------------------ | IView |
| (SimpleModel) | | (GUIView) |
+--------+--------+ +--------+--------+
^ |
| User Actions |
+---------------------------------------------+
|
v
+-------------------+
| IController |
| (ReversiControl) |
+-------------------+
| Component | Class / Interface | Description |
|---|---|---|
| Main | ReversiMain |
Application entry point and dependency injection container. |
| Model | IModel |
Interface defining board representation and state queries. |
SimpleModel |
Grid-based board state storage and turn management. | |
SimpleTestModel |
Extension of SimpleModel with interactive test controls. |
|
| Controller | IController |
Interface for game rule execution and automated moves. |
ReversiController |
Implements legal move validation, 8-way directional flips, and Greedy AI. | |
| View | IView |
Interface for board visualization and user notifications. |
GUIView |
Dual-window Java Swing graphical user interface. | |
TextView |
Terminal/Console text interface with command parser. | |
BoardSquareButton |
Custom JButton rendering anti-aliased game discs. |
|
ColorLabel / ConsoleInput |
UI indicator labels and keyboard input utilities. |
Outnumber your opponent by having the majority of your colored discs on the board at the end of the game.
- Starting Position: The game starts with 4 pieces placed in the center of an 8x8 grid (2 White, 2 Black).
- Making a Move: Players take turns placing a disc of their color on an empty square.
- Flanking & Flipping: A move must trap one or more opposing discs between the placed disc and another disc of the active player's color along a straight line (horizontal, vertical, or diagonal). All trapped opposing discs are flipped to the active player's color.
- Turn Skipping & Game Over: If a player has no legal moves, their turn is automatically passed. The game ends when neither player can make a valid move.
- Click Board Square: Attempt to play a disc on the selected grid cell.
- Greedy AI Button: Instruct the AI to calculate and play the optimal move for that player.
- Restart Game: Clear the board and start a new game session.
- Java Development Kit (JDK): Version 8 or higher installed on your system.
-
Clone the repository:
git clone https://github.com/your-username/reversi.git cd reversi -
Compile the Java source files into the
binoutput directory:javac -d bin src/reversi/*.java -
Launch the game:
java -cp bin reversi.ReversiMain
- Open or import the project directory into your favorite IDE.
- Mark
srcas the Source Root directory. - Run
reversi.ReversiMainas a Java Application.