Skip to main content

Technology Stack

BeeHex is built as a modern Progressive Web App using the following core technologies:

Frontend Framework

Next.js 14.2 with React 18 for server-side rendering and routing

Language

TypeScript 5 for type-safe development across the entire codebase

Styling

Styled Components 6.1 for component-scoped CSS-in-JS styling

Real-time Communication

Socket.io Client 4.7 for WebSocket-based multiplayer gameplay

System Architecture

BeeHex follows a client-heavy architecture where complex game logic and AI computations run directly in the browser.

Core Components

The central game state manager located in src/app/hex/[gameId]/GameInstance.ts.Key Responsibilities:
  • Maintains the game grid as a 2D array: Array<Array<number>>
  • Tracks player IDs (first_player_id, second_player_id)
  • Manages turn state and validates moves
  • Provides methods for state updates and player queries

Data Flow

Online Multiplayer Flow

1

Player initiates game search

Client sends GAME_SEARCH packet with GameParameters (board size, ranked status)
2

Server matches players

Server responds with GAME_FOUND packet containing game_id
3

Join game room

Client sends JOIN_GAME packet and receives full Game object with initial state
4

Gameplay loop

Players send PLAY_MOVE packets, server broadcasts MOVE_PLAYED to both clients

Offline Mode Flow

  1. Local Game Creation: Creates GameInstance with LocalGameParameters
  2. AI Move Request: Explorer spawns Web Workers to evaluate positions
  3. Worker Exploration: Each worker explores 2 levels deep using basicHeuristic
  4. Move Recommendation: Best moves returned with optimal continuation paths

Performance Optimizations

BeeHex implements several performance optimizations to handle complex game tree search:

Array Caching

The ArrayCache class (src/app/hex/[gameId]/ArrayCache.ts:1) reduces memory allocation during game tree exploration:

Grid Hashing

Board positions are hashed to base-36 strings for efficient deduplication:

Memory Management

Explored game states clear their grid arrays once children are created to conserve memory:

Type System

BeeHex uses comprehensive TypeScript interfaces defined in src/app/definitions.ts:
  • Game Types: Game, GameParameters, GameStatus
  • Network Packets: ClientBoundPacket, ServerBoundPacket enums and interfaces
  • AI Types: RawScoredGameInstance, ExploreResult, Coordinate
  • Identifiers: UserId, GameId, RoomId, GridHash
All packet types use discriminated unions with type field for type-safe message handling.

Directory Structure

Next Steps

Game Engine

Deep dive into AI algorithms and game state management

WebSocket Protocol

Complete packet specification and communication flow