This is an enhanced version of the classic Isolation board game, implemented using Pygame. Players take turns moving their pieces across a grid, blocking off squares as they go. The last player to make a valid move wins. This version includes a Player vs. AI mode with a Minimax algorithm, Player vs. Player mode, animated UI elements, and enhanced graphics.
This project was developed for the Foundations of AI course.
- Prawin Kumar S
- Malathi G
- Player vs. AI Mode: Challenge an AI opponent powered by the Minimax algorithm with Alpha-Beta Pruning.
- Player vs. Player Mode: Play against a friend on the same computer.
- Multiple Piece Types: Choose from King, Queen, Rook, Knight, Bishop, or Pawn, each with their unique movement patterns.
- Animated User Interface: Enjoy smooth transitions, particle effects, and gradient backgrounds.
- Dynamic Game Board: Visually appealing grid with highlighted valid moves and blocked squares.
- Game Over Screen: Clear display of the winner and game statistics.
Upon launching the game, you'll be greeted by an animated main menu. Press any key to proceed to mode selection.
Choose between "Player vs AI" or "Player vs Player" mode.
- Player vs AI: You (Player 1) will play against the computer.
- Player vs Player: Two players will take turns on the same keyboard/mouse.
After selecting the game mode, you'll choose a piece type for Player 1 (and Player 2 in PvP mode). Each piece has distinct movement rules:
- King: Moves one square in any direction (horizontal, vertical, or diagonal).
- Queen: Moves any number of squares along any rank, file, or diagonal.
- Rook: Moves any number of squares along any rank or file.
- Knight: Moves in an 'L' shape (two squares in one direction, then one square perpendicularly).
- Bishop: Moves any number of squares diagonally.
- Pawn: Moves one square forward (Player 1 moves up, Player 2 moves down).
- Starting Positions: Player 1 starts at the bottom-left corner, and Player 2 (or AI) starts at the top-right corner.
- Making a Move:
- Click on your piece to select it. Valid moves will be highlighted on the board.
- Click on a highlighted square to move your piece to that position.
- The square you just moved from becomes blocked and cannot be used again by either player.
- Winning: The game ends when a player cannot make any valid moves. The other player wins.
- Mouse Click: Interact with UI elements and make moves on the board.
- ESC: Go back to the previous menu (from mode selection, piece selection, or reset game from playing/game over).
- R: Restart the game (from game over screen).
To run this game, you need Python and Pygame installed.
-
Clone the repository (or download
main.py):git clone https://github.com/your-username/isolation-game.git cd isolation-game(Note: Replace
https://github.com/your-username/isolation-game.gitwith the actual repository URL if available, or simply ensuremain.pyis in your working directory.) -
Install Pygame:
pip install pygame
Navigate to the directory containing main.py in your terminal and run:
python main.pyThe AI uses a Minimax algorithm with Alpha-Beta Pruning to determine its moves.
- Evaluation Function: The AI evaluates game states based on:
- The number of valid moves available to itself versus the opponent.
- Future mobility (how many moves it can make from potential next positions).
- A bonus for blocking the opponent's best future squares.
- Depth: The AI searches up to a predefined depth (default is 4 moves ahead) to find the optimal move.
main.py: Contains the entire game logic, UI rendering, and AI implementation.PieceType(Enum): Defines the types of pieces.Player(Enum): Defines players (Human, AI, Player1, Player2).GameMode(Enum): Defines game modes (PvP, PvA).Animationclass: Handles smooth movement animations.Particleclass: Manages visual particle effects.GameStateclass: Manages the game board, piece positions, and game state.IsolationAIclass: Implements the Minimax algorithm with Alpha-Beta Pruning.IsolationGameclass: The main game class, handling Pygame initialization, event loops, rendering, and game flow.
- More sophisticated AI evaluation functions.
- Different difficulty levels for AI.
- Sound effects and background music.
- Customizable board sizes.
- Online multiplayer.
- Improved piece graphics (e.g., 3D rendering).
This project is open-source and available under the MIT License.