🧩 Combinatorics of Beads: When Tang Poetry Meets Chess in Python
What if you could shuffle classical Chinese verses using chess moves — and get weird, wonderful new poetry?
If you’ve ever read Hermann Hesse’s The Glass Bead Game, you know the feeling: a mysterious, intellectual game where players combine symbols from music, math, art, and literature to create beautiful, useless patterns. Hesse never explained the rules. He wanted every reader to invent their own.
So I did. With Python.
Meet Chess Bead Game – a small Python package that lets Tang dynasty poems (8 lines × 7 characters + punctuation = 8×8 grid) play a game of chess against themselves. Each character is a square. Every move swaps two characters. After 40 moves, the poem becomes… something else.
And something surprisingly poetic.
🎯 The Rules (such as they are)
- Take a classical Chinese poem from the Tang era (7 characters per line, 8 lines → 8×8 board).
- Load a real chess game from a PGN file.
- For each move: swap the characters on the from and to squares.
- Watch the original text mutate – step by step, move by move.
- No practical purpose whatsoever. ✔️
That’s it. Pure, useless, beautiful combinatorial art.
🐍 Show Me the Code
import chess_bead as cb
game = cb.Game() # loads a random poem + a random chess game
verses = game.start_game() # run all moves
viz = cb.Viz(verses, game.author, game.title)
viz.gif() # creates an animation of the whole transformation
That’s literally it. Two lines to shuffle an 8th‑century poem using a Kasparov‑vs‑Topalov knight sacrifice.
📜 Before & After (with Machine Translation)
Original poem (anonymous Tang style):
新婦去年胼手足,
衣不暇縫蠶廢簇。
白頭使我憂家事,
還如夜裏燒殘燭。
當初為取傍人語,
豈道如今自辛苦。
在時縱嫌織絹遲,
有絲不上鄰家機。
Translation (DeepL):
Last year the bride’s hands and feet were calloused,
No time to sew, silkworms abandoned in their frames.
White hair makes me worry about family matters,
Like a candle burning low in the night.
At first I listened to other people’s gossip,
How could I know I’d suffer so myself?
Back then I complained that weaving silk was too slow,
But now I have silk – yet won’t use the neighbor’s loom.
After 10 chess moves – same characters, completely new order:
新裏去年胼手家,
衣不暇婦憂廢簇。
白頭使我蠶足事,
還如夜織燒殘不。
當初為嫌絲人語,
豈道縫今自辛苦。
在時縱取傍絹遲,
有如燭上鄰家機。
New translation:
Last year in the inner chamber, calloused hands stayed home,
No time for the woman – worries over wasted silk frames.
White hair makes me busy with silkworm matters,
Yet like weaving at night, burning the candle but not quite.
At first I disliked the gossiping people,
How did I know the seams would now be stiff with toil?
Back then I freely took the silk, but too slow,
It's like a candle on the neighbor's loom.
The two versions enter a dialogue. The banal candle becomes surreal. Helplessness turns into defiant.
♟️ Why Programmers Will Love This
- It’s completely useless – perfect for a side project.
- Combinatorial explosion – 64! possible permutations, but constrained by chess move legality.
- Data mashing – poetry × chess × machine translation × animation.
- Plug‑and‑play architecture – easily extend to other text grids (Latin hexameters? Haiku? ASCII art?).
-
Python package on PyPI –
pip install chess_beadand you’re ready.
The package already includes:
- A small corpus of Tang‑style 8×8 poems.
- PGN parser for real chess games.
- GIF generator (shows each move as a frame).
- DeepL integration? No, but you can pipe the output yourself.
🧠 The Bigger Picture
Hesse dreamed of a game that weaves together mathematics, music, astronomy, Greek, Latin, and Chinese wisdom. This is one tiny step: chess (rules) + Chinese poetry (data) + randomness (deterministic but emergent).
The next steps? Add mathematical sequences, musical notation, ancient Greek fragments, maybe a SPARQL endpoint to Wikidata. Imagine a game where a Beethoven motif, a line from Ovid, and a tangram shape swap places according to chess rules.
Yes, it’s absurd.
Yes, it’s beautiful.
Yes, I want to see the GIF.
📦 Get It / Try It
- PyPI:
chess_bead - Docs: chess-bead.readthedocs.io
- GitHub: github.com/nevmenandr/chess_bead
pip install chess_bead
Then run the 3‑line script above and watch poetry disintegrate into art.
🎼 “Let it resound in our games, in our whole life, in everything we create and endure!”
― Hermann Hesse (paraphrased)
Inspired by Alexander Genis’s confession: “In *The Glass Bead Game, I was only interested in the game itself. Everything else – just because.”*
Top comments (0)