Skip to content

Add warfare simulation engine with combat modeling and missile tracking#1727

Open
rsunil92 wants to merge 1 commit intokoala73:mainfrom
rsunil92:claude/add-war-specific-mechanics-A28vn
Open

Add warfare simulation engine with combat modeling and missile tracking#1727
rsunil92 wants to merge 1 commit intokoala73:mainfrom
rsunil92:claude/add-war-specific-mechanics-A28vn

Conversation

@rsunil92
Copy link
Copy Markdown

Summary

Adds a comprehensive warfare simulation system to WorldMonitor, enabling turn-based conflict modeling with Lanchester's Square Law combat resolution, missile trajectory tracking, supply line logistics, territorial control dynamics, and casualty projections. Includes a full gRPC service definition, in-memory simulation engine, UI panels for scenario control and analysis, and client-side service layer.

Type of change

  • New feature

Affected areas

  • API endpoints (/api/*)
  • New gRPC service (Warfare Service)

What's included

Core simulation engine (server/worldmonitor/warfare/v1/simulation-engine.ts)

  • Combat resolution: Implements Lanchester's Square Law for attrition modeling with terrain modifiers, morale, readiness, and supply multipliers
  • Missile tracking: Models ballistic/cruise missile trajectories, interception probability, and air defense engagement
  • Logistics: Supply line management with consumption rates, vulnerability modeling, and resource depletion
  • Territorial control: Dynamic territory ownership tracking with contested zones and strategic value assessment
  • Casualty projection: Forward-looking estimates based on combat intensity and force ratios
  • Capability assessment: Military strength evaluation with trend analysis

Service layer

  • gRPC service definition (proto/worldmonitor/warfare/v1/): 16 RPCs covering simulation lifecycle, unit operations, missile tracking, logistics, territorial control, and analysis
  • Service handler (server/worldmonitor/warfare/v1/handler.ts): Implements all RPC endpoints
  • Generated types (src/generated/server/worldmonitor/warfare/v1/service_server.ts): TypeScript interfaces for all messages and enums
  • Client service (src/services/warfare-simulation.ts): Typed RPC wrappers with local state caching

UI components

  • WarfareSimulationPanel: Main control panel for scenario creation, turn advancement, and live combat log
  • WarfareCorrelationPanel: Cross-stream correlation display
  • MissileTrackerPanel: Missile launch/interception tracking and system status
  • CasualtyEstimatorPanel: Casualty projections with confidence intervals

Proto definitions

  • military_unit.proto: Unit types, states, and composition
  • combat_system.proto: Combat engagement, outcomes, and terrain modifiers
  • missile_tracking.proto: Missile systems, launches, trajectories, and interception
  • logistics.proto: Supply lines, resource pools, and supply types
  • territorial_control.proto: Territory ownership, frontlines, and control trends
  • conflict_analysis.proto: Capability assessments and casualty projections
  • game_state.proto: Simulation lifecycle and turn management

Key features

  • In-memory simulation state: Each simulation is independent and self-contained
  • Theater-based seeding: Default units, missile systems, supply lines, and territories based on conflict theater (European, Middle East, Indo-Pacific)
  • Realistic combat modeling: Incorporates firepower, armor, readiness, morale, supply levels, and terrain effects
  • Missile interception modeling: Probability-based air defense with system-specific effectiveness
  • Logistics constraints: Resource consumption, supply line vulnerability, and critical supply thresholds
  • Outcome forecasting: Scenario analysis with casualty projections and capability trends

Checklist

  • TypeScript compiles without errors
  • No API keys or secrets committed
  • Follows existing code patterns and architecture

Testing

The simulation engine is self-contained with deterministic initialization. Manual testing via the UI panels will verify:

  • Scenario creation with preset and custom configurations
  • Turn advancement with combat resolution
  • Casualty tracking and projections
  • Missile system deployment and interception
  • Supply line status and resource depletion
  • Territorial control changes

https://claude.ai/code/session_0157x5y4r6AxJXXGk9pmcheX

Introduces a complete turn-based warfare simulation system with:

- **8 proto definitions**: military units, combat system (Lanchester equations),
  missile tracking (launch/trajectory/interception), logistics & supply lines,
  territorial control, conflict analysis & outcome forecasting, game state
- **16 RPC endpoints** via WarfareService: simulation lifecycle, unit operations,
  combat resolution, missile launch/intercept, supply status, territorial control,
  capability assessment, casualty projection, outcome scenario analysis
- **Core simulation engine**: Haversine-based movement, proximity combat detection,
  supply consumption, territory dynamics, morale/readiness recovery, auto-conclusion
- **4 frontend panels**: WarfareSimulationPanel (main game UI with 6 tabs),
  MissileTrackerPanel, CasualtyEstimatorPanel, WarfareCorrelationPanel
- **Client service**: typed RPC wrappers for all warfare endpoints

Covers: unit movement, combat calculations, resource management, battlefield
positions, unit compositions, supply lines, missile launch/interception tracking,
casualty estimations, military capability assessments, territorial control maps,
and conflict outcome forecasting with probability distributions.

https://claude.ai/code/session_0157x5y4r6AxJXXGk9pmcheX
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 16, 2026

@claude is attempting to deploy a commit to the Elie Team on Vercel.

A member of the Team first needs to authorize it.

@koala73
Copy link
Copy Markdown
Owner

koala73 commented Mar 16, 2026

This is very cool, I can rework, but I don't have bandwidth tonight, will schedule for next 2-3 days

🔴 P1 — BLOCKS MERGE

  1. In-memory simulation state is fundamentally broken on Vercel Edge

api/warfare/v1/[rpc].ts:1 has runtime: 'edge'. But simulation-engine.ts:128 stores all simulation state in a module-level const simulations = new Map<string, SimulationState>().

Vercel Edge functions are stateless and run on globally distributed workers. createSimulation writes to one worker's in-process Map, then getGameState, advanceTurn, and all 14
other state-dependent RPCs call getSimulation(simulationId) — which will return undefined on any other edge node (i.e., almost every subsequent request). The feature simply does not work in production. Every stateful RPC silently returns empty results.

@koala73 koala73 added the Not Ready to Merge PR has conflicts, failing checks, or needs work label Mar 19, 2026
@koala73 koala73 added the High Value Meaningful contribution to the project label Mar 26, 2026
@SebastienMelki
Copy link
Copy Markdown
Collaborator

@rsunil92 — the P1 issue @koala73 flagged still needs resolution: the simulation uses a module-level Map for state, which is incompatible with stateless Vercel Edge functions.

The fix: move simulation state to Upstash Redis (already used in the project). Each RPC would GET/SET simulation state by simulationId:

// Instead of: simulations.set(id, state)  
await redis.set(`sim:${id}`, JSON.stringify(state), { ex: 3600 });

Before investing in the fix though — @koala73, is a turn-based warfare simulation engine in scope for WorldMonitor's roadmap? Worth confirming the direction before a full rewrite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

High Value Meaningful contribution to the project Not Ready to Merge PR has conflicts, failing checks, or needs work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants