Gambitron is a cutting-edge chess AI application that combines modern web development with sophisticated artificial intelligence algorithms. Built with React/TypeScript frontend and Python backend, it delivers a professional chess experience with real-time gameplay, advanced AI decision-making, and responsive design.
- Minimax Algorithm with Alpha-Beta Pruning for optimal move selection
- Piece-Square Tables for positional evaluation (Pawn, Knight, Bishop, Rook, Queen)
- Material Evaluation with sophisticated piece value calculations
- Center Control and Pawn Advancement bonuses
- Bishop Pair and Rook Mobility evaluation
- King Safety assessment for endgame scenarios
- Real-time Chess Board with drag-and-drop piece movement
- Move Validation ensuring only legal moves are allowed
- Pawn Promotion with interactive piece selection dialog
- Game State Persistence with localStorage integration
- Move Highlighting showing valid moves for selected pieces
- Game History tracking and replay capabilities
- Dual Timers for both player and AI
- Configurable Time Controls (1-30 minutes)
- Visual Timer Indicators with active/inactive states
- Time Persistence across browser sessions
- Real-time Updates with smooth countdown animations
- Desktop Layout with sidebar game information
- Mobile Layout optimized for touch devices
- Adaptive UI that works on all screen sizes
- Modern Dark Theme with professional styling
- Social Media Integration with GitHub, LinkedIn, and LeetCode links
- Admin Panel for FEN position loading and testing
- Error Handling with retry mechanisms
- API Integration with AWS Lambda backend
- CORS Support for cross-origin requests
- TypeScript for type safety and better development experience
frontend/
โโโ src/
โ โโโ components/
โ โ โโโ board/
โ โ โ โโโ Board.tsx # Main game logic and state management
โ โ โ โโโ Board.css # Board-specific styles
โ โ โโโ tile/
โ โ โ โโโ tile.tsx # Individual chess square component
โ โ โ โโโ tile.css # Tile styling
โ โ โโโ ChessBoard.tsx # Chess board rendering
โ โ โโโ ChessPiece.tsx # Piece rendering and interactions
โ โ โโโ DesktopLayout.tsx # Desktop-specific layout
โ โ โโโ MobileLayout.tsx # Mobile-responsive layout
โ โ โโโ GameDialogs.tsx # Modal dialogs (promotion, start, endgame)
โ โ โโโ GameInfo.tsx # Game information display
โ โ โโโ Timer.tsx # Timer component
โ โ โโโ MobileTimer.tsx # Mobile timer variant
โ โ โโโ SocialLinks.tsx # Social media links
โ โโโ App.tsx # Main application component
โ โโโ main.tsx # Application entry point
โโโ public/
โ โโโ pieces/ # Chess piece SVG assets
โ โโโ readme/ # Documentation assets
โโโ package.json # Dependencies and scripts
lambda-backend/
โโโ backend.py # FastAPI application with chess logic
โโโ lambda.py # AWS Lambda handler
โโโ lambda-layer/
โ โโโ python/
โ โโโ chess/ # Python chess library
โ โโโ __init__.py
โ โโโ engine.py # Chess engine implementation
โ โโโ gaviota.py # Endgame tablebase support
โ โโโ pgn.py # PGN format support
โ โโโ polyglot.py # Opening book support
โ โโโ svg.py # SVG rendering
โ โโโ syzygy.py # Syzygy tablebase
โ โโโ variant.py # Chess variant support
โโโ requirements.txt # Python dependencies
The core AI engine uses the minimax algorithm enhanced with alpha-beta pruning for optimal performance:
def minimax(board_state: chess.Board, depth: int, alpha: float, beta: float, is_maximizing: bool) -> float:
if depth == 0 or board_state.is_game_over():
return evaluate_board_state(board_state)
if is_maximizing:
max_eval = float('-inf')
for move in board_state.legal_moves:
board_state.push(move)
move_eval = minimax(board_state, depth - 1, alpha, beta, False)
board_state.pop()
max_eval = max(max_eval, move_eval)
alpha = max(alpha, move_eval)
if beta <= alpha:
break # Alpha-beta pruning
return max_eval
else:
# Minimizing player logic...The AI evaluates positions using multiple sophisticated criteria:
- Material Values: Pawn (100), Knight (320), Bishop (330), Rook (500), Queen (900), King (20000)
- Piece-Square Tables: Positional bonuses for each piece type
- Center Control: Bonus for controlling central squares
- Pawn Advancement: Rewards for advanced pawns
- Bishop Pair: Bonus for having both bishops
- Rook Mobility: Evaluation based on rook movement options
- King Safety: Endgame king positioning
The AI optimizes move selection by:
- Capture Moves First: Prioritizes moves that capture pieces
- Material Value Sorting: Orders captures by piece value
- Alpha-Beta Pruning: Eliminates branches that won't affect the final decision
- Node.js (v14 or later)
- Python 3.x
- Git
-
Clone the repository:
git clone https://github.com/Cyrus-Krispin/gambitron cd gambitron/frontend -
Install dependencies:
npm install
-
Start development server:
npm run dev
-
Open your browser to
http://localhost:5173
-
Navigate to backend directory:
cd lambda-backend -
Create virtual environment:
python -m venv venv
-
Activate virtual environment:
# Windows venv\Scripts\activate # macOS/Linux source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Run the backend:
fastapi dev backend.py
- Start a New Game: Click "New Game" and select your preferred time control
- Make Moves: Click on a piece, then click on a valid destination square
- Pawn Promotion: When a pawn reaches the end, choose your promotion piece
- Timer Management: Watch the countdown timers for both you and the AI
- Game Over: The game automatically detects checkmate, stalemate, or timeouts
The application uses React hooks for state management:
- useState for local component state
- useEffect for side effects and API calls
- useMemo for performance optimization
- Custom hooks for game logic encapsulation
The frontend communicates with the backend via REST API:
- POST /move: Get AI's next move
- POST /evaluate: Evaluate current board position
- Error Handling: Comprehensive error management with retry mechanisms
- Move Generation: Efficient legal move generation using chess.js
- Alpha-Beta Pruning: Reduces search tree size by up to 50%
- Move Ordering: Prioritizes promising moves for better pruning
- Memoization: Caches expensive calculations
- Lazy Loading: Loads components only when needed
# Frontend
npm run dev # Start development server
npm run build # Build for production
npm run preview # Preview production build
npm run lint # Run ESLint
# Backend
fastapi dev backend.py # Start development server
python lambda.py # Test Lambda function locally- TypeScript: Full type safety throughout the application
- ESLint: Code quality and consistency enforcement
- Tailwind CSS: Utility-first CSS framework
- Material-UI: Component library for dialogs and UI elements
- Automatic Deployment: Connected to GitHub repository
- Preview Deployments: Automatic previews for pull requests
- Custom Domain: Available at gambitron.vercel.app
- Serverless Architecture: Scales automatically with demand
- Lambda Layers: Chess library packaged as a layer
- API Gateway: RESTful API endpoint configuration
- AI Response Time: < 2 seconds for most positions
- Search Depth: Configurable depth (typically 3-4 plies)
- Memory Usage: Optimized for Lambda constraints
- Frontend Bundle: < 1MB gzipped
- Mobile Performance: 60fps animations on modern devices
We welcome contributions! Please see our contributing guidelines:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Chess.js - JavaScript chess library
- Python-chess - Python chess library
- React - Frontend framework
- FastAPI - Backend framework
- AWS Lambda - Serverless computing platform
- Vercel - Frontend deployment platform
Ready to challenge Gambitron? Play Now!
