Skip to content

kkalmanowicz/blockai

Repository files navigation

HexTactics

A strategic multiplayer territory control game played on a hexagonal grid, featuring AI opponents and real-time multiplayer gameplay.

Features

  • Online Multiplayer: Play with friends in real-time using room codes
  • AI Opponents: Challenge AI with 3 difficulty levels (Easy/Medium/Hard)
  • Local Multiplayer: Pass-and-play on the same device
  • Hexagonal Grid: Unique 6-sided tile system creates fresh strategic possibilities
  • 20 Unique Pieces: Polyhex pieces from 1-5 hexagons in various configurations
  • Strategic Depth: Territory control through diagonal-only connections

Game Rules

HexTactics is an abstract strategy game for 2-4 players. Each player starts with 20 polyhex pieces in their color.

Objective

Claim as much territory as possible by placing your pieces on the hexagonal board. The player with the lowest score (fewest hexagons remaining) wins!

Rules

  1. First Move: Your first piece must cover your starting hex (marked on the board)
  2. Diagonal Connection: Each subsequent piece must touch at least one of your existing pieces, but only at corners (diagonally)
  3. No Edge Sharing: Your pieces cannot share edges with each other (only diagonal touches allowed)
  4. Blocking: You can block opponents by occupying hexes they need
  5. Scoring: You start with points equal to total hexagons in all pieces. Each hex you place reduces your score by 1. Lower score is better! Bonus: -20 points if you place all pieces, -10 more if your last piece is the single hex!

Strategy

  • Place Large Pieces First: Secure high-value pieces early before space runs out
  • Maximize Diagonal Connections: Create as many diagonal connection points as possible
  • Control Territory: Spread across the board to maintain placement options
  • Block Opponents: Cut off their expansion routes strategically
  • Stay Centered: Avoid board edges to preserve future moves

Installation

# Install dependencies
npm install

# Run the game (starts both client and server)
npm run dev

The game will be available at http://localhost:5173

How to Play

Create a Game

  1. Choose your game mode:

    • Online Game: Get a room code to share with friends
    • vs AI: Play against computer opponents
    • Local Multiplayer: Pass-and-play on one device
  2. Select number of players (2-4)

  3. For AI mode, choose difficulty level

Playing

  1. Select a piece from your collection on the right
  2. Use Rotate 60° and Flip buttons to orient the piece
  3. Move your mouse over the board to preview placement
  4. Click to place the piece
  5. Pieces must follow the diagonal-connection rule

Online Multiplayer

  1. Player 1 creates a room and gets a 6-character code
  2. Other players join using that code
  3. Once at least 2 players are ready, start the game
  4. Take turns placing pieces

Technical Details

Architecture

  • Frontend: React with Canvas-based hexagonal rendering
  • Backend: Node.js + Express + Socket.IO
  • Game Logic: Axial coordinate system for hexagonal grid
  • AI: Greedy algorithm with heuristic evaluation

Recent Fixes

  • Rotation Fix: Corrected hexagonal piece rotation to prevent expansion during gameplay (see ROTATION_FIX.md)

Hexagonal Grid System

The game uses axial coordinates (q, r) for the hexagonal grid:

  • Each hex has 6 neighbors (edges) and 6 diagonal neighbors (corners)
  • Pieces must connect at diagonal neighbors only
  • Board is a circular hex grid with radius 10

AI Strategy

The AI evaluates moves based on:

  • Piece size (larger pieces prioritized)
  • Distance from board center
  • Random variation for unpredictability

Project Structure

blockai/
├── src/                    # React frontend
│   ├── components/         # UI components
│   │   ├── HexBoard.jsx   # Hex grid canvas renderer
│   │   └── Menu.jsx       # Main menu
│   ├── App.jsx            # Main app component
│   └── main.jsx           # Entry point
├── server/                 # Node.js backend
│   └── index.js           # WebSocket server
├── shared/                 # Shared game logic
│   ├── hexPieces.js       # Polyhex piece definitions
│   ├── hexGameLogic.js    # Game rules engine
│   ├── hexGrid.js         # Hexagonal grid utilities
│   └── hexAI.js           # AI opponent
└── package.json           # Dependencies

Game Theory

HexTactics is a deterministic, perfect-information abstract strategy game based on:

  • Polyhexes: Mathematical shapes from combinatorial game theory (hexagonal polyominoes)
  • Territorial Control: Area control mechanics on hex grid
  • Greedy Optimization: AI prioritizes immediate high-value moves
  • Spatial Reasoning: Geometric puzzle-solving in hexagonal space
  • Diagonal Advantage: Maximizing future move options through diagonal connections

Why Hexagonal?

Hexagons offer unique strategic properties:

  • 6 directions instead of 4 (square grid)
  • Equal distance to all neighbors (no diagonal vs orthogonal distinction)
  • Natural tessellation creates organic flow
  • Different spatial relationships than square grids

Credits

Original concept inspired by classic territory control games. This is an original implementation using hexagonal grid mechanics.

License

MIT License - Feel free to use and modify!

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages