Purva09/algorithm-battlefield
0
Algorithm Battlefield Arena
A gamified Flask web application where two players compete by running algorithms from different categories and comparing their performance (execution time and memory usage).
๐ฎ Features
- 34+ Algorithms across 8 categories (Sorting, Searching, Graph, String Matching, etc.)
- Real-time Performance Metrics - Measures execution time and memory usage
- Gamified Battle Interface - Engaging UI with animations and effects
- Responsive Design - Works perfectly on mobile, tablet, and desktop
- Session Management - Track game state without a database
- Visual Comparison - Side-by-side results with charts and statistics
๐ Quick Start
Installation
- Clone or extract the project
cd "d:\SEM 5\NEW CA CP"- Create virtual environment
python -m venv venv
venv\Scripts\activate- Install dependencies
pip install -r requirements.txtRunning the Application
python app.pyThen open your browser and go to: http://localhost:5000
๐ Project Structure
algorithm-battlefield-arena/
โโโ app.py # Main Flask application
โโโ config.py # Configuration settings
โโโ requirements.txt # Python dependencies
โ
โโโ algorithms/ # Algorithm implementations
โ โโโ sorting.py # 6 sorting algorithms
โ โโโ searching.py # 3 searching algorithms
โ โโโ shortest_path.py # 3 shortest path algorithms
โ โโโ mcst.py # 2 MST algorithms
โ โโโ graph.py # 2 graph traversal algorithms
โ โโโ string_matching.py # 4 string matching algorithms
โ โโโ subset.py # 5 subset generation algorithms
โ โโโ knapsack.py # 3 knapsack algorithms
โ
โโโ utils/ # Utility functions
โ โโโ performance.py # Performance measurement
โ โโโ input_generator.py # Random input generation
โ โโโ validators.py # Input validation
โ
โโโ templates/ # HTML templates
โ โโโ base.html # Base template
โ โโโ index.html # Home page
โ โโโ select_category.html # Category selection
โ โโโ select_algorithm.html # Algorithm selection
โ โโโ input.html # Input entry
โ โโโ battle.html # Battle execution
โ โโโ result.html # Results display
โ
โโโ static/ # Static files
โโโ css/
โ โโโ style.css # Main stylesheet
โ โโโ animations.css # Animations
โ โโโ responsive.css # Responsive design
โโโ js/
โโโ main.js # Main JavaScript
โโโ battle.js # Battle logic
โโโ animations.js # Animation effects
โโโ api.js # API utilities๐ฏ Gameplay Flow
- Home Page - Welcome screen with "Start Battle" button
- Category Selection - Both players choose different algorithm categories
- Algorithm Selection - Players choose specific algorithms
- Input Entry - Provide input data (manual or random)
- Battle - Algorithms execute and compete
- Results - View detailed performance comparison
๐ง Supported Algorithms
Sorting (6)
- Bubble Sort
- Insertion Sort
- Merge Sort
- Quick Sort
- Selection Sort
- Heap Sort
Searching (3)
- Linear Search
- Binary Search
- Fibonacci Search
Shortest Path (3)
- Dijkstra's Algorithm
- Bellman-Ford Algorithm
- Floyd-Warshall Algorithm
MST (2)
- Prim's Algorithm
- Kruskal's Algorithm
Graph Traversal (2)
- BFS (Breadth-First Search)
- DFS (Depth-First Search)
String Matching (4)
- Naive Search
- KMP Search
- Rabin-Karp
- Boyer-Moore
Subset Generation (5)
- Bitmasking
- Backtracking
- Recursive
- Iterative
- Python Built-in
0/1 Knapsack (3)
- Dynamic Programming
- Backtracking
- Branch & Bound
๐ก How It Works
Performance Measurement
The application uses:
- `timeit.default_timer()` - Precise execution time measurement
- `tracemalloc` - Memory usage profiling
- Session management - Stores game state temporarily
Scoring System
Winner is determined by lowest combined score:
Score = 100 - (execution_time * 100 + memory_usage * 0.1)Features
- Real-time Execution - Algorithms run sequentially with timing
- Error Handling - Graceful error messages for invalid inputs
- Input Validation - Ensures data is compatible with algorithms
- Responsive UI - Adapts to all screen sizes
- Animations - Smooth transitions and visual feedback
๐จ UI/UX Highlights
- Dark Gaming Theme - Navy blue + Neon red/green
- Responsive Design - Mobile-first approach
- Smooth Animations - Fade, slide, and glow effects
- Modern Typography - Orbitron, Poppins, Montserrat fonts
- Interactive Elements - Hover effects, ripple animations
- Progress Visualization - Animated bars during execution
โ๏ธ Configuration
Edit config.py to customize:
- Session timeout
- Default input sizes
- Algorithm-specific settings
- Logging levels
๐ง Requirements
- Python 3.8+
- Flask 2.3.3
- Flask-Session 0.5.0
- Werkzeug 2.3.7
- python-dotenv 1.0.0
๐ Performance Considerations
- Input size limits prevent long-running algorithms
- Timeout protection for execution
- Memory-efficient implementations
- Optimized for competitive testing
๐ Troubleshooting
Application won't start
- Ensure Python 3.8+ is installed
- Verify all dependencies:
pip install -r requirements.txt - Check port 5000 is available
Algorithms running slowly
- Reduce input size in settings
- Check system resources
- Monitor memory usage
UI looks broken
- Clear browser cache
- Update to latest browser version
- Ensure JavaScript is enabled
๐ Example Scenarios
Scenario 1: Sorting Competition
- Player 1: Bubble Sort with 100 numbers
- Player 2: Merge Sort with 100 numbers
- Result: Merge Sort wins with faster execution
Scenario 2: String Matching
- Player 1: Naive Search in 1000 character text
- Player 2: Boyer-Moore in same text
- Result: Boyer-Moore wins with optimal algorithm
Scenario 3: Graph Traversal
- Player 1: BFS on graph with 50 nodes
- Player 2: DFS on same graph
- Result: Compare traversal performance
๐ Educational Value
- Learn algorithm performance characteristics
- Compare different implementations
- Understand time vs. space tradeoffs
- Practice competitive programming
๐ Security Notes
- Session data stored locally (no persistence)
- Input validation prevents injection attacks
- No sensitive data stored
- Safe for educational use
๐ License
Free for educational and personal use.
๐ค Contributing
Feel free to add:
- More algorithms
- Additional categories
- Enhanced UI features
- Performance optimizations
๐ Support
For issues or questions:
- Check the troubleshooting section
- Review algorithm implementations
- Verify input data format
- Check browser console for errors
Enjoy the Algorithm Battlefield Arena! โ๏ธ๐ฎ
Made with โค๏ธ for algorithm enthusiasts
