The Mathematics of Taikyoku Shogi
A formal model, exact counts from the engine, and a roadmap to a machine-checked formalization in Lean 4.
Abstract · 1 Model · 2 Counts · 3 State space · 4 Game tree · 5 Mobility · 6 Rank algebra · 7 Symmetry · 8 Complexity · 9 Lean roadmap · 10 AI and solving · 11 Open problems · References
Working draft. Every number marked V was computed by the game's own rules engine and is reproducible
with godot --headless --path . -s tests/math_stats.gd. P marks short proofs given here,
C results cited from the literature, O open or conjectural statements and
L statements planned for a machine-checked proof in Lean 4. The Lean development has not been written yet; the code
blocks below are statements we intend to prove, not compiled theorems.
Abstract
Taikyoku shogi is the largest known shogi variant: two armies of 402 pieces on a \(36\times 36\) board, drawn from 301 piece kinds with move rules that include unbounded riders, jumpers, two-step “area” moves, 90° turning “hook” moves and multi-capture “range” moves. We give a formal model of positions and legal moves, exact initial-position counts (\(97\) legal first moves; \(1{,}426{,}099\) positions after three plies), upper bounds on the size of the state space (\(<10^{3604}\)) and a measured branching factor (\(\approx 320.6\) in random play), closed forms for the mobility of riders on an \(N\times N\) board, and a rank algebra for range capture. We then state the theorems we plan to formalize in Lean 4, describe how we are working to make the AI stronger and to solve as much of the game as can be solved, and list open problems.
1. A formal model
1.1 Board, sides, pieces
1.2 Moves as set-valued functions
Write \(\mathrm{Own}_t(\pi)\) and \(\mathrm{Opp}_t(\pi)\) for the squares occupied by the side to move and by its opponent, and orient direction vectors by the mover (\(d\mapsto d\) for Black, \(d\mapsto -d\) for White). A move is a finite path \(p=q_0\to q_1\to\cdots\to q_m\) together with the set \(C\) of captured squares. A kind's move rule is a finite union of the following components.
The set \(\mathrm{Mv}(s)\) of legal moves of a position is the union over the mover's pieces of their components' moves. There is no check rule: a move is legal exactly when it is generated. A player wins by capturing every enemy royal piece. Promotion is a rule parameter: on entering the far 11 ranks (default), on first capture, or never.
In the implementation a move is the triple \((\text{from},\text{to},\text{via})\). Distinct values of \(\text{via}\) are counted as distinct moves, which is why counts below exceed the number of (from,to) pairs.
2. Exact counts from the initial position
| \(n\) | \(\mathrm{perft}(s_0,n)\) | ratio to previous |
|---|---|---|
| 1 | 97 | - |
| 2 | 9,393 | 96.8 |
| 3 | 1,426,099 | 151.8 |
V The opening has \(97\) legal moves for Black. Note \(\mathrm{perft}(s_0,2)=9393\) is \(16\) below \(97^2=9409\): White's number of replies depends slightly on which move Black played (the mean is \(9393/97\approx96.8\)).
Statement for Lean: L theorem perft_one : (moves init).card = 97, and likewise perft init 2 = 9393, perft init 3 = 1426099, checked first by decide/native_decide and then, if the kernel allows it in reasonable time, by a proof that avoids the compiler (see Section 8).
3. Size of the state space
Both numbers dwarf the figures usually quoted for other games (as tabulated by Allis, 1994): chess \(\approx10^{46}\), shogi \(\approx10^{71}\), Go \(\approx10^{172}\) positions C. A far better bound should exist because reachable positions have at most 804 pieces and captures are irreversible, but any such bound remains astronomically beyond exhaustive enumeration.
3.1 Endgame tablebases are within reach
For a King and one other piece against a bare King the number of placements is \(1296\cdot1295\cdot1294\cdot 2=4,343,492,160\) P (ordered placements of three distinct pieces, times side to move). That is about \(4.3\times10^{9}\) states: small enough that exhaustive retrograde analysis of such endgames is a realistic computation, and would give exact distance-to-win tables for every piece kind. O We have not computed them.
4. Branching factor and game-tree size
We measured the number of legal moves along random playouts (3,600 positions over 30 playouts of up to 120 plies, fixed seed) V:
| plies | 0–19 | 20–39 | 40–59 | 60–79 | 80–99 | 100–119 |
|---|---|---|---|---|---|---|
| mean legal moves | 203.0 | 267.8 | 307.4 | 349.8 | 382.9 | 412.9 |
The overall mean is \(\bar b\approx 320.6\) with a maximum of 608. The growth with the ply number reflects the board opening up as pieces are captured and the riders gain open lines. (Random play is not representative of strong play, so \(\bar b\) is a rough scale, not an estimate for good players.)
Following Allis, a game-tree complexity estimate is \(\bar b^{\,d}\) for an average game length of \(d\) plies. The length of a real game is unknown, so we tabulate:
| \(d\) (plies) | \(\log_{10}\bar b^{\,d}\) |
|---|---|
| 100 | 251 |
| 200 | 501 |
| 400 | 1002 |
| 800 | 2005 |
For comparison Allis gives \(\approx10^{123}\) (chess), \(10^{226}\) (shogi) and \(10^{360}\) (Go) C. Even a short game of 200 plies exceeds all three.
5. Mobility and piece value
V Over the 301 kinds: minimum \(\mu=1\), median \(43\), mean \(70.0\), maximum \(2,520\). The maximum is attained by the Hook mover, whose turning paths multiply the count: \(\mu\) counts moves \((\text{from},\text{to},\text{via})\), so one destination reached by several turning squares is counted several times. (The number of distinct destination squares is smaller; see Section 9, M6.)
The mean mobility of a queen (rook + bishop) is therefore \(\approx 70+46.02=116.02\) on this board. The ratio of mean mobilities rook : bishop is \(70/46.02\approx1.52\), close to the classical chess convention \(5:3.25\approx1.54\); this is suggestive but not a derivation of piece values, because blockers are ignored. A mobility model with occupancy (a random density \(\delta\) of blockers, giving geometrically distributed ray lengths) is a natural refinement. O
6. Range capture and the rank algebra
Planned Lean form.
-- sketch, not yet compiled
inductive Side | black | white
structure Pos where
board : Fin 36 → Fin 36 → Option (Kind × Side)
turn : Side
def rangeCapturePassed (π : Pos) (p : Fin 36 × Fin 36) (d : Int × Int) (r : Nat) : List (Fin 36 × Fin 36) := ...
theorem rangeCapture_rank_lt {π p d r c} (hc : c ∈ captured (rangeCapture π p d r)) :
rank (kindAt π c) < r := by ...
theorem royal_untouchable {π p d r c} (hc : c ∈ captured (rangeCapture π p d r)) :
¬ isRoyal (kindAt π c) := by ...
theorem rangeCapture_card_le {π p d r} : (captured (rangeCapture π p d r)).length ≤ 35 := by ...
7. Symmetries and invariants
The setup is not left–right symmetric (only 2 of its 12 ranks read the same in both directions) V, so there is no reflection symmetry of the initial position to exploit.
8. Complexity-theoretic context
For \(n\times n\) generalizations, chess is EXPTIME-complete (Fraenkel & Lichtenstein, 1981), shogi is EXPTIME-complete (Adachi, Kamekawa & Iwata, 1987) and Go under Japanese rules is EXPTIME-complete (Robson, 1983) C. Taikyoku shogi is a single finite instance, so asymptotic classes do not apply to it directly. We conjecture that the family of games obtained by letting \(N\) grow with the setup scaled accordingly (and a fixed repertoire of the component moves above) is also EXPTIME-complete: the natural route is a reduction from a generalized shogi position, since every shogi piece is a Taikyoku component. O We have no proof.
Infinite play. The rules as implemented contain no repetition or move-limit rule, so the game graph has cycles and the value of a position is defined by the usual retrograde fixpoint
(win/loss in a finite number of plies, otherwise draw by infinite play). Formalizing this in Lean needs an inductive predicate WinIn : Nat → Pos → Side → Prop and a coinductive notion of avoiding loss. L
9. Roadmap: a machine-checked formalization in Lean 4
We intend to develop the model above in Lean 4 (de Moura & Ullrich, 2021) so that every V and P statement on this page becomes a theorem checked by the kernel, and every counting claim is tied to the same data the game executes. Planned milestones:
- M1 – Data. Import the 301 kinds (Betza-style move descriptions) as a Lean structure; prove the generated component tables equal the ones the engine uses.
- M2 – Positions and moves. Define
Pos, the component move functions (slide, leap, jump-slide, hook, area, range capture) andmoves : Pos → Finset Move; prove soundness (every move is on the board, never captures an own piece except in range capture, never captures a royal by range capture). - M3 – Perft.
perft init 1 = 97,perft init 2 = 9393bydecide;perft init 3 = 1426099by a verified efficient implementation (refinement proof from the naivemoves). A kernel-checked proof of \(n=3\) withoutnative_decideis a serious computation (about \(1.4\times10^{6}\) leaves) and may need a bespoke reflection proof. - M4 – Invariants. Items (i)–(v) of Section 7.
- M5 – Rank algebra. Lemmas 1 and 2, then the statement that range capture is the unique move component that can capture more than 2 pieces.
- M6 – Closed forms. Mean mobility of riders (Propositions 3 and 4), generalized to arbitrary direction sets \(D\subseteq\{-1,0,1\}^2\), with
decidechecks for \(N=8\) and \(N=36\). - M7 – Symmetry. Proposition 5 and its consequences for outcome classes.
- M8 – Game theory. Outcome predicate by retrograde induction, correctness of a small endgame solver (King + one piece vs King), and the claim that for each kind the tablebase value is computable within the \(4.3\times10^{9}\) bound.
Beyond formulas we expect Lean to expose subtle points in the sources: where the surviving rule descriptions disagree (promotion, hook moves, area-move edge cases) the formal definitions will force a choice, and we will publish each choice as a labelled rule parameter.
10. Making the AI smarter, and solving the game
What the AI is today. The computer opponent is an iterative-deepening alpha-beta search with killer and history move ordering, quiescence search at the hardest level and a time budget (1.5 s at Normal, 3 s at Hard). Its evaluation is material weighted by the mobility value of Section 5, \(v(k)=10+2\mu(k,c)\), plus positional terms (advancement and pressure on the enemy royals). It is far from strong: with a branching factor of \(\approx 320.6\) (Section 4) a search of fixed time reaches only a few plies.
Our goals. We are working to make the AI substantially smarter and, as far as mathematics allows, to solve the game. Following Allis, a game is ultra-weakly solved when the value of the initial position is known, weakly solved when a strategy achieving that value from the initial position is known, and strongly solved when the value of every position is known. Strong solution is impossible here: Section 3 bounds the state space only by \(10^{3604}\), and even the placements of the two initial armies number \(\approx10^{2181}\). Weak or ultra-weak solution of the full game is also far beyond brute force at today's computing power, so our program is staged:
- Search engineering. Transposition tables with Zobrist hashing, better move ordering, null-move and late-move reductions, and a faster move generator (the current generator is written for clarity, not speed: it takes about 20 s to enumerate the \(1.4\times10^6\) leaves of \(\mathrm{perft}(s_0,3)\)). Every optimization will be checked against the reference perft numbers of Section 2.
- Learned evaluation. Replace hand-set mobility values by a value function learned from self-play, with the mobility model as the prior, and Monte-Carlo tree search or a policy network to focus the search on the few hundred plausible moves out of \(\approx 320.6\).
- Opening and middlegame knowledge. Opening books mined from self-play, and measured strength ratings of each version against the previous one (we already have an AI-versus-AI match harness for this).
- Endgame tablebases. Exact retrograde solution of small-material endgames, starting from King + one piece against King (\(4.3\times10^{9}\) states, Section 3.1), then positions with two or three pieces per side. These are strongly solved sub-games, and they give the search exact values at the leaves.
- Solved fragments of the rules. Complete solutions of reduced boards (for example \(N=8,\dots,12\) with scaled-down setups) to learn how first-player advantage and drawishness depend on size, which is evidence about the full game.
- Verified solvers. Where a computation claims a game-theoretic value (a tablebase, a reduced-board solution) we will certify it with a proof object checked in Lean (Section 9, M8), so a published result is not just “the program said so”.
We expect a full solution of Taikyoku shogi to remain out of reach for a long time, if it is possible at all; the point of the program is to make the AI measurably stronger, to establish exact results on every fragment that can be solved, and to say precisely where the boundary lies. O
11. Open problems
- Is there a first-player advantage? (Even for chess and shogi this is unknown; here it is far from decidable by search.) O
- What is the empirical distribution of game length under strong play? It fixes the real size of the game tree (Section 4).
- Exact reachable-state counts for small material (Section 3.1), and the longest forced win in King + piece vs King for each kind.
- A tight combinatorial bound on the number of reachable positions in terms of the multiplicities \(m_k\).
- Complexity of the scaled family (Section 8).
- Do range-capturing generals admit an elegant potential function proving that long sequences of captures must end (so that no cycle of pure captures exists)? Trivial for captures (the piece count decreases), but the stronger question about bounded numbers of non-capturing moves between captures is open.
References
- H. Adachi, H. Kamekawa and S. Iwata. Shogi on \(n\times n\) board is complete in exponential time. Trans. IEICE J70-D(10):1843–1852, 1987 (in Japanese).
- L. V. Allis. Searching for Solutions in Games and Artificial Intelligence. PhD thesis, University of Limburg, 1994.
- R. Betza. Chess with different armies and the “funny notation” for piece moves. Chess Variant Pages, 1996.
- L. de Moura and S. Ullrich. The Lean 4 theorem prover and programming language. CADE-28, 2021.
- A. S. Fraenkel and D. Lichtenstein. Computing a perfect strategy for \(n\times n\) chess requires time exponential in \(n\). J. Combin. Theory Ser. A 31(2):199–214, 1981.
- G. Hodges. Ten Shogi Variants. 2002.
- J. M. Robson. The complexity of Go. Proc. IFIP Congress, 1983.
- C. E. Shannon. Programming a computer for playing chess. Philosophical Magazine 41(314):256–275, 1950.
- J. Tromp. Counting legal Go positions (with G. Farnebäck), 2016, and his estimates of the number of chess positions.
- “Taikyoku shogi”, English Wikipedia (CC BY-SA 4.0): the source of the piece list and setup used here.
The engine, the data and the script that produced every V number are in the project repository; the numbers on this page are regenerated by python3 tools/build_math.py from data/math_stats.json.
Found an error or want to help with the Lean development? hello@taikyokushogi.com.