A classic Othello (Reversi) board game implementation using Python and the Pygame library. Play against an AI opponent powered by the Minimax algorithm with Alpha-Beta pruning.
- Graphical Othello board and pieces rendered using Pygame.
- Full implementation of Othello rules, including capturing opponent pieces.
- Human vs. AI gameplay.
- AI opponent utilizes the Minimax algorithm with Alpha-Beta pruning for move selection.
- AI uses a positional weighting heuristic to evaluate board states.
- Valid moves for the human player are visually highlighted.
- Real-time score display showing the count for Black and White pieces.
- Automatic detection of game end conditions (when neither player has a valid move).
- Clear indication of the winner (Black, White, or Draw) upon game completion.
- Clean, object-oriented code structure (refactored from an initial procedural version).
- Python 3.x (tested with 3.7+)
- Pygame library
- Run the game script from your terminal.
- The game window will open.
- By default, you play as Black, and the AI plays as White.
- On your turn, valid moves will be indicated by small, semi-transparent yellow circles.
- Click on one of the highlighted squares to place your piece. The corresponding opponent pieces will be flipped.
- The AI will then automatically calculate and make its move.
- The game continues alternating turns. If a player has no valid moves, their turn is skipped.
- The game ends when neither player has any valid moves left.
- The final score and the winner (or Draw) will be displayed at the bottom of the screen.
You can modify the following constants near the top of the .py file:
HUMAN_PLAYER: Change this fromBLACKtoWHITEin themain()function if you want to play as White against a Black AI.PLY_DEPTH: Adjust the AI's search depth. Higher values mean a stronger (but slower) AI. Lower values mean a weaker (but faster) AI. The default is reasonably challenging. Values above 6 or 7 can become very slow depending on your hardware.- Colors and screen dimensions can also be adjusted in the constants section if desired.
- Constants: Defines game parameters, colors, board states, dimensions, and AI settings.
- Helper Functions: Utility functions like
opponent(),to_board_index(),to_row_col(). OthelloGameclass: Encapsulates the game board, current player, rules logic (checking/making moves, determining winner, calculating score).AIPlayerclass: Contains the AI logic, including thealphabetasearch algorithm and board evaluation methods.- Drawing Functions:
draw_board(),draw_valid_moves(),draw_score()handle rendering the game state using Pygame. main()function: Initializes Pygame, creates game objects, runs the main game loop, handles events, and manages player/AI turns.
Files: OTHELLO.BAS: original Othello game for QuickBASIC OTHELLO_FB.BAS: othello game for FreeBASIC othello.py: Python version using pygame library for graphics