Specification

Hnefatafl Encoding Notation (HEN)

version 1.0

Download HEN spec (PDF)

Hnefatafl (pronounced nef-eh-TAH-full) is a Viking game that predates chess. It's similar to Chess, Go or Pente, but is different in that it has asymmetrical goals: white is trying to defend or escape. Black is trying to conquer, like a real Viking raid. Black has twice as many pieces.

HEN (a play on FEN from chess) was invented by Drew Gislason, and is a compact plain text representation of a Hnefatafl game. It is useful for:

For Hnefatafl rules, see https://aagenielsen.dk/Copenhagen_Hnefatafl_11x11.pdf

Other rules, such as Fetlar, Tablut and Brandubh can be listed as a top comment in the HEN file, but how a computer interprets that is outside the scope of this document.

See also:

HEN File

A HEN file (or string) is ASCII, and begins with "HENv1" followed by white-space. The "HENv1" may be preceded by whitespace or comments. All elements are separated by whitespace of any kind (e.g. space, tab, newline, comment). UTF-8 characters (such as a rune) are allowed in the comments.

Next, the following optional fields are allowed in order.

  1. Initial Board State
  2. The List of Moves
  3. Final Board State

If the initial Board state is missing, the normal 11x11 board setup is assumed.

If there are no moves, the Final Board State is ignored and should not be present.

If the List of Moves results in a win, loss or draw (including timeouts and resignations), it is marked in the move list as such, and reflected in the optional Final Board State.

A result marker is the official result and may record a resignation, timeout or agreed draw that the moves alone don't show.

A sample HEN file is below. It omits the initial state, which is assumed to be the normal game setup. Three full turns are taken (black, then white x 3). The optional resulting board state is shown in text graphics.

<!-- a standard HEN file -->
HENv1

1.f2f3 f4b4 2.k4c4* f5f4 3.fXjX f4k4

L ...vvvvv...
X .........v.
9 ...........
8 v....V....v
7 v...VVV...v
6 vv.VVKVV.vv
5 v...V.V...v
4 v.v.......V
3 .....v.....
2 ...........
1 ...vvvvv...
  abcdefghijk

Black's Move

The following compact HEN file is the same, but is not as easy for humans to read:

HENv1 1.f2f3 f4b4 2.k4c4* f5f4 3.fXjX f4k4

If any errors are found in the HEN file (for example, bad characters in the move sequence, or rows and columns don't agree), then the loading software should flag the error.

HEN File Comments

Optional HTML style comments can be added and are treated as white-space. For example:

<!-- my comment here -->

Since comments are treated as white-space, you can insert them anywhere white space is expected.

HENv1 1.f2f3 f4b4 2.k4c4*<!-- good move by black! -->f5f4 3.fXjX f4k4

Hnefatafl Board State

The Board State describes where all pieces are on the board, and whose turn it is. When used for the Final Board State, it can also indicate a win, loss, or draw.

Below is a verbose board state. Notice that black has the opportunity to capture three white pieces with the next move.

L ...........
X ...........
9 ..........v
8 .........vK
7 ..........v
6 ..v........
5 ..V........
4 vV.Vv......
3 ...........
2 ..v........
1 ...........
  abcdefghijk

Black's Move

Here is the same board state in compact form:

11 11 10v 9vK 10v 2v8 2V8 vV1Vv6 11 2v8 11

Each state indicates whose move it is (black or white). The compact form of the Initial Board State does not need to indicate it is black's move as that is assumed. But if it were white's move, in the same setup example, it would be indicated, as shown below.

11 11 10v 9vK 10v 2v8 2V8 vV1Vv6 11 2v8 11 W

In this second case, white could move d4c4 and block black from taking any of its pieces.

Compact and Verbose Board States are detailed in the sections below.

Compact Board State

The Initial Board State for a new 11x11 Hnefatafl game in compact form is always:

3vvvvv3 5v5 11 v4V4v v3VVV3v vv1VVKVV1vv v3VVV3v v4V4v 11 5v5 3vvvvv3

The numbers represent empty squares. The V's represent Vikings, lowercase v for black (invading), uppercase V for white (defending). The K represents the white King.

Each row, listed from top to bottom, is separated by whitespace (usually a single space). The numbers are in base 10, so an empty row is 11 (eleven) spaces on an 11x11 board. The board size can be inferred by the number of spaces, so this same scheme works for 7x7 or 9x9 boards. If any row does not agree with the size of the first row, it shall be flagged as an error by any tool that can read HEN.

Moves are usually black, then white. But if this board state represents the middle of the game (or a scenario) and it is White's turn to move, then a W is placed after the last row. For example:

3v1v5 5v5 4v6 v2V1Vv1vv1 2vVV6 vv2VKV2vv 1v1v1VV3v 2v1V2v2v V10 5v1v3 4vvv4 W

The Compact Board State indicates the game is over with a W!, B!, or D at the end to indicate White wins, Black wins or Draw. The game over markers are also present in the List of Moves.

An example of white winning is below (notice the king in the upper right corner of the board):

3vvv4K 1v8v 5V1v2v v8V1 v3V1V4 vv1VV1VV2V v3VVV3v 2v2V4v 11 5v3v1 3vvvvv3 W!

A T or R can be added after a win or loss to indicate Timeout or Resignation. For example, if black lost due to running out of personal game time, the end marker would be:

3v1v5 5v5 4v6 v2V1Vv1vv1 2vVV6 vv2VKV2vv 1v1v1VV3v 2v1V2v2v V10 5v1v3 4vvv4 W!T

Verbose Board State

A Verbose Board State provides the same information as the compact state, only in a more human readable form. This is useful to describe scenarios for training purposes, or for the final state in tournament games to allow humans to quickly read it from the file alone without help of a computer to interpret the syntax.

The board layout includes coordinates, with rows numbered on the left, and columns lettered at the bottom. The lower left is coordinate a1, the top right is coordinate kL.

Fonts displaying the HEN file must be fixed width to display correctly.

Initial Layout example, which is always Black's Move:

L ...vvvvv...
X .....v.....
9 ...........
8 v....V....v
7 v...VVV...v
6 vv.VVKVV.vv
5 v...VVV...v
4 v....V....v
3 ...........
2 .....v.....
1 ...vvvvv...
  abcdefghijk

Black's Move

White's Move example (about to capture 3 black Vikings with shieldwall maneuver):

L ...vvvvv...
X .....v.....
9 .v.........
8 .....V....v
7 v...VVV...v
6 ...VV....vv
5 v...VVV...v
4 v..K......v
3 ...........
2 ...VVV.....
1 ..Vvvv.....
  abcdefghijk

White's Move

Note: while no examples are shown in this document, a 13x13 board could be represented by using M and N for the additional rows, and lm for the extra columns, resulting in coordinates like aM or mN.

Hnefatafl List of Moves

The List of Moves shows progress of a game or scenario from the Initial State to the Final State of the board.

Note: the * is informational only. It does not tell how many and which pieces were captured. If following the Copenhagen rules, it is clear, but if following other rules, it is up to the interpreter of the game.

Example set of opening moves (three turns, black moves from f2 to f3, then white moves from f4 to b4, etc...):

1.f2f3 f4b4 2.k4c4* f5f4 3.fXjX h6h9

If the initial board state indicates it is white's turn to move, then black's move is null, represented by a -. For example:

1.- f4b4 2.k4c4* f5f4 3.fXjX h6h9

The - can also be used for the black or white move in games that use a move timer (for example 15 seconds per move), to indicate that the move was forfeited, or in the case where black wins (so white has no move). The dash is optional in the latter case.

An entire game can be represented by the List of Moves. No Board States are needed, as standard setup can be assumed and Final Board State can be calculated. The same end-game marker is used as in compact Board State, W!, B!, or D. A T or R is added to indicate if the win or loss was due to timeout or resignation.

Below is an example of white winning a game:

1.f2j2 f8c8 2.b6b2 f7f9 3.k8f8* h6h8 4.hLiL g6i6 5.a8a9 f6h6 6.fXbX h6h3 7.dLcL h3a3 8.b2a2 a3k3
9.j2k2 k3a3* 10.k2a2 f4f2 11.d1c1 a3k3 12.j6j2 k3k1 W!

Below is an example of black winning a game:

1.a8a9 f8j8 2.k7j7 f7f9 3.j6j2 f6f8 4.b6bX f8b8 5.a4b4 f4f3 6.h1i1 e5e2 7.i1i8* g5g2* 8.i8c8 h6h1
9.b4b7 d6d2 10.a7a8 f3f2 11.bXb9 B!

The game over markers are the same as used in the Compact Board State.

Complete Hnefatafl Game Examples

A complete Hnefatafl game where black wins is shown below.

HENv1

1.a4b4 d6d8 2.k7i7 d8b8 3.dLd6 b8e8 4.a5d5 g5g3 5.k5j5 f8g8 6.a7d7 g3f3 7.k4j4 g8i8 8.h1h4 e8g8
9.a8d8 f3k3 10.k8j8 k3i3 11.hLh8* i3c3 12.gLgX c3c6* 13.fXf8* c6c1 14.eLe9 c1c7* 15.e1e4 c7c3
16.g1g4* c3c5* 17.fLf9 e7e8 18.d1d7 c5c4 19.d7e7* c4c7 20.d8d7 g7g8 21.i7g7* c7b7 22.gXg9* f5g5
23.f2f5 e5b5* 24.j5h5* h6h7 25.g7f7 h7h6 26.a6b6* b7a7 27.f1f3 g6g5 28.e4e5* h6i6 29.g9g6* a7a3
30.e7e6* - B!

L ...........
X ...........
9 ....vv.....
8 .....v.v.v.
7 ...v.v.....
6 .v..vKv.Vvv
5 ....vv.v...
4 .v....vv.v.
3 V....v.....
2 ...........
1 ...........
  abcdefghijk

Black Wins!

A complete Hnefatafl game where white wins is shown below.

HENv1

1.k7i7 h6h3 2.hLh4 f8e8 3.h1h2* e8h8 4.eLe9 e5e3 5.a5b5 d6d8 6.a4c4 f7f8 7.a7c7 e3a3 8.k8j8 e7d7
9.d1d5 g7e7 10.gLg8 f4e4 11.i7i8* f5f3 12.d5f5 e7i7 13.k5j5 e4e5* 14.j6i6* d7k7 15.e9e8* f6f7
16.a8c8* f7h7 17.i6h6* h7hX 18.c4f4* hXkX 19.fXjX kXkL W!

L ...v.v....K
X .........v.
9 ...........
8 ..v.v.v.vv.
7 ..v.......V
6 vv..V..v..v
5 .v..V.V..v.
4 .....v.v..v
3 V..........
2 .....v.v...
1 ....vvv....
  abcdefghijk

White Wins!

← Back to Hnefatafl