CoolFace
Apppublic

Purva09/algorithm-battlefield

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
App README

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

  1. 1.Clone or extract the project
bash
cd "d:\SEM 5\NEW CA CP"
  1. 1.Create virtual environment
powershell
python -m venv venv
venv\Scripts\activate
  1. 1.Install dependencies
powershell
pip install -r requirements.txt

Running the Application

powershell
python app.py

Then 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

  1. 1.Home Page - Welcome screen with "Start Battle" button
  2. 2.Category Selection - Both players choose different algorithm categories
  3. 3.Algorithm Selection - Players choose specific algorithms
  4. 4.Input Entry - Provide input data (manual or random)
  5. 5.Battle - Algorithms execute and compete
  6. 6.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:

  1. 1.Check the troubleshooting section
  2. 2.Review algorithm implementations
  3. 3.Verify input data format
  4. 4.Check browser console for errors

Enjoy the Algorithm Battlefield Arena! โš”๏ธ๐ŸŽฎ

Made with โค๏ธ for algorithm enthusiasts