Monday, 4 April 2022

Generating random content for RPGs using Artificial Intelligence

Sea-biscuit cutting and rolling machine

The topic of Artificial Intelligence in TTRPGs (actually Machine Learning - but I'll call it AI for simplicity's sake) is something I've seen discussed a lot recently. noisms asked on his blog whether AI would change the hobby. On the NSR Discord server we've had AI-generated failed careers for Electric Bastionland posted by Chris McDowall, and some Cairn sparks from Yochai Gal, plus an ongoing discussion on how AI can be used in RPGs.

Machine Learning is something I've wanted to tinker with for a while now. I've been put off by lack of a powerful enough PC, a loathing of the Python programming language, and general laziness. Meanwhile I've poured hundreds of hours' hacking into my Deity Galaxy twitter bot, using Tracery and nested lists (a little like Perchance) to generate text which is... rarely satisfactory. I plan to publish a book of "nanodeities" based on curated output from Deity Galaxy (I wrote about this a while ago). But before doing so, I will  have to spend a lot of time sharpening up the bot's output.

A couple of weeks ago my friend, the horror writer James Burt, came to visit. We had a wonderful walk around the hills about Allenheads where, among many other things, we talked about my nanodeities plans. James has written previously about using AI as a writing partner, and our shared acquaintance Shardcore published what may be the world's first AI-written book, "The Future is Already Here" by Algohiggs (a computerised riff on the book The Future Starts Here by John Higgs which, BTW, is a fabulous book; if everyone read it then the world would be a better place). James suggested that I try generating deities using AI and the GPT engines.

So that's what I've done. I used the OpenAI Playground to paste in some prompt text (which you'll find at the end of this post) and was blown away with the results:

Mallus, deity of the abandoned sock, is a small, slightly furry creature, not dissimilar to a ferret, that can be found in the laundry basket of most homes. Mallus is a mischievous god, and often delights in hiding one sock of a pair, or tangling up clothes that have just been ironed. To please Mallus, leave a sock out on the floor for him to play with.

Kerfuffle, goddess of tangled wires, is best worshipped by knotting together at least 7 different electrical cables, and then throwing them into a puddle. The resulting sparks will be a sign of Kerfuffle's favour. Kerfuffle herself is a small, spiky sphere, not unlike a hedgehog made of barbed wire.

Snorfle is the god of hiccups. Snorfle is an amorphous blob of green slime with a single eye in the center. To worship Snorfle, drink a pint of milk and then try to hiccup. If you are successful, Snorfle will grant you a wish, provided that wish is related to hiccups.

Schnarf is the god of electronic bleeps and bloops, and can be found in most electronic devices, especially those with a lot of buttons. Schnarf is especially fond of mobile phones, and can often be found lurking in the background when someone is taking a selfie. To worship Schnarf, simply take a selfie with a mobile phone and then offer it up to the god.

Those were all written by a computer! Wow. OK, that got my attention.

Suddenly I'm thinking of all sorts of uses for GPT-3 powered text generation. Tables of random content are a Big Deal in TTRPG-land, people can't seem to get enough of them (witness the wonderful d4 Caltrops). Right out of the box, GPT-3 understands these tables. When I asked it to "write a table of random encounters for a fantasy TTRPG", here is what it came up with:

10 believable but rather vanilla possible random encounters

As an aside, something which initially appears surprising is that this output includes the gaming-specific term "2d6". One of the great things about GPT-3 (in comparison with its more readily-available predecessor GPT-2) is that it was trained on a mind-boggling number of web pages, undoubtedly including many gaming blogs (and probably a sizeable number of random encounter tables). It is really great at understanding context, and using the relevant domain-specific language in its output. It can even write computer code, given just a very simple prompt:

To get improved random encounters, I started writing ("crafting"?) prompts to seed the AI-generated list. i.e. I started to write the sort of encounters that I would like to read. This took many iterations and, as you'll see from the prompts at the end of this post, required adding a huge amount of spice to the seed text in order to get encounters that didn't sound too generic.

Here is what the AI came up with when I tasked it with creating some random wilderness encounters (I had to hit "submit" several times to collect all of these examples):

* A small village of mud-huts is in the process of being slowly buried by an encroaching sand-dune. The villagers are in a state of panic. A quick check will reveal that the sand is being controlled by an evil sorcerer, who lives in a crumbling manor-house in the centre of the village, surrounded by a low moat. The sorcerer’s name is Hamza Omri, and he is a wicked man. In his basement, he possesses d6 bottles of a potion which, when drunk, will transform the drinker into a sand-dune. These potions are worth 100GP each, and Omri is willing to sell them. The sorcerer also possesses a magical amulet, which will allow the wearer to control any sand-dune within 100 miles. Omri is very reluctant to sell this, but will do so if offered d1000GP.

* A group of d6 pixies flutter down from the trees, laughing and playing. They carry with them a large number of brightly-coloured flowers, which they offer to the PCs. If the PCs accept the flowers, they will find that they are unable to move from the spot. The pixies will then proceed to strip the PCs of their clothes and possessions, and will fly away, laughing. The flowers are actually poisonous, and will cause the PCs to become paralyzed for d6 hours.

* A large group of d6+12 unicorns approaches, led by a magnificent white stallion. The unicorns are on their way to a magical spring, where they will drink the water and be transformed into Pegasus. The stallion is the only one who knows the location of the spring, and he is very reluctant to reveal it. However, if the PCs can convince him that they are worthy, he may show them the way. The spring is located in a hidden valley, guarded by a ferocious dragon. The dragon will allow the PCs to pass if they can answer three riddles.

* A small campsite, in which a fire is burning and a pot is bubbling. Sitting around the fire are 2d4 humanoids, with the heads of eagles. They wear colourful feathers and have beaks made of gold. These are the Aaracockra, a race of bird-people. They are friendly, and will share their food (a stew made of insects and small rodents) with the PCs. They will also give the PCs 2d4 feathers, which can be used as currency in some cultures, or as quills for writing.  
* A d4-1 skunk-like animals are chasing a small golden-furred creature with a long tail. This creature is a “chai”, a small, intelligent, furry creature who is being hunted by the skunks, who are known as “chai-hunters”. These chai-hunters are attracted to the chai’s fur, which is used to line cloaks and blankets. If the PCs help the chai escape the chai-hunters, the chai will invite them back to its village, where they will be welcomed with a feast and a chai-fur-lined cloak.
* 3d20 flying bats, each with a wingspan of around 9 feet, descend from the twilight sky, circling around the PCs, hissing and squawking. These are not ordinary bats. They are “shrieking bats”, which can emit a loud shriek which can be heard up to 5 miles away. This shriek can be used to warn other animals of danger, or to call for help. The bats will only attack if provoked. If the PCs capture one of the bats, they will find that its fur can be sold for 5GP.
* A column of luminous green slime slides across the ground towards the PCs, slowing as it nears them. This is a “slime-beast”, a predatory creature which feeds on small animals. If the PCs do not move out of the way, the slime-beast will envelop them, and begin to digest them. The slime-beast can be killed by fire, or by being frozen solid. If killed, the slime-beast will leave behind a sticky green residue which can be used as a glue.
* A large, slow-moving, armoured creature, resembling a cross between a turtle and a snail, emerges from a nearby pond. This is a “turtle-snail”, a harmless creature which is often hunted for its meat. The turtle-snail’s meat is tough and stringy, but can be roasted and eaten. The turtle-snail’s shell can be used as a bowl, or as a shield.

* A pink elephant-like creature, with trunk outstretched and a gleaming white tusk. It is covered in dozens of colourful umbrellas, hanging from its sides like leaves. The elephant is the reincarnation of a local rain god, and the umbrellas are his “holy symbols”. He is friendly and curious, and will follow the PCs around, trundling along behind them. He is also very clumsy, and has a habit of knocking over small trees and stepping on things. If the PCs give him a basket of fruit, he will be overjoyed, and will bestow upon them a magical blessing: for the next 24 hours, they will be able to breathe underwater.

* 2d6+6 very tall (around 12 feet) humanoids, with ashen grey skin and long white hair. They are wearing simple white tunics, and each carries a large wooden staff. These are the ash-walkers, guardians of the forest of Ashes. They are friendly, but will not allow the PCs to enter the forest of Ashes, as it is a sacred place. If the PCs are persistent, the ash-walkers will tell them a story: “Once, long ago, there was a great kingdom, whose people were just and good. But the king was corrupted by power, and he became a tyrant. His people rebelled, and the kingdom was destroyed in the ensuing war. The forest of Ashes is all that remains of that kingdom. It is a place of sadness and loss, but also of hope. For one day, the ash-walkers believe, the kingdom will be reborn, and its people will be just and good once again.” 

Well. That's rather interesting. There's still a clear tendency for these encounters to revert to something rather more generic than the examples I've fed them, and there are inconsistencies which need tidying-up and details which need filling-in. But I'd say that these encounters are at least as creative as 75% of the equivalent human-written content out there.

I'm really tempted to keep fiddling with this and creating more encounters, but OpenAI Playground costs money (I'm still well within my $18 initial free credit, but I have lots of uses I want to put that remaining credit towards). 

In the future I'm sure we will see more and more AI replacing (or at least providing an increasingly-used alternative to) old-school tables. The key, as ever, is the seed text, and so there will still be a need for humans to craft texts which lead to interesting results from the AI. Unlike with tables though, a single set of well-written prompts can generate pretty much unlimited outputs forever more. So it may not be true to say that we will need good writers as much as ever. We may only ever need them once.

The other thing that this type of AI is great for - and which I intend to explore a lot more over the coming months - is providing inspiration and feedback for human-written text. This might operate in a similar way to existing writing partnerships, allowing ideas to be bounced back and forth and refined before the human partner settles on a final revision. Also a great way for breaking out of writer's block!

Below are the hand-written prompts I put into the OpenAI playground to generate the texts above. To generate your own encounters, sign up for an account at OpenAI, then head to the playground and paste in the second list below (or write your own prompts). I'd be really interested to hear of any good results that it comes up with - please write them in the comments below.

Nanodeities prompts:

Manufarraion is the god of a discarded spoon in a soup-kitchen in the Outer Hebrides. Manufarraion looks mostly like a mouth, with gobbets of brown drool dribbling out, but has a yellow translucent dome above that mouth which glows gently when fed compliments. To worship Manufarraion, fill a spoon with concentrated gravy and then pour it over a piece of limestone the size of a squid. If you are lucky, you will be rewarded with a bottomless bowl of brown Windsor soup.

Kleafluvia, goddess of a quarter-acre patch of scrubland halfway between Staines and Slough, is desperately seeking worshippers who would be willing to construct a multi-storey car park upon her domain, increasing its surface area and significantly increasing the chances of attracting converts to her cult. In appearance, Kleafluvia is somewhat amorphous, somewhat bear-like, and somewhat like the extraneous screw that comes with an IKEA product. She sings reasonably well, and likes to play Kabaddi on Sundays.

Enkovi is a deity sometimes encountered when paragliding in the Northern Pennines. Although mostly invisible, Enkovi can take on the aspect of a polygon-footed Atlantic skua, but with somewhat shorter wings. Enkovi is quite desperate for worshippers who are happy to throw themselves off a sizeable boulder in exchange for a little air.

F'nuff is an egregore created during a ritual during which all of the 7 participants stubbed their toes and sneezed. F'nuff has domain over sneezing and liminal headaches. F'nuff looks like an abandoned VCR with a wrinkled nose and bloodshot eyes. When F'nuff is placed beneath a television and contemplated, reality will briefly glitch, flickering black-and-white noise across the vision of all those within a 23-foot radius.

Brant, godhead of mild irritation, can be encountered and worshipped in most photobooths. Brant is humanoid, but with one shoe larger than the other, and eyes that are always looking where you are not. Anyone simply wearing a wire-wool jumper and brushing their hair in front of their eyes, whilst pulling an uncomfortable face, will be considered by Beant as one of their worshippers.

Burbcore, unremitting goddexx of pink fluffy blankets, takes the form of an anthropomorphised smoothing-iron with kawaii attachments. Run a heated iron gently across a pink fluffy blanket and Burbcore will sooth you with feelings of hikikomori for at least the next century. Burbcore sometimes sends a spirit messenger to their most esteemed worshippers, in the form of a wrinkle-toed dove. The messenger will vomit up a fortune-cookie message slip, before flapping away drunkenly.

Trunkeleon, god of a tiny leaf on the end of a twig on the end of a branch on a tree on the outskirts of the tiny village of Wumpington-sue-le-Brough, looks like a teeny-tiny aphid with 21 legs. Bring Trunkeleon a soupcon of sap, and he will dance for you and grant you a wish, provided that wish is related to leaves. Trunkeleon’s deadly enemy is Bunkiliion, goddess of pincers. 

Reðellton is a squeaky transformer for an 00-gauge model railway, who thinks that they hold domain over all toy vehicles. To elevate Reðellton to godhead status would require a network of model-railway enthusiasts all forming a ring while touching the terminals of their kits’ transformers and singing the theme tune to Thomas the Tank Engine transposed into a minor key. On achieving godhead status, Reðellton intends to lay bobbles of lichen across the entire empire. Reðellton smells of burnt foil and toffee, and has the eyes of a slithy tove.

Random encounter prompts:

* A caravanserai of 6d10 small humanoid traders - squat grey individuals whose eyes are almost hidden within deep folds and wrinkles. Their clothing is cut and sewn in patterns not seen in these parts for 1,000 years. Their 2d6 elephant-like beasts of burden totter under bundles of balsa-wood crates, oak barrels, and musty heavy-woven cloth, precariously bound together with hemp ropes. The traders call themselves the Unari, and their beasts are elluph-ents. The Unari traders have in stock most items that the PCs may want to buy, but slightly smaller than usual, and sold at 25% more than regular prices. They also carry amphorae of “wub-wub juice”, a sticky liquid which tastes like molasses. This wub-wub juice is ladled out and sold by the spoonful: one dessert-spoon-sized dose costs 11GP and heals d3 HP. At the centre of the caravan, two stallions tow a sealed iron wagon studded with copper-and-verdigris rivets. Shut inside with wagon is a barrelled chest, itself locked and bound with multiple chains. Inside are d100 x 1000 GP, 2d10 gems - rubies emeralds, pearls and peridots - worth d10 x 100 GP; d4 magical weapons; and a plain looking pendant - a hag-stone on a black string - which increases the wearer’s haggling-ability, allowing them to buy things at 50% cheaper than usual and sell them at 50% more expensive.

* A deep voice booms from behind an artificial copse (made of lincoln green cloth and whittled sticks): “LAY DOWN ALL OF YOUR POSSESSIONS AND BACK AWAY”. Behind the copse are 2d6 chestnut-brown 4-armed humanoids with earwig-heads. One of them bellows its demands through a parchment cone which magically makes lowers its voice by two octaves. If not obeyed, the earwig-people will leap out and attack. 25% of them carry a moebius-halberd and an earwig-shield; 25% carry two two-handed hammers decorated with engravings of rotting apples; the remaining 50% wield four impossibly-curved swords. Each has a purse of sticky silk, containing 2D6 SP. Behind the copse are sacks of a similar silk, containing a further 2d20 GP, a rough piece of jet work d20GP, and the earwig-people’s lunch. A dusty stylised earwig idol, worth 25GP, is hidden beneath some frayed felt blankets. There is also a terrified man, Humphrey Beligard, tied up and struggling. If released and escorted to the nearest village, he will thank the PCs and invite them to his effulgent home in a nearby town, where he will feed them a gourmand meal and present them each with a tin medal decorated with his own likeness, worth 3SP.

* A lone traveller is dragging a moth-eaten ochre anteater on a frayed piece of string. This road-stained traveller looks at the PCs pleadingly, tears welling in his bedevilled eyes. This is Waygu, former high priest of the Analeptine cult, now mute, alone, and very, very hungry. The anteater is the disgraced god Fuxu, whom an irritated balrog transmogrified into this despicable form many aeons ago. Any PC who approaches within 20 feet of Fuxu will feel an existential sadness caused by hallucinations of the death of all those they hold dear; they will also be unable to speak in anything other than barking hiccoughs.

* A herd of 4d100 silent antelopes approaches. The dust cloud raised by them billows for miles behind. A small number, around 5%, of the antelopes are ridden by translucent djinn wielding magical teal-coloured +1 scimitars and wearing nothing but yellow silk headdresses encrusted with rubies and dipped in oud and patchouli. These headdresses are worth 50GP each, but once a PC handles one then they will always smell of oud and patchouli, and can easily be detected even when invisible. The djinn are on their way to a battle many hundreds of miles away, which his been raging for the last millennium. They do not wish to stop for anything.

* 2d4 smooth frog-like animals with simian arms descend from sun-crisped vines, croaking a tuneless song. These “frogs” are harmless, but their skin emits a sticky grey ooze, smelling of acetone, which is used as a glue by the local Inamuri tribespeople. The creatures can be milked for this ooze, yielding d6 blobs, each of which can be sold for 5SP to the Inamuri. However, there is a 20% chance of the PC doing the “milking” getting stuck to the frog, which can only be removed by cutting off one of the PC’s fingers.  




10 comments:

  1. This is very cool! Glad to see more people doing ML stuff for RPGs. I keep saying I'll do more, and then getting lazy lol.

    You're one of those types who hates python eh >.>? Lol no worries, I do understand the complaints.

    ReplyDelete
    Replies
    1. Haha, yeah! Call me a weirdo, but I like to be able to actually _see_ parts of my code that are going to break things (and don't even get me started on tabs vs. spaces!)

      Delete
    2. The majority of my professional experience has been with Python, but I recently started using Go for some things and it has made me appreciate that side of things. I'm in the habit of typing my python code anyway but I also understand the criticisms of dynamic typing. I know there are plenty of other criticisms as well, but ya it's just so prevalent in the ML space that that's primarily what I use.

      Delete
    3. I'm OK with dynamic typing - the most significant part of my career was spent programming in ActionScript, but when Flash died I had to switch to JavaScript, and dynamic typing felt like a backwards step, but I came to love it.

      The other problem I always had with Python - although I believe this is largely solved now - is that on any bit of software I tried to write, half of the libraries I needed were Python 2 only and the other half were Python 3 only.

      Delete
    4. Aah, ya that's been mostly a non-issue for me, I think it's come up before but not too often, but my understanding is that that used to be much more of a problem.

      Delete
  2. I now feel like I ought to keep abreast of all this stuff if only to avoid becoming outmoded....

    ReplyDelete
    Replies
    1. I think that reading the comments on your two blog posts about this ought to keep you more abreast of it than I am.

      Glad you did post about it (and that Chris McDowall started posting some of his experiments in this field) otherwise I wouldn't have thought of doing it.

      Delete
  3. I used your random encounter prompts to generate some responses. It's remarkable how good the model is with context.

    * A man - bearded, road-worn and worried-looking - strides forwards, hunched forward under the weight of a heavy sack. He stops, and stands, panting, raggedy leather satchel slumped against his leg. The stranger looks at the PCs, then at his own hands. He shakes his head slowly, then yanks the sack open suddenly, revealing a swarm of bees. The stranger is trying to shake off a curse: every time he opens his mouth, bees fly out. 2d6 bees will escape each round as the stranger speaks; anyone within 10 feet of the stranger when they open or close their mouth will take 1d3 points of piercing damage as the bees sting them.

    * A clattering and squeaking noise is heard in the distance, growing louder as an odd machine comes into view. The machine is a wooden contraption, powered by a large waterwheel, with a series of cranks, cogs and levers. It is being driven by a stooped, bearded man in a leather apron, who is surrounded by a cloud of steam and soot. If the PCs approach, the man will introduce himself as Grendel, and explain that he is a travelling inventor. He is selling his latest invention - a mechanical man, which he has christened “Grendel’s Automaton”. The Automaton is a large wooden figure, roughly man-shaped, with a series of pipes, cogs and pistons inside. It is powered by a fire, which Grendel stokes with a bellows. The Automaton can be bought for 500GP, and can be used to perform simple tasks, such as lifting heavy objects or fetching water. However, the Automaton is prone to malfunctioning, and has a 50% chance of exploding if used improperly.

    * Three small humanoid beings, each with the head of a rat, are gathered around a small fire, roasting a rat on a spit. They look up at the PCs, and invite them to sit down and join them for dinner. These are the Rat-men of the Rat-Sultanate of Varn, a small kingdom to the east. The Rat-men are peaceful, and will share their dinner with the PCs (although it tastes of rat), and give them gifts of 3d6 copper pieces, a small knife, and a scrap of map showing the way to the Rat-Sultanate.

    * A lone figure approaches, mounted on a donkey. This figure is a young woman, no more than 18 years old, with long black hair and dark eyes. She is wearing a simple dress of white linen, and a cloak of red velvet. She is carrying a small bundle, wrapped in brown paper. This is Alia, a young woman who is running away from home. She is fleeing an arranged marriage to a man she does not love. She will not speak of her homeland, or her family. If the PCs offer to escort her to the nearest town, she will agree, but she will be constantly looking over her shoulder, as if she is being followed.

    ReplyDelete
    Replies
    1. Wow, those are wonderful, especially the first two. Even though I know that the are computer-generated, it makes me feel as though they've been stolen from somewhere. Although it's slightly revealing that the repetition, which usually makes the encounter more coherent (e.g the repeated references to mechanical parts in Grendel's description) sometimes throws up peculiar results (rat-men eating rats, chai offering chai-lined cloaks)

      Delete