log

Implementation Log: Hnefatafl

A record of implementing the Viking board game 'Hnefatafl' on the Parlourite engine. Covers the game overview, historical context, and implementation decisions.

I implemented Hnefatafl on the Parlourite engine. This is a record of the work, created as the game is added to the public lineup.

About Hnefatafl

Hnefatafl is a board game played in Viking-age Scandinavia. The name means “king’s table,” and it is considered the representative game of the tafl family.

On an 11×11 board, a throne sits at the center where the defender’s king resides. Twelve guard pieces surround the king, while 24 attacker pieces encircle from all sides. All pieces move like rooks in straight lines, and flanking an enemy with two pieces captures it.

The defender wins by escaping the king to any corner. The attacker wins by surrounding the king on all four sides. The struggle around the throne, securing escape routes to the corners, and constructing the encirclement—asymmetric objectives create tense gameplay.

A Viking Game

The phrase “Viking game” drew me in. People who crossed the North Sea, raided, traded, and settled. A game played on their ships and in their settlements during long winter nights. That alone is romantic.

Traces of Hnefatafl have been found in Icelandic sagas, British burial sites, and Irish ruins. Pieces and dice have been excavated, and literary sources describe matches. Before chess spread across Europe, Hnefatafl was the intellectual board game of the North.

The structure of siege and escape may reflect the Viking worldview. A small elite surrounded by a great army, searching for a breakthrough. Or a great army besieging a fortress, slowly tightening the grip. Such battles are condensed onto the board.

But romance alone doesn’t finish an implementation.

Reconstruction Confusion

The original rules of Hnefatafl have not survived completely. Various reconstructions have been attempted from artifacts and textual fragments.

The problem is that reconstructions differ in details. Can pieces pass through the throne? Is an empty throne hostile territory? How many directions are needed to capture the king? Can the king be captured at the board’s edge? Interpretations vary among researchers and enthusiast organizations, with multiple “official rules” claiming legitimacy.

This implementation adopts modern competition rules established on Fetlar Island, Scotland: an 11×11 board, the king wins by escaping to corners, and capturing the king requires surrounding on four sides.

However, even these rules have ambiguous points that forced implementation decisions.

Implementation Struggles

I started with excitement but ended up struggling considerably.

First, handling the throne and corners was complex. Only the king can stop on the throne. Only the king can stop on corners. But for capture purposes, both throne and corners function as “hostile territory”—you can’t stop there, but you can use them for flanking. Expressing this asymmetry through conditionals made the code convoluted.

Whether pieces can pass through the throne was also troublesome. The adopted reconstruction allows non-king pieces to pass, but others prohibit it. I maintained both behaviors as variants for verification, but the doubled conditions reduced clarity.

The king’s capture conditions were the most troublesome. Regular pieces are captured by flanking from two directions. But the king requires surrounding on four sides. However, when adjacent to the throne, three sides plus the throne suffice. Furthermore, some reconstructions allow capturing a king at the board’s edge with three sides.

Organizing these conditions as king_captured_by caused the state machine transitions to balloon. Test cases were divided finely by king position—adjacent to throne, adjacent to corner, at edge, at center—confirming capture conditions for each.

Verification involved visual inspection of 6 games, including king escapes, king captures, and no-moves endings, confirming legal moves and termination conditions.

Independent Decisions

For points not specified by the reconstruction or differing from the adopted rules, the following decisions were made.

  • Non-king pieces can pass through an empty throne
  • The throne is treated as hostile only when the king is not sitting on it (effective when attackers flank defenders)
  • The king cannot be captured at the board’s edge with three sides (four are required)
  • No-moves results in a loss (not passing to continue)
  • Win/loss determination by position repetition was not implemented

Reflections

I started because the romance of a Viking game drew me in, but implementation was tougher than imagined. Reconstruction branches, condition complexity, verification difficulties. Reviving the game of people who crossed the North Sea involves archaeological challenges.

Still, I imagine that when the king escapes to a corner on the 11×11 board, or when surrounded on four sides and captured, there’s the same excitement that players felt a thousand years ago.

An implementation started on a whim ended up being one of the most demanding tasks. But that struggle included, it became a memorable piece of work.