Skip to content

ayushfand/BattleForces

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

⚔️ BattleForces

A competitive coding battle platform where two users race to solve Codeforces problems in a private timed room.


🗂️ Project Structure

BattleForces/
├── backend/            # Node.js + Express + MongoDB
│   ├── server.js
│   ├── .env
│   └── src/
│       ├── models/     Battle.js
│       ├── routes/     battleRoutes.js, profileRoutes.js
│       ├── controllers/ battleController.js, profileController.js
│       └── services/   codeforcesService.js
└── frontend/           # React + Vite + Tailwind CSS v4
    └── src/
        ├── pages/      Home.jsx, BattleRoom.jsx, Profile.jsx
        ├── components/ Navbar.jsx, Timer.jsx
        ├── api.js
        └── index.css

🚀 Getting Started

Prerequisites

  • Node.js 18+
  • MongoDB running locally (mongodb://localhost:27017)

1. Start Backend

cd BattleForces/backend
npm install
node server.js

Backend runs at http://localhost:5000

2. Start Frontend

cd BattleForces/frontend
npm install
npm run dev

Frontend runs at http://localhost:5173


🔌 API Endpoints

Method Route Description
POST /battle/create Create a new battle room
POST /battle/join Join a room by roomId
POST /battle/start Host starts the battle
POST /battle/validate Validate a CF submission
GET /battle/:roomId Get battle room state
GET /profile/compare?handle1=&handle2= Compare two CF profiles

Example: Create a Room

POST /battle/create
{
  "handle": "tourist",
  "minRating": 1000,
  "maxRating": 1600,
  "problemCount": 3,
  "duration": 60
}

🎮 How to Play

  1. Host goes to the homepage, fills out settings, and clicks Create Battle Room
  2. Host shares the join link with the opponent
  3. Opponent joins using the link or Room ID and enters their CF handle
  4. Host clicks Start Battle → problems are fetched from Codeforces API
  5. Both players solve problems on Codeforces.com
  6. Click Validate after submitting a solution — backend checks your CF submissions
  7. Timer counts down. Most problems solved wins (tiebreak: total time)

📋 .env Configuration

PORT=5000
MONGO_URI=mongodb://localhost:27017/battleforces

⚠️ Notes

  • Polling interval: 5 seconds (no WebSockets needed)
  • Validation checks submissions from Codeforces API: verdict=OK + problem match + submission after battle start
  • Profile comparison uses live Codeforces API data with rating history chart

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors