Hex

Eight connection game variants across rhombus and triangular boards, with bridge-aware MCTS search, pie rule, and the same embed and SDK every family uses.

Embed via iframe

Every game family shares one embed surface. Select the family and variant through the URL.

<iframe
  src="https://engine.moddable.games/play/?embed=1&family=hex&variant=standard"
  style="width:100%;max-width:560px;aspect-ratio:1/1;border:none"
  title="Play Hex"
></iframe>

URL parameters

ParamValuesDefault
embed1Required for embed mode
familyhexchess
variantAny variant key belowstandard
opponentai | humanai
difficultybeginner | easy | medium | hard | expertmedium
themeBoard theme idclassic

postMessage control

Commands accept either the generic game: prefix or the family prefix, so game:undo and hex:undo both work.

iframe.contentWindow.postMessage({ type: 'game:setVariant', variant: 'y-game' }, '*')
iframe.contentWindow.postMessage({ type: 'game:setDifficulty', difficulty: 'hard' }, '*')
iframe.contentWindow.postMessage({ type: 'game:newGame' }, '*')
iframe.contentWindow.postMessage({ type: 'game:undo' }, '*')
iframe.contentWindow.postMessage({ type: 'game:pass' }, '*')
iframe.contentWindow.postMessage({ type: 'game:resign' }, '*')
iframe.contentWindow.postMessage({ type: 'game:requestState' }, '*')

Events from embed

window.addEventListener('message', (e) => {
  switch (e.data.type) {
    case 'game:ready':  break  // { family, variant, state }
    case 'game:move':   break  // { move, state }
    case 'game:status': break  // { text, gameOver, family, variant }
    case 'game:state':  break  // { state } in reply to requestState
  }
})

Variants

All eight variants from the moddable-rules Hex hub are playable. Five are standard Hex on different board sizes; three are Y, played on a triangular board where both players must connect all three sides.

KeyBoardDistinguishing rule
standard11×11 rhombusTournament size; connect opposite edges; pie rule
9x99×9 rhombusSmaller board for faster games
13x1313×13 rhombusLarger board; deeper strategy
14x1414×14 rhombusInternational competition size
19x1919×19 rhombusLargest standard size
y-game12-side triangleConnect all 3 sides; both players share the same objective
y-large16-side triangleLarger Y board
y-small8-side triangleCompact Y board

Mechanics

The plugin is pure connection logic. All configuration arrives via frontmatter:

Config keyEffect
connect"edges" (Hex: opposite pair) | "all-sides" (Y: all three)
pieRuleAfter the first stone, second player may swap instead of replying
shape"rhombus" | "triangle"
sideLengthBoard size (cells per edge)

No draws are possible on a hex grid. The search is MCTS with a bridge-aware rollout policy: if an opponent probes any bridge carrier, the defender always replies to maintain the connection.

SDK

import { createGame, createAI, listVariants } from 'moddable-engine/play'

listVariants('hex')                           // [{ key, label, group, board }]
const game = createGame('hex', 'standard')
game.applyMove({ action: 'place', to: '5,5' })

const ai = createAI('hex', 'standard', { difficulty: 'hard' })
ai.pickMove(game.getState().slice, 0)         // MCTS with bridge-aware rollouts