MEXICA (Rafael Pérez y Pérez)


MEXICA: 20 Years — 20 Stories is a book of twenty machine-generated stories plotted by the program MEXICA. These have been rendered into natural language, both in English and in Spanish, by the machine’s designer Rafael Pérez y Pérez.

The stories concern characters of Aztec legend: a jaguar knight, a princess, a warrior, a lady, the god Huitzilopochtli. They fall in love, they get into fights, they pursue or evade one another, they run away to hide beside the volcano Popocatépetl. They experience subtler things, too: lust, jealousy, inner conflict, mingled love and hate, even embarrassment at having been inconsistent.

The stories were produced as plot descriptions by the machine, and their human readable descriptions are both translations of those plots — so the Spanish is not a translation of the English, or vice versa. There are, I’m told, subtle differences between the Spanish and English versions of the stories, though my Spanish is not good enough to appreciate this deeply. But even from the most basic reading Spanish, it is clear that sometimes elements are named differently in the two versions.

At the same time, the versions are narrated in a way that retains the evidence of their machined nature. For instance, here is a passage:

The princess was a proud native of the Great Tenochtitlán City.

The competition between the princess and the eagle knight had reached levels of strong animosity.

Quickly, the princess and the eagle knight were immersed in a fight.

This is perfectly readable English, but it suggests an outline for a longer piece, a short story or even a novel, in which these things we are being told are rendered more fully. Performing that more extensive rendering, though, would have concealed what exactly the machine was doing — and it is extremely interesting to have this clearly evident. Besides, as the afterword indicates, we might consider that writing in this way is simply the style and voice of MEXICA the generator.

MEXICA has a different texture from works produced by standard grammars. A common thing in a system like Parrigues or Voyageur, or in a Tracery bot, is for the grammar to get showy about its large collection of interchangeable parts. A character in the Parrigues Tarot might choose to eat a pie made of any one of a couple hundred varietals of apple, or visit any of several dozen towns that Parrigues recalls from its past work. That variety is part of the intended pleasure of the piece, a sense of the rich particularity of an imagined world.

MEXICA is not so committed to surface-level variety. When one of the characters is wounded, they use tepezcohuite, the magic plant, for healing, or else prepare a potion; they do not draw from a long list of randomized plants. When one wants to leave, they run away to one of a handful of locations: a named lake, a named forest, a named volcano.The character identities are similarly repeated: lady, princess, jaguar knight, eagle knight, slave. Even in the course of twenty stories, these elements repeat several times and become familiar; or familiarly unfamiliar, since one of the important points about MEXICA is its cultural identity, and this may be an identity that is not well known to some readers.

For this reason, the stories have a ritual weight when read singly, but are apt to run together if one reads a number of them at a time; it is probably most satisfying to read one, then set the book aside.

Most of MEXICA’s stories do concern matters of the heart and of personal relationships of one kind or another: love triangles, unrequited love, a lover who treats another badly. This means its stories are always toothier than TALESPIN output like this:

John Bear is somewhat hungry. John Bear wants to get some berries. John Bear wants to get near the blueberries. John Bear walks from a cave entrance to the bush by going through a pass through a valley through a meadow. John Bear takes the blueberries. John Bear eats the blueberries. The blueberries are gone. John Bear is not very hungry.

With its repetitions and recurrences, MEXICA suggests a world of eternal cycles in which the same characters are locked in one affair of the heart after another, often to tragic effect, and generally ending in separation rather than death.


In addition to the twenty stories (each in two languages), MEXICA contains a description, written for an audience not necessarily steeped in the history of computational creativity or interactive storytelling methods, which explains how MEXICA the system works.

At the core of its process is a cycle of engagement and reflection. During “engagement,” it’s actively choosing new actions to add to the plot. Actions can create emotional circumstances (the knight and the princess fell in love) and conflicts (the knight resented the princess for not returning his feelings). The system then searches its database for identical circumstances and chooses randomly among the possible next actions — so its understanding of what is logical depends on what has been logical in similar stories previously.

During “reflection,” MEXICA is considering the quality of what has been generated so far and looking to make additions to the generated story in order to correct for these problems. The “reflection” stage might involve adding elements to introduce characters in the story, or to lay groundwork for a conflict that has already been chosen for the characters — or to repair logical problems introduced by the selection of events. So for instance if the engagement section had chosen an event sequence like

  1. the lady injured the princess
  2. the princess ran away to the volcano
  3. the lady killed the princess

the reflection sequence might realize that it needed to insert an additional element to get the characters back in the same location between steps two and three, winding up with

  1. the lady injured the princess
  2. the princess ran away to the volcano
  3. the lady followed the princess
  4. the lady killed the princess

So in this regard, MEXICA is able to produce stories that focus on events of potential interpersonal or plot interest first — how do these characters feel about each other, and how does this drive them to act? — and then it does its dry-goods-management second, moving people and props around as required to support the key events.

The story is deemed finished when all conflicts are resolved — this generator will not produce, and would not consider it a good thing to produce, a Limbo-style plot. Many of the stories end with one of the characters running away. This resolves pending conflicts they might have with another character, since the two are no longer together and there is no longer any danger. Character deaths or marriages — the classic endings of western fairy tales — are not so common, and I do not know whether this is down to choices about the corpus, or to an actual difference in the content of Aztec folklore.

The reflection stage examines other story qualities besides continuity. Pérez y Pérez mentions that, if the story is currently deemed insufficiently novel, the reflection stage will prefer to look for new actions that are comparatively rare. Reflection is also the point at which it adds character thoughts — realizations that they are conflicted or upset, for instance.

Ultimately, MEXICA evaluates its own output for coherence, interestingness, and novelty — novelty in particular addressing whether this piece is similar to pieces already extant in its database. That same database, of course, is also the source of a lot of its solutions to narrative problems.


One of the interesting points of this generator, quite different from the grammar-based process I use for the Parrigues projects, is that it is intentionally replicating an authorial process of creation and revision. The revision omits some of the actions that might be common in a human authoring process, such as throwing away actions, moving actions from one location in the plot to another, or revising the motivations of the characters to make particular actions seem more inevitable.


Articles about MEXICA. Pérez y Pérez has published a number of scholarly articles about MEXICA. These are the ones for which I could find a free public access copy:

Disclosure: I received a copy of this work from the author, though after I had asked him about it.

2 thoughts on “MEXICA (Rafael Pérez y Pérez)”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: