An interactive web-based chess application featuring an AI opponent powered by a Large Language Model (LLM). Play chess against an intelligent computer opponent with adjustable skill levels, beautiful UI animations, and comprehensive move tracking.
- Interactive Chess Board: Full-featured chess board with drag-and-click piece movement
- AI Opponent: Computer player powered by Ollama's Llama2 LLM
- Adjustable Skill Levels: 10 difficulty levels from beginner to master (1-10)
- Move History: Complete game notation with piece names and move tracking
- Captured Pieces Display: Visual tracker showing all captured pieces for both players
- Last Move Highlighting: Yellow overlay shows the most recent move
- AI Move Flash: 5-second blue animation highlights AI moves for visibility
- Learning Mode: Educational hints system with move explanations and visual guidance
- Hint Levels: Three complexity levels (Basic, Intermediate, Advanced) for tailored learning
- Modern Design: Professional gradient background with chess-themed patterns
- Coordinate Labels: Board coordinates (a-h, 1-8) for easy square identification
- Animated Pieces: Smooth hover effects and scale animations on pieces
- Loading Spinner: Visual feedback during computer thinking time
- Game Over Overlay: Elegant end-game notifications for checkmate/stalemate
- Responsive Layout: Optimized for desktop viewing with mobile considerations
- Containerized Deployment: Easy setup with Podman/Docker
- RESTful API: Clean separation between frontend and backend
- Chess Engine: Powered by python-chess library for legal move validation
- Skill Tuning System: Multi-layered difficulty adjustment using prompt engineering, temperature control, and move filtering
- Container Runtime: Podman or Docker
- Compose Tool: Podman Compose or Docker Compose
- Web Browser: Modern browser with JavaScript enabled (Chrome, Firefox, Safari, Edge)
git clone https://github.com/yourusername/llm_chess_bot.git
cd llm_chess_botUsing Podman (Recommended):
# Build the containers
podman-compose build
# Start the services
podman-compose up -d
# Check container status
podman-compose psUsing Docker:
# Build the containers
docker-compose build
# Start the services
docker-compose up -d
# Check container status
docker-compose psThe llama2 model (approximately 3.8GB) will be automatically downloaded on first startup. This may take several minutes depending on your internet connection. You can monitor the download progress:
# For Podman
podman logs -f llm_chess_bot_ollama_1
# For Docker
docker logs -f llm_chess_bot_ollama_1Wait until you see "Ollama is ready!" in the logs before proceeding.
Open your web browser and navigate to:
http://localhost:5001
You should see the chess board ready to play!
- OpenShift CLI (oc): Install from OpenShift CLI documentation
- Cluster Access: Admin or developer access to an OpenShift cluster
- .env Configuration: Create a
.envfile with cluster credentials
Create a .env file in the project root with your OpenShift cluster configuration:
# OpenShift Cluster Configuration
OCP_CONSOLE_URL=https://console-openshift-console.apps.your-cluster.com/
OCP_API_URL=https://api.your-cluster.com:6443
OCP_USERNAME=your-username
OCP_PASSWORD=your-password
OCP_SKIP_TLS_VERIFY=true
# Optional: Custom GitHub repository URL (if different from git remote)
GITHUB_REPO_URL=https://github.com/yourusername/llm_chess_bot.git
# Optional: Docker Hub credentials (required for Ollama image pulls)
DOCKER_HUB_USERNAME=your-dockerhub-username
DOCKER_HUB_PASSWORD=your-dockerhub-token-or-passwordNote: Replace the values with your actual cluster details. The OCP_SKIP_TLS_VERIFY=true is useful for development clusters with self-signed certificates.
Run the automated deployment script:
# Make the script executable
chmod +x deploy-ocp.sh
# Deploy to OpenShift
./deploy-ocp.shThe script will:
- Login to your OpenShift cluster
- Create a dedicated namespace (
llm-chess-bot) - Pre-pull base images to avoid Docker Hub rate limits
- Build and push container images from GitHub main branch to the internal registry
- Deploy the chess application and Ollama service
- Configure network policies for secure access
- Pull the llama2 model
- Display the application URL when complete
After deployment completes, the script will display the application URL. The app will be accessible via an OpenShift Route (HTTPS endpoint).
Example output:
🎮 Chess App URL: https://chess-app-llm-chess-bot.apps.your-cluster.com
# View application logs
oc logs -f deployment/chess-app -n llm-chess-bot
# View Ollama service logs
oc logs -f deployment/ollama -n llm-chess-bot
# Get shell access to the chess app
oc exec -it deployment/chess-app -n llm-chess-bot -- bash
# Check deployment status
oc get pods -n llm-chess-bot
# Scale the application
oc scale deployment chess-app --replicas=3 -n llm-chess-bot
# Delete the entire deployment
oc delete namespace llm-chess-botThe deployment includes:
- High Availability: 2 replicas of the chess application
- Persistent Storage: 10GB PVC for Ollama model storage
- Network Policies: Secure traffic management between services
- Resource Limits: Memory and CPU constraints for stability
- Health Checks: Liveness and readiness probes
- TLS Termination: Automatic HTTPS via OpenShift Routes
- Monitoring: Compatible with OpenShift monitoring stack
- Start a Game: The board loads with white pieces at the bottom (your side)
- Make a Move: Click a piece to select it, then click the destination square
- AI Response: The computer will think and make its move (watch for the blue flash!)
- Adjust Difficulty: Use the skill level slider (1-10) at any time to change AI strength
- View History: Check the right panel to see all moves with piece names
- Get Hints: Click "Get Hint" for move suggestions and explanations
- Enable Learning Mode: Toggle learning mode for enhanced educational features
- Adjust Hint Level: Choose Basic, Intermediate, or Advanced hint complexity
- Reset Game: Click the "Reset Game" button to start over
| Endpoint | Method | Purpose |
|---|---|---|
/board |
GET | Returns current board state and legal moves |
/move |
POST | Processes a player move, triggers AI response |
/reset |
POST | Resets game to initial state |
/skill-level |
GET | Returns current AI skill level |
/skill-level |
POST | Updates AI skill level (1-10) |
/hint |
POST | Generates a hint for current position |
/learning-mode |
GET | Returns learning mode settings |
/learning-mode |
POST | Updates learning mode settings |
Purpose: Generate a hint for the current position
Request Body:
{
"level": "basic" // "basic", "intermediate", or "advanced"
}Response (200 OK):
{
"move": "e2e4",
"explanation": "Control the center - this is a key strategic principle in chess.",
"category": "center",
"from_square": "e2",
"to_square": "e4"
}Purpose: Update learning mode settings
Request Body:
{
"enabled": true,
"hint_level": "intermediate"
}Response (200 OK):
{
"success": true,
"enabled": true,
"hint_level": "intermediate"
}| Level | Description | Characteristics |
|---|---|---|
| 1-2 | Beginner | Random moves, frequent mistakes, 50% chance of random move |
| 3-4 | Learning | Basic tactics, occasional blunders, 35% chance of random move |
| 5-6 | Intermediate | Considers tactics and piece activity, 20% chance of random move |
| 7-8 | Advanced | Strong tactical and positional play, 10% chance of random move |
| 9 | Expert | Complex evaluations, 5% chance of random move |
| 10 | Master | Objectively best moves, full LLM strength |
The learning mode provides educational assistance to help players improve their chess skills:
| Level | Description | Explanation Style |
|---|---|---|
| Basic | Beginner-friendly | Simple 1-2 sentence explanations focusing on main ideas |
| Intermediate | Club player level | 2-3 sentence explanations with tactical details and principles |
| Advanced | Expert analysis | 3-4 sentence detailed explanations with strategic considerations |
Hints are color-coded by type:
- 🔴 Capture - Material gain opportunities
- 🟠 Check - Attacks on the opponent's king
- 🟣 Checkmate - Game-ending moves
- 🔵 Development - Getting pieces into play
- 🟢 Center Control - Controlling key squares
- 🟡 Castling - King safety and piece development
- 🟪 Promotion - Pawn promotion opportunities
- ⚪ General - Positional improvements
- Green highlighting shows suggested move squares
- Animated arrows indicate move direction
- Light bulb icons mark hint squares
- Color-coded explanations match move categories
If you make changes to the code, rebuild and redeploy:
# Stop containers
podman-compose down
# Rebuild with no cache
podman-compose build --no-cache chess-app
# Start containers
podman-compose up -dIf you prefer to run without containers (note: automated model download only works with containerized deployment):
pip install -r requirements.txtDownload and install Ollama from https://ollama.ai/
ollama pull llama2# Set port (optional, defaults to 5000)
export PORT=5001
# Start Flask server
python app.pyNavigate to http://localhost:5001 in your browser
Edit player.py to use a different Ollama model:
self.model = "llama2" # Change to another model (e.g., "mistral", "codellama")Available models: Ollama Library
Edit app.py to set a different starting skill level:
DEFAULT_SKILL_LEVEL = 5 # Change to 1-10Edit docker-compose.yml to change the exposed port:
ports:
- "5001:5000" # Change 5001 to your preferred portOr set the PORT environment variable:
export PORT=8080
python app.pyThe application includes a comprehensive test suite:
# Ensure app is running on port 5001
python run_tests.py- Basic opening moves validation
- Board state verification
- Pawn promotion mechanics
- Move legality checks
Add test cases to test_chess.py:
def test_my_scenario(self):
"""Test description"""
# Make moves in test mode
response = self.make_move("e2e4", test_mode=True)
# Assert board state
self.assertEqual(response['turn'], 'black')llm_chess_bot/
├── app.py # Flask backend server
├── board.py # Chess board logic wrapper
├── player.py # Player classes (Human, Computer, AI skill tuning)
├── chess.js # Frontend game logic
├── index.html # HTML structure
├── style.css # UI styling and animations
├── test_chess.py # Test suite
├── run_tests.py # Test runner
├── docker-compose.yml # Container orchestration
├── Dockerfile # Chess app container
├── requirements.txt # Python dependencies
├── deploy.sh # Local Podman/Docker deployment script
├── deploy-ocp.sh # OpenShift cluster deployment script
├── .env # Environment variables (OCP cluster config)
├── k8s/ # Kubernetes manifests for OCP deployment
│ ├── namespace.yaml
│ ├── chess-app-deployment.yaml
│ ├── ollama-deployment.yaml
│ └── network-policy.yaml
├── ollama/ # Ollama service configuration
│ └── Dockerfile.ollama
├── README.md # This file
└── ARCHITECTURE.md # Detailed architecture documentation
- Check containers:
podman-compose psordocker-compose ps - View logs:
podman-compose logsordocker-compose logs - Port conflict: Ensure port 5001 is not in use
- Check Ollama container:
podman logs llm_chess_bot_ollama_1 - Verify model:
podman exec -it llm_chess_bot_ollama_1 ollama list - Restart containers:
podman-compose restart
- LLM processing takes 3-10 seconds per move (normal behavior)
- First moves may be slower due to model initialization
- Consider using a faster model like "mistral" for quicker responses
- Check browser console for JavaScript errors (F12)
- Ensure JavaScript is enabled
- Try hard refresh (Ctrl+Shift+R or Cmd+Shift+R)
- Clear browser cache
- Ensure app is running on port 5001
- Check that the board state matches expected values
- Verify test mode is enabled in move requests
- Verify credentials: Check
.envfile contains correct username/password - API URL: Ensure
OCP_API_URLis accessible from your network - TLS Certificate: If using self-signed certs, set
OCP_SKIP_TLS_VERIFY=true
- Check build logs:
oc get builds -n llm-chess-botandoc logs build/<build-name> - Registry access: Ensure you have permissions to push to the internal registry
- Docker Hub auth: Add
DOCKER_HUB_USERNAMEandDOCKER_HUB_PASSWORDto.envfile - Dockerfile: Verify Dockerfile syntax and dependencies
- Rate limits: Use Docker Hub credentials to avoid anonymous pull limits
- Check pod status:
oc get pods -n llm-chess-bot - View pod logs:
oc logs -f <pod-name> -n llm-chess-bot - Describe pod:
oc describe pod <pod-name> -n llm-chess-bot - Resource limits: Check if pods are hitting memory/CPU limits
- Route status:
oc get routes -n llm-chess-bot - Service connectivity:
oc get svc -n llm-chess-bot - Network policies: Verify network policies allow required traffic
- DNS resolution: Check if services can resolve each other
- Storage space: Ensure PVC has enough space (default 10GB)
- Network connectivity: Verify cluster can download models from internet
- Manual download:
oc exec -it deployment/ollama -n llm-chess-bot -- ollama pull llama2
- Resource scaling: Increase CPU/memory limits in deployment manifests
- Replica count: Scale chess app:
oc scale deployment chess-app --replicas=3 -n llm-chess-bot - Node resources: Check cluster node utilization
# Delete entire namespace (cleanup)
oc delete namespace llm-chess-bot
# Redeploy from scratch
./deploy-ocp.sh- Edit style.css, index.html, or chess.js
- Rebuild:
podman-compose build --no-cache chess-app - Restart:
podman-compose up -d - Hard refresh browser (Ctrl+Shift+R)
- Edit app.py, board.py, or player.py
- Rebuild and restart (same as UI changes)
- Check logs:
podman-compose logs chess-app
Create feature branches for changes:
git checkout -b feature/my-feature
# Make changes
git add .
git commit -m "Description of changes"
git push origin feature/my-featureFor detailed information about the application architecture, design decisions, and implementation details, see ARCHITECTURE.md.
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- python-chess: Chess move validation and game logic
- Ollama: Local LLM inference
- Flask: Backend web framework
- Inter Font: Professional typography by Rasmus Andersson
For issues, questions, or suggestions:
- Open an issue on GitHub
- Check existing issues for solutions
- Review the ARCHITECTURE.md for technical details