A mobile-web, P2P version of the card game Love Letter.
Royal Letters is a full-stack mobile web game featuring:
- Core Game Engine: A pure TypeScript engine with deterministic RNG for P2P synchronization
- P2P Networking: WebRTC-based peer-to-peer communication using PeerJS
- Mobile-First UI: A Svelte-based responsive interface optimized for mobile devices with full-screen native app experience
- Node.js (v18 or higher recommended)
- npm (comes with Node.js)
npm installnpm testThe test suite covers:
- RNG determinism and deck shuffling
- Game initialization and round management
- All card effects (classic + 2019 ruleset cards)
- Win conditions and state serialization
- P2P message encoding/decoding
- Game state synchronization
- AI player decision-making
npm run devThis starts the Vite development server. The app features a mobile-first UI with:
- Host/Join game lobby
- QR code sharing for easy game joining
- Real-time P2P game state synchronization
- Full game screen with card interactions
npm run buildnpm run checkSee docs/ARCHITECTURE.md for the full directory structure, layer responsibilities, and data flow diagrams.
import { GameEngine } from './src/lib/engine/game';
// Initialize game
const game = new GameEngine();
game.init({
players: [
{ id: 'p1', name: 'Alice' },
{ id: 'p2', name: 'Bob' },
],
});
// Start a round
game.startRound(); // Generates seed, shuffles deck, deals cards
// Player draws
game.drawPhase();
// Player plays a card
const result = game.applyMove({
type: 'PLAY_CARD',
playerId: 'p1',
cardId: 'guard',
targetPlayerId: 'p2',
targetCardGuess: 'baron',
});
// Get current state (for P2P sync)
const state = game.getState();
// Restore state (from P2P sync)
game.setState(state);- Deterministic: Same seed always produces same game sequence
- Serializable: Full state can be converted to/from JSON for P2P sync
- Type-safe: Complete TypeScript type definitions
- Well-tested: Comprehensive test suite covering game logic and networking
- Mobile-First: Optimized for mobile browsers with native app-like experience
- P2P Networking: WebRTC-based communication for low-latency gameplay
- Architecture Overview - System design, directory structure, and data flow
- Coding Guidelines - Conventions for contributing