Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Homepage

Hnefatafl Board

History

Find out about the history of Hnefatafl.

Install

See how to install the software.

Rules

See the rules.

Artificial Intelligence

Learn about AI.

Translate

If you want to add, update, or fix a translation, open an issue and state what you want to do. If it is a minor change, you can just update the code and submit a pull request.

Discord

Discord

Help Me

If you have any issues with the software, open an issue on github.

Money PNG by Vecteezy

Hnefatafl Org by David Lawrence Campbell is licensed under CC BY 4.0CC BY 4.0CC BY 4.0

History

Hnefatafl Board

From Wikipedia:

Tafl Games

Tafl games (pronounced [tavl]), also known as hnefatafl games, are a family of ancient Northern European strategy board games played on a checkered or latticed gameboard with two armies of uneven numbers. Names of different variants of tafl include hnefatafl, tablut, tawlbwrdd, brandubh, Ard Rí, and alea evangelii. Games in the tafl family were played in Norway, Sweden, Denmark, Iceland, Britain, Ireland, and Sápmi.

Tafl gaming was eventually supplanted by chess in the 12th century, but the tafl variant of the Sámi people, tablut, was in play until at least the 18th century. The rules for tablut were written down by the Swedish naturalist Linnaeus in 1732, and these were translated from Latin to English in 1811. All modern tafl games are based on the 1811 translation, which had many errors.

New rules were added to amend the issues resulting from these errors, leading to the creation of a modern family of tafl games. In addition, tablut is now also played in accordance with its original rules, which have been retranslated.

Hnefatafl

Hnefatafl (sometimes now referred to as Viking chess) was a popular game in medieval Scandinavia and was mentioned in several of the Norse sagas. Some of these saga references have contributed to controversy over the possible use of dice in playing hnefatafl.

The rules of the game were never explicitly recorded, and only playing pieces and fragmentary boards are extant, so it is not known for sure how the game was played. If dice were in fact used, nothing has been recorded about how they were employed. Archaeological and literary sources indicate hnefatafl may have been played on a 13×13 or an 11×11 board.

Hnefatafl became a popular game in Northern Europe during the Viking era (end of the 8th century to 1000 CE), a turbulent time full of conflicts. When chess became a popular game during the Middle Ages, the rules of hnefatafl were forgotten over time. Hnefatafl was particularly popular in Nordic countries and followed the Viking civilization to other parts of Europe, primarily to the British Isles and the Viking country of Garðaríki in what is now part of Russia.

The game developed differently at different locations. Archaeologists have found editions in places such as Ireland and Ukraine. Hnefatafl literally translates to “fist table”, from the Old Norse (equivalently in modern Icelandic) hnef, ‘fist’, and tafl, ‘table’.

Modern Hnefatafl

The rules for Norse tafl were lost, but in the 1900s attempts were made to reconstruct the game based on the rules for the Sámi tafl game tablut. The rules for tablut had been written down in the 1700s, and translated from Latin to English in the 1800s (see § Tablut). Unfortunately, the rules were poorly translated from Latin and gave unbalanced gameplay, mainly due to the mistaken idea that the king must be surrounded on four sides to be captured – instead of two.

Different innovations were made to create a game that favoured the defender side less, such as limiting the king’s escape possibilities to the corners (instead of the entire edge of the board), making the king “weaponless” (unable to participate in capture), making the initial starting points of the attackers inaccessible for the king, and making it easier to capture the king against the corner fields of the board.

Today, many different versions of modern hnefatafl are in play – both online and on physical boards that are sold commercially. One variant used in tournaments is Copenhagen hnefatafl, which also features a “shield wall” mechanism to capture several soldiers at once, and an “exit fort” rule that enables the king to escape on the edge while otherwise being limited to escape in the corners.

Install

Login

Arch and Derivatives (Linux) AUR

In your terminal run:

sudo pacman --sync yay
yay --sync hnefatafl-copenhagen

Then under KDE go to Application Launcher -> Games -> Hnefatafl Copenhagen or in a terminal run \usr\bin\hnefatafl-client.

Chocolatey (Windows) chocolatey

Install Chocolatey.

Then install hnefatafl-copenhagen.

Go to the Start menu and run Hnefatafl.

Debian and Derivatives (Linux)

Download hnefatafl.list to /etc/apt/sources.list.d/ or:

echo 'deb [arch=amd64 signed-by=/etc/apt/keyrings/packages.hnefatafl.org.asc] https://hnefatafl.org/apt stable main' \
| sudo tee /etc/apt/sources.list.d/hnefatafl.list

Then, Download packages.hnefatafl.org.asc to /etc/apt/keyrings/ or:

wget https://hnefatafl.org/packages.hnefatafl.org.asc
sudo mv packages.hnefatafl.org.asc /etc/apt/keyrings/

Then in your terminal run:

sudo apt update && sudo apt install hnefatafl-copenhagen

Then under KDE go to Application Launcher -> Games -> Hnefatafl Copenhagen or in a terminal run \usr\games\hnefatafl-client.

Cargo (Linux, macOS, Windows) crates-io

Dependencies (Linux)

ALSA development files are needed to build cpal on Linux (rodio dependency, hnefatafl-client dependency). These are provided as part of the alsa-lib package on Arch, libasound2-dev package on Debian and Ubuntu, and alsa-lib-devel on Fedora.

The package uses the mold linker. This is provided via the mold package on Arch, Debian, Ubuntu, and Fedora.

Run

In your terminal run the following to run the client with Rust’s cargo:

cargo install hnefatafl-copenhagen
hnefatafl-client

Flatpak (Linux) flathub

See flathub.org.

Or after installing the application under KDE go to Application Launcher -> Games -> Hnefatafl Copenhagen

F-Droid (Android)

  1. Go to Google. Scroll down to Enhanced Safe Browsing for your account. If it is on, turn it off.
  2. Go to F-Droid and download F-Droid.
  3. Open F-Droid, go to search, and install Termux: Terminal emulator with packages.
  4. Open Termux, then run the following:
# Only need to run this once per update.

pkg upgrade
termux-change-repo
pkg install rust git x11-repo
pkg install xfce termux-x11-nightly
git clone https://github.com/termux/termux-packages termux-packages-hnefatafl-copenhagen-dest
git clone -b hnefatafl-copenhagen https://github.com/robertkirkman/termux-packages termux-packages-hnefatafl-copenhagen-src
cp -r termux-packages-hnefatafl-copenhagen-src/x11-packages/hnefatafl-copenhagen/ termux-packages-hnefatafl-copenhagen-dest/x11-packages/
cd termux-packages-hnefatafl-copenhagen-dest
scripts/setup-termux.sh
./build-package.sh -I -f hnefatafl-copenhagen
cd output/
apt reinstall ./hnefatafl-copenhagen*.deb
# Repeat this every time you want to run the program.

export LIBGL_ALWAYS_SOFTWARE=1 DISPLAY=:0
termux-x11 -xstartup xfce4-session &
hnefatafl-client --ascii

Then go to Termux:X11 from the main menu. You may need to hold Termux:11 to go to the Preferences -> Output, then increase the Display scale %.

NPM npm

# With Apache and Firefox on Debian.
sudo npm install -g hnefatafl-copenhagen
sudo mkdir --parent /var/www/html/pkg
sudo cp /usr/lib/node_modules/hnefatafl-copenhagen/ -r pkg /var/www/html

Then load the javascript on a webpage:

cat << EOF > /var/www/html/index.html
<!DOCTYPE html>
<html>
<head>
    <title>Copenhagen Hnefatafl</title>
</head>
<body>
    <h1>Copenhagen Hnefatafl</h1>
    <script type="module">
        import init, { Game } from '../pkg/hnefatafl_copenhagen.js';

        init().then(() => {
            const game = new Game();
            const output = game.read_line_js("show_board");
            console.log(output);
        });
    </script>
</body>
</html>
EOF

See the message protocol for all of the commands available.

# With Apache running.
firefox localhost

Redox @

Edit your user config to include:

[packages]
hnefatafl-copenhagen = "source"

You should be at least using the packages supplied via include = ["desktop-minimal.toml"]. Go to games and open Hnefatafl or run /usr/games/hnefatafl-client. After logging in and exiting the application, you’ll have to restart Redox, because the application is buggy.

There are also at least these bugs:

  1. There are no CJK fonts.
  2. On a button press two characters are read in instead of one.
  3. Backspace does not work.
  4. I think you have to restart Redox after entering the application, because TcpStream shutdown is not implemented.

Source github

See the github README.md file.

Note

At the moment their may be fairly regular updates. If you run into problems, make sure you are running the latest version.

Hnefatafl Org by David Lawrence Campbell is licensed under CC BY 4.0CC BY 4.0CC BY 4.0

Rules

Rules

From Copenhagen Hnefatafl with minor changes.

The Copenhagen rules were outlined 2012 by Aage Nielsen (Denmark), Adam Bartley (Norway) and Tim Millar (UK). English text and diagrams: Adam Bartley (Norway)

Based on the version that was last updated 21.12.2024.

Copyright © 1998-2025 Aage Nielsen, All Rights Reserved;

A: attacker
a: captured attacker
K: king
k: captured king
D: defender
d: captured defender
R: restricted space

1. Starting Board Position

Opening Game

2. First Turn

The attackers move first.

3. Movement

You can move to the edge of the board or another piece orthogonally:

Move

4. Capture

All pieces except the king are captured if sandwiched between two enemy pieces, or between an enemy piece and a restricted square. A piece is only captured if the trap is closed by the aggressor’s move, it is therefore permitted to move in between two enemy pieces. The king may take part in captures.

Captures

  ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────┐
11│R.........R│ │R.........R│ │R.........R│ │Rd........R│
10│...........│ │...........│ │...........│ │..↑........│
 9│...........│ │...........│ │...........│ │..A........│
 8│...........│ │...........│ │...........│ │...........│
 7│...........│ │...........│ │...........│ │...........│
 6│.....R.....│ │...A.R.....│ │..K..R.....│ │.....R.....│
 5│.....d.....│ │...d.......│ │..↓........│ │...........│
 4│.A→→→......│ │.Ad.dA.....│ │...........│ │...........│
 3│...........│ │...↑.......│ │..a........│ │...........│
 2│...........│ │...A.......│ │..D........│ │...........│
 1│R.........R│ │R.........R│ │R.........R│ │R.........R│
  └───────────┘ └───────────┘ └───────────┘ └───────────┘
   ABCDEFGHIJK   ABCDEFGHIJK   ABCDEFGHIJK   ABCDEFGHIJK

Doesn’t Capture

  ┌───────────┐ ┌───────────┐
11│R.........R│ │R.........R│
10│...........│ │...........│
 9│...........│ │...........│
 8│...........│ │...........│
 7│...........│ │...........│
 6│.....K.....│ │.....R.....│
 5│.....D.....│ │.D.D.......│
 4│.A→→→......│ │..↑........│
 3│...........│ │..A........│
 2│...........│ │...........│
 1│R.........R│ │R.........R│
  └───────────┘ └───────────┘
   ABCDEFGHIJK   ABCDEFGHIJK

Shield Wall

A row of two or more taflmen along the board edge may be captured together, by bracketing the whole group at both ends, as long as every member of the row has an enemy taflman directly in front of him.

A corner square may stand in for one of the bracketing pieces at one end of the row. The king may take part in the capture, either as part of the shield wall or as a bracketing piece. If the king plus one or more defenders are attacked with a shield wall, the attack will capture the defenders but not the king.

  ┌───────────┐ ┌───────────┐
11│R.........R│ │R.........R│
10│...........│ │...........│
 9│...........│ │...........│
 8│...........│ │...........│
 7│...........│ │...........│
 6│.....R.....│ │.....R.....│
 5│...........│ │...........│
 4│...........│ │...........│
 3│..D........│ │...........│
 2│..↓DDD.....│ │........AA.│
 1│R..aaaD...R│ │R....A→.KdR│
  └───────────┘ └───────────┘
   ABCDEFGHIJK   ABCDEFGHIJK

5. Restricted Squares

Restricted squares may only be occupied by the king. The central restricted square is called the throne. It is allowed for the king to re-enter the throne, and all pieces may pass through the throne when it is empty.

Restricted squares are hostile, which means they can replace one of the two pieces taking part in a capture. The throne is always hostile to the attackers, but only hostile to the defenders when it is empty.

The four corner squares are also restricted and hostile, just like the throne. The board edge is NOT hostile.

  ┌───────────┐
11│R.........R│
10│...........│
 9│...........│
 8│...........│
 7│...........│
 6│.....R.....│
 5│...........│
 4│...........│
 3│...........│
 2│...........│
 1│R.........R│
  └───────────┘
   ABCDEFGHIJK

6. King’s Side Win (Defenders)

If the king reaches any corner square, the king has escaped and his side wins.

Defender Wins

Exit Forts

The defenders also win if the king has contact with the board edge, is able to move, and it is impossible for the attackers to break the fort.

  ┌───────────┐ ┌───────────┐
11│R.........R│ │R.........R│
10│...........│ │...........│
 9│...........│ │...........│
 8│...........│ │...........│
 7│...........│ │...........│
 6│.....R.....│ │.....R.....│
 5│...........│ │...........│
 4│...........│ │...........│
 3│...........│ │....DD.....│
 2│....DD.....│ │....D.D....│
 1│R..DK.D...R│ │R...DKD...R│
  └───────────┘ └───────────┘
   ABCDEFGHIJK   ABCDEFGHIJK

7. Attackers Win

The attackers win if they can capture the king.

The king is captured when the attackers surround him on all four cardinal points, except when he is next to the throne.

If on a square next to the throne, the attackers must occupy the three remaining squares around him.

The king cannot be captured on the board edge.

The King is Captured

  ┌───────────┐ ┌───────────┐ ┌───────────┐
11│R.........R│ │R.........R│ │R.........R│
10│...........│ │...........│ │...........│
 9│...........│ │...........│ │...........│
 8│...........│ │...........│ │...........│
 7│.....A.....│ │...........│ │...........│
 6│....AkA....│ │.....R.....│ │.....R.....│
 5│.....A.....│ │....AkA....│ │...........│
 4│...........│ │.....A.....│ │....A......│
 3│...........│ │...........│ │...AkA.....│
 2│...........│ │...........│ │....A......│
 1│R.........R│ │R.........R│ │R.........R│
  └───────────┘ └───────────┘ └───────────┘
   ABCDEFGHIJK   ABCDEFGHIJK   ABCDEFGHIJK

If the attackers surround the king and ALL remaining defenders with an unbroken ring, then they win, as they have prevented the king from escaping.

Attacker Wins

The King is Not Captured

  ┌───────────┐ ┌───────────┐
11│R.........R│ │R.........R│
10│...........│ │...........│
 9│...........│ │...........│
 8│...........│ │...........│
 7│...........│ │...........│
 6│.....R.....│ │.....R.....│
 5│...........│ │...........│
 4│...........│ │...........│
 3│...........│ │...........│
 2│....A......│ │.A.........│
 1│R..AKA....R│ │RKA.......R│
  └───────────┘ └───────────┘
   ABCDEFGHIJK   ABCDEFGHIJK

8. Perpetual Repetitions

Deleted Rule

Perpetual repetitions are forbidden. Any perpetual repetition results in a loss for the defenders.

Added Rule

If the defender would repeat a board position, the move is not allowed.

9. Automatic Loss

If a player cannot move, he loses the game.

Artificial Intelligence

AI

Artifcial Intelligence

I am working on making a reasonably strong artificial intelligence, but it is pretty weak at the moment. You can run it via hnefatafl-ai on the Arch, cargo, and Debian installs, or via the source package. See --help for what options you can pass it.

You’ll have to create an account for it first on whatever server you will be running it on. Run hnefatafl-client and log onto the server. Then, Create an account for your AI, prefixing the username with ai-.

It can also be run as a service for the Arch and Debian installs. Edit the file /etc/hnefatafl-ai-attacker.conf or /etc/hnefatafl-ai-defender.conf and add

USERNAME=username
PASSWORD=password

Don’t prefix the USERNAME with ai- here.

Then run

sudo systemctl start hnefatafl-ai-attacker

or

sudo systemctl start hnefatafl-ai-defender

If you want to change the settings for the AI further, you can edit /usr/lib/systemd/system/hnefatafl-ai-attacker.service or /usr/lib/systemd/system/hnefatafl-ai-defender.service and change the value of ExecStart.

By default this runs basic AI with a search depth of 4. The AI seems pretty weak if you go below 4. You can increase the depth, but the AI may run very slowly.

Be warned that by default this runs in parallel using all available CPUs. If you only want to use one CPU, you can pass --sequential.

Hnefatafl Org by David Lawrence Campbell is licensed under CC BY 4.0CC BY 4.0CC BY 4.0