Glass Bead Game in Python

Let's play a game?
Let’s play a game?

What is a glass bead game anyway?

In everyday language, this phraseological unit means something abstruse, overcomplicated and useless. The expression goes back to novel by writer Hermann Hesse, for which he received the Nobel Prize for a minute. The novel depicts a fictional world, arranged in such a way that a special country of intellectuals is founded in the midst of ordinary states in the world – Castalia… People living in it can, without thinking about a piece of bread, devote themselves to answering humanitarian questions devoid of practical use, such as the interpretation of some line of an ancient poem. All other states tolerate the existence of Castalia and regularly throw off their content (well, purely as the UN), and Castalia herself brings up teachers of languages, literature, music and mathematics for the outside world a little, but by and large she owes nothing to anyone. The ultimate expression of isolation from practical life is precisely the same glass bead game – the most authoritative activity within Castalia, but very few people understand outside of it.

Those who are accustomed to bouncy action will find it difficult to read the novel: there is little going on there. Hero Joseph Knecht studies in different institutions, walks here and there, talks conversations, and at first achieves great success, moving up the internal hierarchy of Castalia, becomes the most important in the glass bead game (which means – the most important in general), but then he is disappointed in everything and leaves the country, believing that it is better to live next to ordinary people. Morality, in general, is simple, but formulated by a German writer in the midst of World War II (1943 in the yard), it becomes a socially significant statement: intellectuals, despite the temptation to isolate themselves from the world and immerse themselves in their manuscripts, should not lose contact with what is happening around …

True, Knecht, helpless in ordinary life (spoiler!), Dies pretty quickly outside Castalia, but that’s a completely different story.

The novel has survived to this day and has not yet been deposited into a deep archive, not thanks to the simple truths inherent in the plot and not thanks to the boring monologues of Hesse’s characters. The pearl of the work is just the idea of ​​that very game. How it looks and what it consists of, the author does not write anywhere. And this, most likely, is one of the reasons for its attractiveness. Describe everything to Hesse in detail, the game immediately lost its aura of mystery and creative potential. And now the reader himself has to figure out what’s what, and it’s fun.

How should it all look like?

I see the glass bead game as a manipulation of signs (the presence of the actual “beads” in the game is just a metaphor). Signs are objects that have a material representation (“signifier”) and the meanings behind it (“signified”). The signifier for the letter “A” is how this letter looks, and the signified is localized within a particular semiotic system, for example, the graphic system of the Russian language, where there is a sound corresponding to this letter.

The process of playing itself is rather a game in the same sense as “playing a musical instrument”, that is, it is a performance of a pre-composed piece, and not a game in the sense of rivalry between some players. Although for Hesse, the primary meaning of “play”, which is associated with activities that do not bring benefit, where the process is more important than the result.

Therefore, the glass bead game must have some kind of alphabet of characters, the set of which is much wider than that included in the alphabet of natural languages. In addition to letters, it should definitely include musical notes, symbols from mathematical notation, and God knows what else. Their signs, probably, should be not only for individual notes and sounds of the language, but also for whole musical passages and classical quotations – from ancient authors, ancient Indian and Japanese poetry and everything in the world that is accessible to the intellectuals of Castalia.

The interest of the game, apparently, in the combination of all these elements and the tradition behind them. For example, the combination of some theorem with the melody of a sonata of the 17th century should be perceived as witty, and the pentatonic row with a quote from Virgil (a conventional example) as something boring and banal. The rules of rhyme in Russian poetry can serve as a certain analogy: the verbal rhyme like “get angry – shave” is boring, and “comrades – look for the goods” sounds fresh, because the pun. Who said that you need to perceive this way? Nobody, just such a tradition has developed, and if you are not familiar with this tradition, then you do not see the difference. That is why the people outside Castalia did not understand the glass bead game.

In the course of the game, all these combinations of signs are modified, transformed, shuffled, forming new unexpected combinations, and the transformations themselves also obey some rules, because there is nothing more boring than a game without rules.

How to translate this into code?

You just need to encode the entire cultural heritage of mankind and come up with rules for transforming one state of the “beads” laid out on the game board into another. There is a feeling that this is still the same match. Let’s start small.

What if our alphabet so far includes only Chinese writing and the meanings with which we will juggle, we borrow from Chinese poetry Tang era? On the one hand, such a limitation in comparison with the entire culture of mankind makes us shrink quite strongly. On the other hand, the Chinese “alphabet” is large, and the Chinese diploma poetry is clever enough for a computer prototype of a glass bead game.

Let’s take the rules from the most status intellectual game – chess. Yes, it would be necessary from th, but then in our scheme there would be too strong a tilt towards the East, and it is necessary to maintain the diversification of the countries of the world.

The Tang Chinese have verses in which there are exactly 8 lines, and the characters in a line are necessarily 7. In modern editions, a punctuation mark (, or。) is placed at the end of the line, as a result we get a matrix of 8×8 signs, which exactly corresponds to the playing field of chess. Plus, the hieroglyphs look quite square, which reinforces the associations with the cells on the board. We will work with already existing Tang poems.

The rules can be like this. We take some real chess game and turn each of its moves into transformations of the Chinese text. During the move of the figure, we will swap the hieroglyphs that correspond to the starting and target fields of the move. For example, if the rook moves from a8 to b8, then we swap the first and second characters in the first line. When taking pieces, we will not throw out the hieroglyphs, because then our 8×8 matrix would collapse and we would not be able to play further.

In the course of the game, the original poetic text will change in an unpredictable way, and the hieroglyphs will enter into new unexpected relationships, which is what we need.

Sawing a package

We take management for creating python packages, we select from corpus of Tang texts those that suit us in the 8×8 format (8 full-fledged hieroglyphs in 8 lines, alas, does not exist), we fasten ability to read PGN format, in which listings of chess games are recorded – and now, package ready… Hesse’s novel is called “The Glass Bead Game” in English, but we still have a limited functionality prototype, which we will reflect in the title (also pun intended): “Chess Bead Game”.

The package can load a specific poem (or random, if the user does not know which poem he needs), knows who wrote it and what it is called:

import chess_bead as cb
g = cb.Game(poem_num=2000)

The package can load a chess game in the PGN format:

import chess_bead as cb
g = cb.Game(pgn_file="/path/to/file.pgn", poem_num=2000)

If the user does not have his own PGN file at hand, it can be taken from a ready-made set. But in general, there are archives of chess games. cyclopean multi-gigabyte

Then the package can start the game and store all the states of the “beads”, that is, the positions of the hieroglyphs after each move.

Here is a poem by the great poet Du Fu before the game:

g = cb.Game(poem_num=1765)
verses = g.start_game()
initial_state =[]
for line in verses[0].lines:


V translation Natalia Azarova:

Climbing up

a nervous wind soars to the sky

monkey cry for the dead

at the shallow white spray with a spin

circles of birds above the water

so incessantly losing trees

rustling rustling leaves

so endlessly rolling the yangtze

the flow of the meeting

a thousand miles from home a stranger

long sad autumn

years gone sick and lonely

I still climb the tower

hard and hard from the grief of dislike

frost blooms on the temples

strange looking at an unlucky old man

but I don’t drink wine anymore

Another translation

The wind is swift and the sky is high.

In the forest, the monkeys are screaming.

Over the clear, autumn water of the stream

Autumn birds are flying.

Autumn leaves are circling, falling

They are scarlet and light,

And stretch into the distance from the native land

The vastness of the Great River.

(translation by A. Gitovich)

Now let’s mix these beautiful verses, guided by a classic game from the Spassky-Fischer match 1972 year.

g = cb.Game(pgn_file="5152.pgn", chess_game=3, poem_num=1765)
verses = g.start_game()

In the end, it turned out like this:

g.result # А чем закончилась партия?
'1/2-1/2' # ничья

final_state =[]
for line in verses[89].lines:


What does all this mean? This is not for me. I don’t know Chinese, I didn’t study in Kastalia. I can only use an online translator. He is great takes over the function of an oracle:

The frost is over

No one comes to mourn the stop of the wine tree.

The bowls of monkeys and birds are new.

And the sad platform of the river flies back to the iron

Iron of the day on hard sand.

A million years is not enough to create a whistling sound.

A hundred tall visitors often have sideburns in the fall.

I am sick and I hate the wind.

To be honest, I’m not surprised that no one came to mourn the stop of the wine tree, and I also believe about sideburns in the fall. In other words, I would think that everything said in the poem is true.

But it’s boring to look at the letters without visualization. Let’s add the possibility of creating pictures and animating the game. For this we need font… The license assumes that to supply it can only as part of the software, which is just our case. It turns out like this:

v = cb.Viz(verses,, g.title)

Here, the field to which the piece moves is indicated in red, and the field from which it moves is shown in gray.

Now let’s add documentation and the package is ready.

This is our version of the glass bead game. Of course, this is a special case. We need other variants of sign systems and other games besides chess, but the general direction is now discernible.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *