Back to Portfolio

LazrChess

Real-Time Multiplayer Laser Strategy Game — A full-stack web application inspired by Khet 2.0

v1.4.0 — Feature complete, stability & UX polish phase
Play Live at lazrchess.com
lazrchess.com
LazrChess gameplay screenshot

Overview

LazrChess is a full-stack web application inspired by the classic board game Khet 2.0 (Laser Chess). Players manipulate mirrors and pieces on a grid to direct a laser beam and eliminate the opponent's king.

The application supports single-player mode against an AI opponent, real-time multiplayer via WebSockets, and mobile-friendly session persistence so games are never lost to a dropped connection. All game logic is shared between the frontend and backend through a deterministic rules engine — ensuring 100% consistent behavior across all game modes.

v1.4.0
Current Version
21+
Jest Tests Passing
26
Board Pieces
2
Game Modes

Tech Stack

Built with modern web technologies — no heavy frameworks on the backend, no UI library on the frontend. Every layer was chosen intentionally.

React 18
Frontend UI
Vite
Frontend Bundler
Vanilla CSS
Styling (no UI lib)
SVG Animations
Laser & UI Effects
Node.js
Backend Runtime
Express
HTTP Server
Socket.IO
Real-Time Comms
Jest
Unit Testing
Architecture Highlight

The core game engine (gameEngine.js) is a pure JavaScript module shared between the React frontend and the Node.js backend. This eliminates any possibility of logic drift — both sides run identical move validation, laser simulation, and win detection at all times.

Key Features

Four major feature areas — each with its own engineering challenges and design decisions.

Gameplay

  • Full Khet-style board with 26 pieces
  • Piece movement, rotation, and swapping
  • Step-by-step animated laser system
  • Real-time destruction and reflection logic
  • Win detection via king elimination
  • Threefold repetition draw detection
🌐

Multiplayer

  • Real-time gameplay via Socket.IO WebSockets
  • 4-character session code system
  • Session state sync across both clients
  • Rejoin system with persistent player identity
  • Cross-device reconnect support
  • Mobile auto-resume on tab switch
📱

UX & Interface

  • Responsive board scaling across all devices
  • Animated laser paths (80ms step timing)
  • Piece hover effects and visual indicators
  • Deflector reflective edge indicator
  • Session code copy/paste UX improvements
  • Menu system with rematch and navigation
🧠

Single Player & AI

  • AI opponent with adjustable difficulty
  • Shared deterministic rules engine
  • Identical behavior to multiplayer mode
  • Planned: advanced AI with deeper lookahead
  • Planned: performance scoring (fewest moves)

Technical Highlights

The engineering decisions that made this project non-trivial to build.

🔄

Real-Time Synchronization

Implemented bi-directional communication using Socket.IO with a session-based architecture. Each game session has a unique code, and all state changes are broadcast from the server to ensure both players always see the same board. Solved race conditions between client input and server authority.

🔁

Session Persistence & Recovery

Built a reconnect system using rejoin tokens stored in the browser. Implemented the Browser Visibility API to detect when mobile users switch apps — triggering an automatic reconnect when the tab becomes active again. Players can also rejoin from a completely different device using their session code.

🎯

Deterministic Game Engine

Created a reusable rules engine (gameEngine.js) shared across frontend and backend. This prevents any possibility of logic drift between environments. Also implements position hashing for threefold repetition draw detection — a nuanced rule that requires tracking game history across turns.

Performance & UX Polish

Optimized animation timing so laser traversal (80ms per step) feels snappy without sacrificing readability. Balanced visual clarity with responsiveness across screen sizes. Designed the board to maximize visibility on small mobile screens while remaining fully playable.

🧪

Testing

21+ Jest-based unit tests with coverage across move validation, laser physics, and win condition detection. The shared game engine architecture makes the rules engine straightforward to test in isolation — all game logic can be exercised without spinning up a server or a browser.

Challenges Solved

The hardest problems encountered during development, and how they were resolved.

Multiplayer State Consistency

Ensuring both players see an identical game state required strict server authority — the server is the single source of truth for all game state, and clients only render what the server sends. The shared game engine prevents any discrepancy between client-side prediction and server validation. Careful ordering of update broadcasts and animation sequences was also necessary to prevent visual desync.

Laser Physics & Reflection Logic

Implementing accurate laser reflection across multiple piece types (mirrors, deflectors, etc.) required a precise simulation loop. Edge cases such as laser hitting a corner piece at certain angles, or pieces with multiple reflective faces, each needed explicit handling. The simulation also needed loop protection to prevent infinite laser bounces from hanging the engine.

Mobile Session Persistence

Mobile browsers aggressively disconnect WebSocket connections when users switch to another app. The Browser Visibility API (visibilitychange event) was used to detect tab switches and trigger reconnection logic on resume. Combined with the rejoin token system, a player returning to the game after a minute in another app sees their session exactly as they left it.

UI Clarity for a Complex Game

Khet has significant visual complexity — pieces with directional faces, reflective edges, and laser paths that move step-by-step across the board. Design decisions like the deflector reflective edge indicator, explicit hover states, and animated laser steps (rather than instant resolution) all serve to make outcomes understandable to players at a glance, without cluttering the interface.

Future Roadmap

Planned enhancements for future versions of LazrChess.

Advanced AI (deeper lookahead) Spectator mode Ranked matchmaking Player accounts & stats Sound design & music Enhanced destruction animations Series tracking in multiplayer Performance scoring (fewest moves)

What This Project Demonstrates

A summary of the engineering skills and disciplines exercised in building LazrChess from scratch.

🛠
Full-Stack Design
End-to-end architecture from React UI to Node.js server
🔌
Real-Time Systems
WebSocket communication, session management, and event ordering
Advanced React
Component architecture, local state, and SVG animation integration
🎲
Game Logic Engineering
Rules engine, physics simulation, draw detection, position hashing
🔗
State Synchronization
Distributed client state with server authority and conflict prevention
🔎
Async Debugging
Complex multi-client timing issues, reconnect flows, and animation sync

Try It Yourself

LazrChess is live and playable — challenge an AI or invite a friend for a real-time match.

Play at lazrchess.com Get In Touch