Skip to content

Tien-Cheng/leetcode-99

Repository files navigation

Leet 99

Battle Royale for Coders β€” Tetris 99 meets programming in a fast-paced multiplayer coding game.

Status Players Python


πŸš€ Overview

Leet 99 is a real-time multiplayer battle royale game where players race to solve bite-sized tech interview-style problems. Unsolved problems stack up β€” if your stack overflows, you're eliminated. Solve problems to score points and attack your opponents with devious debuffs. Last coder standing wins!

✨ Key Features

  • 2-99 Players β€” Join rooms with friends or compete against bots
  • Real-time Combat β€” Attacks, debuffs, and garbage problems keep everyone on edge
  • Stack Overflow Mechanic β€” Problems pile up; overflow = elimination
  • Tetris 99-style Targeting β€” Choose your targeting mode: Random, Attackers, Top Score, or Near Death
  • Function-only Python Problems β€” Quick to read, fast to solve (1-5 minutes each)

🎯 Gameplay

The Loop

Read problem β†’ Write code β†’ Run (test) β†’ Submit β†’ Attack! β†’ Next problem
  1. Start with 1 active problem + 2 queued problems in your stack
  2. Solve problems to earn points and automatically attack your target
  3. New problems arrive periodically β€” they push onto your stack
  4. Stack overflow? You're eliminated!
  5. Last player standing wins (or highest score when time expires)

Scoring

Difficulty Points
Easy +5
Medium +10
Hard +20
Garbage 0

Attacks & Debuffs

When you solve a problem, you attack your current target:

Attack Effect Trigger
πŸ—‘οΈ Garbage Drop Add 1 garbage problem to target's stack Solving Easy
πŸ’‘ Flashbang Force light mode for 25s Solving Medium
⌨️ Vim Lock Force Vim mode for 12s Solving Medium
🚫 DDOS Disable "Run" for 12s Solving Hard
πŸ’Ύ Memory Leak Double incoming problem rate for 30s 3-solve streak

Shop Items

Spend your hard-earned points to gain an edge:

Item Cost Effect
Clear Debuff 10 Remove active debuff
Memory Defrag 10 Remove all garbage from stack
Skip Problem 5 Discard current problem (can go negative)
Rate Limiter 10 Halve incoming problem rate for 30s
Hint 5 Reveal a hint for current problem

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Browser   │────▢│   Next.js   │────▢│  Supabase   β”‚
β”‚   (Client)  β”‚     β”‚   (Vercel)  β”‚     β”‚  (Postgres) β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β”‚ WebSocket
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  PartyKit   │────▢│  Judge0 CE  β”‚
β”‚   (Room)    β”‚     β”‚ (RapidAPI)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Tech Stack

Layer Technology
Frontend Next.js, Tailwind CSS, daisyUI, Lucide Icons
Editor Monaco + monaco-vim
Realtime PartyKit (WebSocket rooms)
Persistence Supabase (PostgreSQL)
Code Execution Judge0 CE via RapidAPI
Deploy Vercel + PartyKit Cloud

Project Structure

leet-99/
β”œβ”€β”€ apps/
β”‚   └── web/              # Next.js frontend application
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ contracts/        # Shared TypeScript types & Zod schemas
β”‚   β”œβ”€β”€ realtime/         # PartyKit room logic (game engine)
β”‚   β”œβ”€β”€ supabase/         # Database queries & types
β”‚   └── ui/               # Shared React components
β”œβ”€β”€ docs/                 # Design documents & specs
└── supabase/             # Database migrations

🎨 Design Philosophy

"Riced Workstation" Aesthetic β€” Inspired by r/unixporn tiling WM setups:

  • Dark theme (harsh white "Flashbang" for the debuff 😈)
  • Sharp edges, minimal border-radius
  • Dense but readable information layout
  • IBM Plex fonts (Sans + Mono)
  • Subtle noise grain texture

What We Avoid

  • ❌ Purple gradients on white (AI-generated startup slop)
  • ❌ Rounded-everything soft UI
  • ❌ Default SaaS fonts
  • ❌ Empty decorative space

πŸ•ΉοΈ Controls

Keyboard Shortcuts

Key Action
Alt+R Run code (public tests)
Alt+S Submit code
Alt+B Open/close shop
Alt+T Targeting mode menu
Alt+V Toggle Vim mode
1-5 Quick-buy shop items
Esc Close menus

πŸ”Œ API Overview

HTTP Endpoints

Method Endpoint Description
POST /api/rooms Create a new room
POST /api/rooms/:roomId/join Join an existing room
GET /api/rooms/:roomId Get room summary
GET /api/matches/:matchId Get match results
GET /api/leaderboard Get global leaderboard

WebSocket Events

Client β†’ Server:

  • JOIN_ROOM β€” Authenticate and join
  • SET_TARGET_MODE β€” Change targeting mode
  • RUN_CODE β€” Run public tests
  • SUBMIT_CODE β€” Submit for scoring
  • SPEND_POINTS β€” Purchase shop item
  • SPECTATE_PLAYER β€” Watch another player

Server β†’ Client:

  • ROOM_SNAPSHOT β€” Full state sync
  • PLAYER_UPDATE β€” Player state change
  • JUDGE_RESULT β€” Code execution result
  • ATTACK_RECEIVED β€” Incoming attack
  • MATCH_END β€” Game over + standings

🚦 Getting Started

Prerequisites

  • Node.js 20+
  • pnpm 8+
  • RapidAPI account (for Judge0)
  • Supabase project
  • PartyKit account

Environment Variables

Copy .env.example to .env.local and configure:

# PartyKit
NEXT_PUBLIC_PARTYKIT_HOST=your-project.partykit.dev

# Supabase
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-key

# Judge0 (RapidAPI)
RAPIDAPI_KEY=your-rapidapi-key
RAPIDAPI_HOST=judge0-ce.p.rapidapi.com

Installation

# Install dependencies
pnpm install

# Start development servers
pnpm dev

Deploy

# Deploy PartyKit
npx partykit deploy

# Deploy to Vercel
vercel deploy

πŸ€– Bots

Sim bots keep lobbies lively for demos:

  • Solve Time: Easy 30-60s, Medium 45-90s, Hard 60-120s
  • Failure Rate: ~20% of submissions fail
  • Targeting: Always random
  • Shop: Never buys items

Bots participate fully in scoring, stacks, and elimination.


βš™οΈ Room Settings

Setting Default Options
Match Duration 10 min 6-10 minutes
Player Cap 8 2-99
Stack Limit 10 β€”
Difficulty Moderate Beginner / Moderate / Competitive
Attack Intensity Low Low / High (1.3x debuff duration)

πŸ“š Documentation


πŸ† MVP Definition of Done

  • βœ… Players can create/join rooms via URL
  • βœ… 2+ players see each other in minimap with synced game state
  • βœ… Problems push onto stack; RUN_CODE tests public, SUBMIT_CODE tests all
  • βœ… Correct submissions award points, advance problems, send attacks
  • βœ… Stack overflow eliminates players
  • βœ… Winner determined: last alive or highest score
  • βœ… Bots fill lobbies for demos
  • βœ… Deployed publicly

May the best coder survive! πŸ§‘β€πŸ’»βš”οΈ

About

Leetcode Battle Royale

Resources

License

Stars

Watchers

Forks

Contributors