Play Hnefatafl, the old Scandinavian board game of a king and his guards against a ring of attackers, on a 9 by 9 or 7 by 7 board against the computer or a friend.
Attackers pieces left 16
Defenders and the king 8
Your move (Attackers)
Session You 0, Computer 0, Draws 0
Wins 0
Quiet moves 0 of 80
Attackers (rose triangles) move first and try to capture the king (the amber star). Defenders (sky discs) guard the king, who wins by reaching any of the four corners (the diamond squares). Every piece slides any distance along a row or column over empty squares, never jumping. Only the king may stop on the middle square (the throne, marked with a cross) or on a corner; any piece may slide over the empty throne. You capture an enemy piece by moving so that it sits in a straight line between the piece you moved and another piece of yours. A corner counts as your piece against everybody, the empty throne counts against attackers always and against defenders when it is empty, and the king helps the defenders. Moving between two enemy pieces is safe. On the 9 by 9 board the king is captured only when attackers stand on all four sides of it, or on the three open sides when it is beside the throne, and never on the edge. On the 7 by 7 board, away from the throne, two attackers on opposite sides capture it. A side that cannot move loses. The game is drawn after 80 moves in a row, by both sides together, with no capture. Click a piece, then a marked square. Arrow keys move around the board, Enter or Space selects or moves, Escape lets go of the piece.
Easy picks any legal move at random, for either side. Medium searches up to 3 moves ahead with alpha-beta pruning, looking at no more than 30,000 positions and stopping after about 0.9 of a second. Hard searches up to 5 moves ahead, one move deeper at a time, and stops deepening after about 0.45 of a second or 60,000 positions. Both score a position from the attackers' side: pieces left (a defender counts more than an attacker), how far the king is from a corner, how many squares it can slide to, a clear line from the king to a corner (a large penalty for the attackers), attackers touching the king, and pieces next to the corners. The defenders play for the opposite score, and a defender to move with a clear line to a corner is counted as a win. It is a fixed search with no learning and no opening book, so a careful player can beat it. Undo takes back your last move and the reply, and a game that used Undo is not counted as a result. Undo is not available once a game is over.
As-is, no warranty. These apps are free under their listed license and run entirely in your browser. Use at your own risk — don't blame me if your PC catches fire, your dog runs away, or the math turns out wrong. Verify anything that actually matters. None of this is professional financial, medical, legal, or engineering advice.
Two armies face each other on a square board. The attackers (rose triangles) start at the middle of each edge. The defenders (sky discs) stand around their king (an amber star), who starts on the middle square, the throne, which is marked with a cross. The four corner squares, marked with a diamond, are the king’s way out. The attackers move first.
The page warns you when the king has a clear line to a corner. As the defender, that is the move that wins. As the attacker, you have one move to block the line or capture the king.
Controls:
Click one of your pieces (pieces that can move have a dashed outline) and then a square with a green dot. On the keyboard, arrow keys move around the board, Home and End jump to the ends of a row, Enter or Space selects a piece or moves it, and Escape puts the piece down. Every square is announced with its row, column, contents and whether it is the throne or a corner, and the status line says what each move did and what it captured. Pieces differ by shape, not just by colour: triangle, disc and star. The page address carries the opponent, difficulty, side and board size.
The engine keeps, for every square and each of the four directions, the list of squares met going outward. A piece’s moves are those lists cut off at the first piece, with the throne and corners skipped for everyone but the king. After a move it looks at the four squares around the landing square for enemy pieces that are now sandwiched, and it asks a separate question about the king.
The test suite pins the rules in several ways:
The computer comes in three levels and plays either side:
Both searches score a position from the attackers’ side and the defenders play for the opposite score. The score counts pieces (a defender is worth more than twice an attacker), how far the king is from a corner, how many squares it can reach, a large penalty for each corner the king has a clear line to, a bonus for attackers touching the king and a small one for pieces on the squares next to the corners. A defender to move with a clear line to a corner is counted as a win at once. Captures and king runs are tried first, and moves that tie for best are chosen between at random.
The alpha-beta search is checked against a plain minimax with no pruning, which gives the same value at depths 0 to 2 on 9 by 9 and 0 to 3 on 7 by 7 in positions from random games. In the test suite, Hard defenders searching 3 moves ahead won at least 5 of 6 small-board games against Easy attackers, and Medium attackers lost at most 1 of 6 against Easy defenders. In the suite’s test positions, the defenders slide the king to a corner when the line is open, the attackers capture the king when they can, and when the king threatens a corner the attackers block it. The suite asserts that Hard answers every position it is asked about in under 5 seconds, a bound loose enough for a slow machine; the design limit is about 0.45 of a second. The computer waits about 0.45 seconds before moving so you can follow along, and moves at once if you have asked for reduced motion.
Nothing is uploaded and there is no account. Against the computer, your win count for each difficulty (for both sides and both boards added together) is saved in your browser’s local storage, as small whole numbers inside a small JSON object, under one key. Clearing site data removes it. The session tally lives only on the page and resets when you leave it. Two-player games are not saved.
Only finished games count. A game in which you used Undo is not counted against the computer, so the saved figures are not inflated.
Free to play, no ads, nothing uploaded. These games are original and are not affiliated with any other game or brand.