A comprehensive Python implementation of Norse Tafl games, specifically focusing on Hnefatafl, with support for both terminal-based and graphical user interfaces. This project serves as a foundation for building game agents and facilitating machine learning research in the domain of ancient board games.
Note
: The key features of this project have been made private.
Tafl games are a family of ancient Nordic board games, with Hnefatafl being the most well-known variant. These asymmetric strategy games date back to the Viking Age and represent the eternal struggle between a small defensive force and overwhelming attackers. The games were popular throughout medieval Scandinavia and provide fascinating insights into both game theory and historical culture.
This implementation aims to preserve the traditional gameplay while providing a modern platform for both casual play and serious game research, including machine learning applications and agent-based exploration of game strategies.
The Tafl Game Engine provides:
- Complete Hnefatafl Implementation: Full game logic with piece movement, capture mechanics, and win conditions
- Multiple Interfaces: Both Text-based UI (TUI) and Graphical UI (GUI) support using Textual
- Extensible Architecture: Object-oriented design allowing for easy addition of other Tafl variants
- Game State Management: Comprehensive board state tracking and validation
- Configuration Support: JSON-based game configuration system
- 11x11 Board: Traditional Hnefatafl board configuration
- Piece Types: King and Pawn pieces with distinct behaviors
- Team Colors: Black (attackers) and White (defenders) with proper turn management
- Movement Validation: Straight-line movement with path obstruction checking
- Capture Mechanics: Sandwich capture system with special corner rules
- Win Conditions: King escape to corners (White wins) and king capture (Black wins)
- TUI Commands: Interactive command system (
quit
,newgame
,help
,rules
,board
,move
) - GUI Features: Dark mode toggle, multiple game support, scrollable interface
- Input Validation: Robust position parsing and command validation
- Visual Representation: Unicode symbols for different piece types and colors
python src/tui.py
python src/gui.py
ng
ornewgame
- Start a new gameb
orboard
- Display current board statem
ormove
- Make a move (prompts for positions)h
orhelp
- Show help informationr
orrules
- Display game rulesq
orquit
- Exit the game
- White (Defenders): Protect the King and help him escape to any corner of the board
- Black (Attackers): Surround and capture the King before he can escape
- Implemented Features:: The key features of this project have been made private.
- In Development:: The key features of this project have been made private.
Any public content is licensed under the Apache License, Version 2.0. See LICENSE for full details.