Morris

Seven mill-formation variants on concentric-ring graph boards, with placement and movement phases, 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=morris&variant=nine-mens-morris"
  style="width:100%;max-width:560px;aspect-ratio:1/1;border:none"
  title="Play Morris"
></iframe>

URL parameters

ParamValuesDefault
embed1Required for embed mode
familymorrischess
variantAny variant key belownine-mens-morris
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 morris:undo both work.

iframe.contentWindow.postMessage({ type: 'game:setVariant', variant: 'lasker-morris' }, '*')
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: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 seven variants from the moddable-rules Morris hub are playable. Each is fully declared in frontmatter; the plugin holds no variant-specific code.

KeyBoardDistinguishing rule
nine-mens-morris3 concentric squares9 pieces each; place then move; mill removes one opponent piece
six-mens-morris2 concentric squares6 pieces each; no placement phase (start on board)
three-mens-morris1 square + centre3 pieces each; tic-tac-toe on a graph; first mill wins
twelve-mens-morris4 concentric squares12 pieces each; diagonals on the outer ring
lasker-morris3 concentric squares10 pieces each; may hop over an adjacent man
morabaraba3 concentric squaresSouth African variant; diagonal connections
shax3 concentric squares12 pieces each; Somali variant

Mechanics

The plugin handles placement, movement, mill detection, and removal. All configuration arrives via frontmatter:

Config keyEffect
piecesPerPlayerHow many men each player places (3, 6, 9, 10, or 12)
allowHopWhether a man may hop over an adjacent man (Lasker)
diagonalsWhether diagonal edges exist on the graph
flyingWhenThreeA player reduced to 3 men may move to any empty node

The game has two phases: placement (alternating until all men are down) and movement (slide along edges). Forming a mill (three in a row along an edge) lets the player remove one opponent piece. A player with fewer than 3 pieces or no legal moves loses.

SDK

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

listVariants('morris')                        // [{ key, label, group, board }]
const game = createGame('morris', 'nine-mens-morris')
game.applyMove({ action: 'place', to: 'n1' })

const ai = createAI('morris', 'nine-mens-morris', { difficulty: 'hard' })
ai.pickMove(game.getState().slice, 0)         // minimax with mill evaluation