{"id":8443,"date":"2018-03-07T14:48:33","date_gmt":"2018-03-07T14:48:33","guid":{"rendered":"http:\/\/rafaelfajardo.com\/portfolio\/so-you-want-to-build-a-generator\/"},"modified":"2018-03-07T14:48:33","modified_gmt":"2018-03-07T14:48:33","slug":"so-you-want-to-build-a-generator","status":"publish","type":"post","link":"https:\/\/rafaelfajardo.com\/portfolio\/so-you-want-to-build-a-generator\/","title":{"rendered":"So you want to build a generator&#8230;"},"content":{"rendered":"<p><a href=\"http:\/\/galaxykate0.tumblr.com\/post\/139774965871\/so-you-want-to-build-a-generator\" class=\"tumblr_blog\">galaxykate0<\/a>:<\/p>\n<blockquote>\n<p><figure class=\"tmblr-full\"><img decoding=\"async\" src=\"https:\/\/66.media.tumblr.com\/6204df41d3946a7fc33ea7f9d8a82dce\/tumblr_inline_pa2cun7ynY1qb76wj_540.png\" alt=\"image\" \/><\/figure>\n<\/p>\n<p>This is a beginner-level advice essay for people just getting started with building generators.  It\u2019s also for practiced experts who want a way to organize their knowledge.  The advice is meant for any kind of generators: humorous twitterbots, fanciful art-making bots, level generators, planet builders, makers of music, architecture, poetry, and cocktails. (edit: it turned out to be 4000 words long, so enjoy the ride!)<\/p>\n<p>With so many possible kinds of generators, what advice can I give? Any advice will depend on what <em>kind<\/em> of generator you want to build. I\u2019ll give you a list of <strong>questions<\/strong> to ask yourself, and advice to match the possible answers.<\/p>\n<p>The first question is:<br \/>\n<strong>What are you making?<\/strong><\/p>\n<p>Write down the <em>thing<\/em> that your generator will make. We\u2019ll refer to this as your \u201cartifact\u201d but it could be anything: procedural birds, generated stories, animated dance choreography, gazpacho recipes, RPG quests, chess variants.<\/p>\n<p>Now the hard part. Inhale, exhale, and start writing down everything you know about what makes one of those successful.  What qualities does a good one of those <em>artifacts<\/em> have?  \u201cFunny\u201d, \u201cHarmonic\u201d, \u201cPlayable\u201d? Now go deeper: the more specific the kind of thing you are making, the more specific and detailed you can get with these requirements.  What does a \u201cfun\u201d level mean? \u201cFun\u201d will mean very different things for Super Mario or Civilization or Bejeweled. I can come up with more properties of a <em>good paranormal regency romance novel<\/em> than I can come up with rules for a <em>good novel<\/em>.  <strong>The easiest generators to make are the ones where you can describe \u201cgood\u201d artifacts as sets concrete properties.<\/strong><\/p>\n<p>Now flip the question on its head: what makes a \u201cbad\u201d example of this artifact?  List everything you can think of, including properties that are merely unfortunate, and properties that are total deal-breakers.  Put a star next to anything that absolutely <em>must not happen<\/em>.  These are your <em>constraints<\/em>.  <strong>The most reliable generators are the ones where you can concretely describe constraints<\/strong>.<\/p>\n<p>You now have a list of desirable <strong>properties<\/strong> and <strong>constraints<\/strong> that you want and don\u2019t want for your artifacts.  We want a generator with a <em>possibility space<\/em> (all the kinds of artifacts it can generate) where most of the artifacts have the good properties, and few (or none) of the artifacts have bad properties.  We\u2019ll also want a <em>range<\/em> of artifacts, not just the same perfect artifact over and over and over, though how <em>wide<\/em> a range that is is a choice for you, the designer (a problem identified by <a href=\"https:\/\/games.soe.ucsc.edu\/sites\/default\/files\/smith-expressiverange-fdgpcg10.pdf\">Gillian Smith<\/a> and being explored by <a href=\"http:\/\/www.gamesbyangelina.org\/2016\/02\/introducing-danesh-part-1\/\">Michael Cook<\/a>).<\/p>\n<p>Now we have the guidance we need to start building <strong>methods<\/strong> that make artifacts.<\/p>\n<p>An alternative approach: the previously described method is good for inflexible situations, where you know ahead of time what you want to build.  For many situations, like game jams or prototypes or side projects, you can be more flexible and improvisational!  You can start with a methods or some loose pieces to figure out what it \u2018wants\u2019 to generate (what properties is it best at generating?) and then revising what artifacts you are generating to better suit what the generator is good at making.  I talk more about this approach in my <a href=\"https:\/\/www.youtube.com\/watch?v=s_eyo_m_hnc\">2015 Procjam talk<\/a>.<\/p>\n<figure class=\"tmblr-full\"><img decoding=\"async\" src=\"https:\/\/66.media.tumblr.com\/9b6da2e6390d26b49076efa16fb5c5b2\/tumblr_inline_pa2cuobEpU1qb76wj_540.png\" alt=\"image\" \/><\/figure>\n<\/p>\n<h2>Building Your Artist-in-a-Box<\/h2>\n<p>When the Spore editors were being designed, the engineers, designers worked closely with the art team to understand <em>how<\/em> an artist or an animator would go about sculpting and texturing a creature.  If they could understand the <em>process<\/em> and design an algorithm that could follow that process on demand, they would have an \u201cArtist-in-a-box\u201d that could make procedurally generated creatures that would be nearly as good as the original animator would have made.  Designer Chaim Gingold explained this process in his 2007 GDC talk <a href=\"http:\/\/www.gdcvault.com\/play\/527\/SPORE-s-Magic\">audio<\/a> <a href=\"http:\/\/levitylab.com\/cog\/presentations\/gdc07\/SporesMagicCrayonsPPT.zip\">slides<\/a> and Art Director Ocean Quigley used a similar process to experiment with what <a href=\"http:\/\/oceanquigley.blogspot.com\/2009\/04\/spore-early-rig-block-experiments.html\">kinds of building blocks he would want for building cities<\/a><\/p>\n<p>It is helpful when making a generator to sit down with someone who makes the sort of artifacts you are building, and have them walk you through the process of making something.  What questions do they ask themselves along the way?  How do they make decisions? How do they describe the tradeoffs between choices?  How do they describe the different problems that they have to keep in mind?  How do they name all the parts of what they are working on, and all the relationships between them? <em>(the academic term for this is an \u201contology\u201d)<\/em><\/p>\n<p>Some fields have expert practitioners who have written <em>frameworks<\/em>, often controversial, to describe what they do.  Music theory has proposed plenty of rule systems, for example, for jazz improvisation or Bach-style harmonies or pop songs.  Story generation has narratological theories like The Hero\u2019s Journey, but also informal frameworks like TV Tropes.  Art theory has the Golden Ratio and color harmonies and composition rules (I haven\u2019t found those visual aesthetic rules to be productive in my own work, though you may feel differently).  No framework is complete, or makes provable good artifacts, but they can help give you guidance and inspiration.<\/p>\n<p>So now, ask yourself: <strong>How would a human solve this problem?<\/strong><\/p>\n<figure class=\"tmblr-full\"><img decoding=\"async\" src=\"https:\/\/66.media.tumblr.com\/6bc7f7e49d40622be040420a9199bb20\/tumblr_inline_pa2cupyfH61qb76wj_540.png\" alt=\"image\" \/><\/figure>\n<\/p>\n<h2>From rules to generative methods<\/h2>\n<p>Unfortunately, knowing how a human would make something isn\u2019t the same as being able to teach a computer how to do it.  Humans are good at estimation, and making guesses, and synthesizing a lot of knowledge about past situations.  Computers know only what you tell them, and many problems require way more implicit knowledge than we think, but they <em>are<\/em> good at performing lots of calculations and trying out lots of possibilities.  So the methods we want to use will need to provide a way for the computer to solve problems <em>like<\/em> a human, or at least with a way to mirror some of the skills of a human.  Methods that are particularly good for building generators (<strong>generative methods<\/strong>) will give the computer some of the following skills:<\/p>\n<ul>\n<li>Encapsulate knowledge of options (skill A)<\/li>\n<li>Create some structure (skill B)<\/li>\n<li>Encode conditional rules for options (A2)<\/li>\n<li>Create variability in structure   (B2)<\/li>\n<li>Be able to ask itself questions about its constraints (have I solved this?) (skill C)<\/li>\n<\/ul>\n<p><strong>Distribution<\/strong><\/p>\n<p>This is the easiest kind of generative method.  You have a bag of <em>stuff<\/em> and an area of space or time that you can spread them out across.  Distribution methods usually don\u2019t have much overall structure (B), but they are often very sophisticated with the odds of picking each option (A).  Some use weighted randomness to change the distribution percentages, or &lsquo;deck shuffling\u2019 (putting all the options in a stack and discarding when they are used), which prevents accidentally picking the same option twice.  The conditional rules (A2) can get quite complex as well, but specifying <em>arbitrary<\/em> conditions is difficult to implement in practice. Most systems have carefully chosen parameters that can be set for each option and the conditional functions can just look compare the fixed parameters to make choices.<\/p>\n<p>For an RPG example, wandering monsters are distributed around the environment (A).  Higher monsters are found in higher level areas, water monsters in water, etc (A2). There may be a little structure to how they are distributed, like several &#8216;baby\u2019 versions of a monster leading up to the &#8216;boss\u2019 version.  Loot is also distributed: you may be more likely to get high level loot in high level situations (A2) but there\u2019s still some randomly selected stuff chosen from a big list of possible loots (A).<\/p>\n<p>Distribution in music and language doesn\u2019t work well.  Randomly selected strings of words or musical notes don\u2019t have enough structure to make interesting meaning.  For structure-heavy artifacts, you might want tile-based or grammar-based methods instead, or for something with very fixed structure and not much variability you could try the Parametric approach.<\/p>\n<figure class=\"tmblr-full\"><img decoding=\"async\" src=\"https:\/\/66.media.tumblr.com\/1fada67e75793cb0f71854809c108f03\/tumblr_inline_pa2cuph6JT1qb76wj_540.png\" alt=\"image\" \/><\/figure>\n<\/p>\n<p><strong>Parametric methods<\/strong><\/p>\n<p>You have a pretty well-built artifact already, and you know that you can <em>tweak<\/em> it a little.  You have music, and you can transpose it up or down, make it louder or softer.  You have a teapot, and you can make the spout curve out farther, you can make the body tall or short, thin or fat, and you can make the base wide or narrow.  You have a set of hand-made alien creatures, and you can tweak their legs to be long, fat, curved, or flat-footed, and their bellies to be slender or barrel-shaped, and this changes their voice as well. <a href=\"http:\/\/www.theatlantic.com\/technology\/archive\/2016\/02\/artificial-universe-no-mans-sky\/463308\/\">This is how creatures in \u201cNo Man\u2019s Sky\u201d are varied<\/a>.  This is a very reliable and controllable technology!  For 3D models, can often be encoded as a Maya animation channel, allowing it to blend with other animations (a Spore trick used in the rig-block animations).  But your variability (A) is only along fixed one-dimensional numerical paths, there is no structure variability at all (B2).  You can see something \u201cnew\u201d, but never something surprising.<\/p>\n<p>A more sophisticated form of parametric methods uses other forms of input, and can generate new artifacts based not only numerical, but also point-based, path-based and graph-based input.  When you draw a line in Photoshop with a tablet pen, your path becomes the input to an algorithm that renders a brushstroke, taking into account pressure, speed, and tilt as parameters at each point.  The Spore creatures, likewise, used Metaballs, a geometry creation algorithm that could create smooth tubes along paths in 3D space.  Other algorithms for filling spaces and paths are Voronoi patterns, Perlin\/Simplex noise, triangulation algorithms, 3D extrusion or rotation, and the Diamond-square algorithm for fractal terrain.   <strong>These algorithms are particularly well-suited for interactive generators, because the user can provide the input parameters for the generator.<\/strong><\/p>\n<p>Want more? <a href=\"http:\/\/inconvergent.net\/\">Inconvergent.net<\/a> has more intriguing specimens of these than you could possibly ever need, with open-source implementations.<\/p>\n<p>However, though these algorithms are delightfully surprising, they can often be too uncontrollable to provide the constraint-satisfaction needed for gameplay or other highly-constrained artifacts.<\/p>\n<p><strong>Tile-based<\/strong><\/p>\n<p>Chop the problem up into modular, identically-sized slots.  Have a number of different hand-made solutions that can fill in these slots.  The artifacts being created are just differently-selected-or-ordered sets of pre-authored solutions.  A familiar example of this is the board layout for games like Settlers of Catan and Betrayal at the House on the Hill (or Civilization for a digital example).  The island, and the mansion, are constructed from the same tiles each time, but laid out differently, which changes the gameplay.  Some of the earliest forms of generative content I\u2019ve found are the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Musikalisches_W%C3%BCrfelspiel\">Musikalisches W\u00fcrfelspiel<\/a> from 1750s and earlier, with which pianists could put together \u201ctiles\u201d (in this case: measures) of music to produce a playable waltz.<\/p>\n<p>Tile-based methods are great for small-scale structure (B) because the insides of the tile are pre-authored, but they have no flexibility (B2) for small-scale structure for the same reason.  Large scale structure is harder to control: it can be totally random. There can be more advanced constraints about which tiles can go next to other tiles but then you may need a complex algorithm to solve for compatible layouts of highly-constrained tiles (\u201cThe beach tile can go next to a jungle tile, but cannot be within two tiles of a river tile and\u2026..\u201d).  Individual tiles have a very rigid encapsulation of possible options (A), because each possible tile has to be authored by a human.  These systems don\u2019t have enough knowledge to come up with good new tiles by themselves.  <strong>Tile-based methods work for problems that can be broken-up into small chunks where internal structure matters, but that can still create interesting (but not constraint-breaking) behavior when combined in different orders.<\/strong><\/p>\n<p>Interested in more analog content generation? Additional forms of boardgame and role-playing-game content generation <a href=\"http:\/\/sokath.com\/main\/files\/1\/smith-fdg15.pdf\">can be found in this paper by Gillian Smith<\/a>, and this <a href=\"http:\/\/lambdamaphone.blogspot.com\/2015\/12\/generativity-interpretation-study-of.html\">exploration of comics by Chris Martens<\/a><\/p>\n<figure class=\"tmblr-full\"><img decoding=\"async\" src=\"https:\/\/66.media.tumblr.com\/9b9414851e4ff1ed51d041c0648cb1e2\/tumblr_inline_pa2cuqfpYy1qb76wj_540.png\" alt=\"image\" \/><\/figure>\n<\/p>\n<p><strong>Grammars<\/strong><\/p>\n<p>Grammars are one of my favorite generative methods, because I find that they give me a great way to make very deep and complicated structures while still also having a lot of control over my options.  Grammars are a computer-sciency way of saying that big complex things are made out of other things, and those other things may themselves be made out of even smaller simpler things.  Orteil\u2019s <a href=\"http:\/\/orteil.dashnet.org\/nested\">Nested<\/a> is a lovely example of this.  The universe is made of galaxies made of planets made of continents full of people who are full of thoughts and dreams and memories and atoms.  Each symbol (that is, a type of thing) has a distribution of sub-symbols that it might be composed of.  When it \u201cunpacks\u201d it has to pick one of those options (and any subsymbols then unpack recursively).  <strong>Grammars make it easy to encode knowledge about a particular artifact and its structure and its options all in one piece of data.<\/strong>  I like them so much I made a library to help people work with them, <a href=\"https:\/\/github.com\/galaxykate\/tracery\/tree\/tracery2\">Tracery<\/a>.  This has been used to make a <a href=\"http:\/\/cheapbotsdonequick.com\/\">twitterbot hosting service<\/a> and lots of <a href=\"https:\/\/twitter.com\/thinkpiecebot\">great<\/a> <a href=\"https:\/\/twitter.com\/DUNSONnDRAGGAN\">weird<\/a> <a href=\"https:\/\/twitter.com\/thetinygallery\">creative<\/a> <a href=\"https:\/\/twitter.com\/HipsterCocktail\">twitterbots<\/a> including some of <a href=\"https:\/\/twitter.com\/alltartans\">my<\/a> <a href=\"https:\/\/twitter.com\/TinyAdv\">own<\/a>.<\/p>\n<p>The downside of grammars is that they do not have a way to handle constraints, unless the constraints are implicitly encoded in the grammars themselves (if a bed can only be in a house, than only the house can have a bed as a sub-child, for example). It\u2019s harder for grammars to encode high level relationships between different things generated at different points in the grammar. If you wanted to have foreshadowing of the villain\u2019s death at the very beginning of the grammar, that might be difficult to do, and you might want to use the &#8216;big hammer\u2019 of a constraint-solver.<\/p>\n<figure class=\"tmblr-full\"><img decoding=\"async\" src=\"https:\/\/66.media.tumblr.com\/f7e37499d80a0b77a7d1396847e7d61e\/tumblr_inline_pa2cuqRa4z1qb76wj_540.png\" alt=\"image\" \/><\/figure>\n<\/p>\n<p><strong>Constraint solvers<\/strong><\/p>\n<p>Constraint solvers are very powerful, very recent tools in our generative arsenal.  They are what you use when you have a lot of hard constraints, a lot of flexible and complex structure, but you don\u2019t know how to build out the structure in a way that will be <em>sure<\/em> to solve your constraints.<\/p>\n<p>The oldest simplest version of this is <strong>brute force solving<\/strong>. Make <em>every<\/em> possible variant of content, toggle every switch, make an alternative universe where you have made each different decision, and test your constraints until you find one that works.  This is a viable solution for some problems!  But as any mathematician will tell you, too many choices will create a number of possible artifacts to search that is greater than the number of atoms in the universe.  And that\u2019s going to be slow.<\/p>\n<p>There are often shortcuts you can take, depending on how your constraints are structured (I don\u2019t have to choose an ice-cream flavor in possible futures where I did not go out for ice cream).  But this takes a long time to author by hand (just ask the <a href=\"http:\/\/www.storyteller-game.com\/\">Storyteller<\/a> developer).<\/p>\n<p>Fortunately, many mathematicians and logicians find it amusing to try to solve this problem, and they have come up with <em>general purpose solvers<\/em>. Plug in your constraints and structure and options (in a language that it can understand) and it will find all the cheap shortcuts to cut the aeons of brute-force solver time down to something slow but accomplishable within normal gameplay time.<\/p>\n<p>Because these tools are big and bulky and new, they are still hard to plug into many game engines, and there aren\u2019t many tutorials.  <a href=\"https:\/\/eis-blog.soe.ucsc.edu\/2011\/10\/map-generation-speedrun\/\">Adam Smith has been doing good educational outreach for Answer Set Solving<\/a>, a particularly powerful one.  Another one with some support is <a href=\"https:\/\/github.com\/ianhorswill\/Craft\">Craft<\/a> by Ian Horswill, a constrained random number generator, that has been recently <a href=\"https:\/\/github.com\/relimited\/Craftjs\">ported to javascript<\/a>.  <strong>Look for these rare but powerful methods to be more common in the future!<\/strong><\/p>\n<p><strong>Agents and Simulations<\/strong><\/p>\n<p>This is where it gets weird.  Remember how I said that we could look at how humans solve problems to provide inspiration for our generators?<\/p>\n<p><strong>Guess what: humans aren\u2019t the only ones who solve problems<\/strong><\/p>\n<p>There are algorithms that solve problems based on the colonial behaviors of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Ant_colony_optimization_algorithms\" title=\"Ant-colony optimization\">ants<\/a>, or the social communications of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Firefly_algorithm\">fireflies<\/a>.  Many other agents and simulations take inspiration from other parts of nature, like flocks of birds, evolution, bacteria, neurons and cities.  Here are a few of my favorites, but there are many more.<\/p>\n<p><strong>Steering behaviors<\/strong> (these deserve their own long post some day) can create remarkably complex crowd motion. Braitenberg vehicles were originally a <a href=\"http:\/\/www1.appstate.edu\/~kms\/classes\/psy5150\/Documents\/Braitenberg1984.pdf\">thought experiment<\/a> about simple machines with two photosensitive eyes and two wheels that could &#8216;steer\u2019 themselves just by activating one wheel more than the other, applying an asymmetrical force that changes their direction.  Despite their total brainlessness, they can show &#8216;fear\u2019 and &#8216;adventure\u2019 and have been ported to <a href=\"https:\/\/github.com\/vinceallenvince\/Braitenberg-Vehicles\">many languages<\/a> and <a href=\"https:\/\/www.youtube.com\/watch?v=NJo5HEdq6y0\">physical robots<\/a>.<\/p>\n<p><a href=\"http:\/\/www.red3d.com\/cwr\/boids\/\">Boids<\/a> took the steering approach of the Braitenberg vehicles and applied it to flocks of birds and fish (and the wildebeest in the Lion King animated movie).  Each bird helps keeps its flock in shape by calculating applying its own forces for cohesion, alignment and separation. Small variations in the each birds\u2019s tuning values can generate new  behavior for the flock.<\/p>\n<p>I\u2019ve also used steering forces to <a href=\"http:\/\/www.galaxykate.com\/Apps\/Prototypes\/Dancer\/\">generate procedural dance<\/a>: you just replace the flocking forces with rhythmic forces in time to the music <a href=\"http:\/\/www.ccgworkshop.org\/wp-content\/uploads\/2015\/06\/CCGW2015_submission_9.pdf\">paper<\/a>.  Steering forces can do a lot more than pathfinding, but I don\u2019t think they haven\u2019t yet been explored to their full potential.<\/p>\n<figure class=\"tmblr-full\"><img decoding=\"async\" src=\"https:\/\/66.media.tumblr.com\/0b8305053fe440d39833b08414c5cefe\/tumblr_inline_pa2curLvyl1qb76wj_540.png\" alt=\"image\" \/><\/figure>\n<\/p>\n<p><strong>Genetic algorithms<\/strong>, as can be seen in <a href=\"http:\/\/www.galaxykate.com\/Apps\/Prototypes\/LTrees\/\">my flower-evolving app<\/a> aren\u2019t methods to generate content, you still need a generator (a flower generator in this case).  But they are a way to <em>guide<\/em> that generator towards more constraint-fulfilling and desirable-property-producing content. A genetic algorithm (which, yes, needs its own post), needs three things:<\/p>\n<ul>\n<li>A thing you can modify (a &#8216;genotype\u2019)<\/li>\n<li>A thing you can judge (a &#8216;phenotype\u2019)<\/li>\n<li>A way to turn the first into the second<\/li>\n<\/ul>\n<p>For the flowers, the genotype is an array of floats.  That array gets fed into a parametric generator to create a pretty animated flower (turning genotype to phenotype).  The user can see which flowers they like (a judgable phenotype).  They pick their favorite, it\u2019s original genotype is cloned and mutated (a thing you can modify, remember?) and the next generation is born from its mutant babies, and overtime, evolution happens.  Sexual reproduction is common in GAs, but so are many other interesting kinds of reproductions and metaheuristics.  There\u2019s a lot of neat research in this area!<\/p>\n<figure class=\"tmblr-full\"><img decoding=\"async\" src=\"https:\/\/66.media.tumblr.com\/fba22d9213302238ecd382e524d21d43\/tumblr_inline_pa2cusowvR1qb76wj_540.png\" alt=\"image\" \/><\/figure>\n<\/p>\n<p><strong>Cellular automata<\/strong> rely on many very simple agents, all working in parallel.  The canonical example of this is Conway\u2019s Game of Life, in which many tiny automata in a grid, each with a very simple behavior, can give rise to so many strange behaviors and phenomena that many mathematicians make a hobby of <a href=\"http:\/\/www.conwaylife.com\/wiki\/Main_Page\">discovering and cataloging them<\/a>.<\/p>\n<p>Cellular automata with more complex rules are used to create Dwarf Fortress, the classic <a href=\"http:\/\/dan-ball.jp\/en\/javagame\/dust\/\">Powder game<\/a>, and with the advent of voxel-based simulation, are taking on a new life as the engine behind <a href=\"http:\/\/0fps.net\/2012\/01\/14\/an-analysis-of-minecraft-like-engines\/\">Minecraft<\/a><\/p>\n<h2>After you generate\u2026<\/h2>\n<p>You\u2019ve browsed this list of generative methods, you\u2019ve got your list of constraints and properties in hand, and you\u2019ve built your generator!<\/p>\n<p>Now what?<\/p>\n<h2>Ways that generators fail<\/h2>\n<p>Something has gone horribly wrong.  The content looks ugly. The content all looks the same. The content looks like <a href=\"http:\/\/kotaku.com\/5017350\/when-spore-penis-monsters-attack\">genitalia<\/a>.  The content is broken.  Some of these problems are easier to solve than others. Here are a few kinds of difficult problems you will encounter.<\/p>\n<p>One will be the kind where you can <em>computationally identify<\/em> when something is going wrong.  The solution to this one is to generate some new content until this constraint is no longer violated.  Perhaps you want a generated chair to have its center of gravity over its support points (like legs), so it won\u2019t fall over.  This is possible to calculate with a physics simulation, so if the generated chair fails, generate a new one until it passes.  This approach is called <a href=\"https:\/\/www.itu.dk\/~yannakakis\/SB-PCG.pdf\">\u201cgenerate and test\u201d<\/a>.<\/p>\n<p><strong>What can go wrong with \u201cgenerate and test\u201d:<\/strong> what if every chair you generate fails this test?  Perhaps content that passes the test is very rare.  Or there are too many constraints, if you have constraints for  material thickness and cost and symmetry and comfort and more?  Each chair might satisfy most constraints, but with enough constraints, most chairs will still fail one or two.  Maybe you need a constraint solver.  Or maybe you need to restrict your generator so that it is more conservative with its choices, though that may lose interesting possibility space.<\/p>\n<p>Another difficult constraint is when you cannot adequately describe your constraints.  This is a remarkably common situation, because there are so many things that we don\u2019t want but can\u2019t write rules that \u201cI know it when I see it\u201d can be used as a serious legal argument.<\/p>\n<p>Is this an offensive adjective to use to describe this character?  Does this color palette look too much like a corporate logo? Does this look like genitalia? Is this just\u2026 ugly?  This is a hard and unsolved problem, I\u2019m afraid.  If you can\u2019t define \u201cbad\u201d content, it becomes impossible to filter, <a href=\"http:\/\/www.exquisitetweets.com\/tweets?eids=SOlZp2L8I8.SOl4CsO6YC.SOmhNAiuES.SOmlJ2T2Gq.SOmpjeGn1w.SOmwta15gX.SOmB4207kO.SOmJPgkOFU.SOmOl1j08a.SOmW0jPTRA.SOm72fKFfE.SOncwNl2SP.SOnlkgH05k.SOntnuAhGw.SOqg0uZR8K.SOqkXGJtbU.SOqrXBJruS\">especially when your human users are trying to get around the detection algorithm<\/a>.   In this case, the best path is to construct an generator such that it is <em>harder<\/em>  or less-likely to make offensive content.  This also restricts your possibility space, like removing words that are harmless and useful unless combined in a particular way.<\/p>\n<p><strong>Aesthetics: the toughest challenge<\/strong><\/p>\n<p>The most common way that generators fail is that they produce content that fails to be interesting.  What is \u201cinteresting\u201d?  That depends on the situation.  Very few generators produce only one of a thing.  Most generate multiples, but a twitterbot posting every hour will generate more content than a novel-generator outputing one novel every NaNoGenMo.  So achieving novelty with the first Twitterbot will be more difficult because there are so many artifacts being produced that any given one of them will probably start seeming less special.<\/p>\n<p>So your algorithm may generate 18,446,744,073,709,551,616 planets.  They may each be subtly different, but as they player is exploring them rapidly, will they be <em>perceived as different<\/em>?  I like to call this problem the <strong>10,000 Bowls of Oatmeal<\/strong> problem. I can easily generate 10,000 bowls of plain oatmeal, with each oat being in a different position and different orientation, and <em>mathematically speaking<\/em> they will all be completely unique.  But the user will likely just see <em>a lot of oatmeal<\/em>.  <strong>Perceptual uniqueness<\/strong> is the real metric, and it\u2019s darn tough.<\/p>\n<figure class=\"tmblr-full\"><img decoding=\"async\" src=\"https:\/\/66.media.tumblr.com\/7736ec1ba087d66c534d5b09b0908f4a\/tumblr_inline_pa2cusWXKN1qb76wj_540.png\" alt=\"image\" \/><\/figure>\n<\/p>\n<p>In some situations, just <strong>perceptual differentiation<\/strong> is enough, and an easier bar to clear.  Perceptual differentiation is the feeling that this piece of content is not identical to the last.  A user glancing at a line of trees can tell if they are identical, or if they are less-varied-than-expected suggesting unnaturalness.  This fulfills an aesthetic need even if no tree is particularly memorable.<\/p>\n<p><strong>Perceptual uniqueness<\/strong> is much more difficult.  It is the difference between being an actor being a face in a crowd scene and a <em>character<\/em> that is memorable.  Does each artifact have a distinct personality? That may be too much to ask, and too many for any user to remember distinctly.  Not everyone can be a main character. Instead many artifacts can drab background noise, highlighting the few <em>characterful<\/em> artifacts.<\/p>\n<p><em>Characterful<\/em> artifacts is another blog post for another time, but certain aesthetic principles create objects with <em>readable<\/em> meanings for human perception.  Humans seem to like perceiving evidence of process and forces, like the pushed up soil at the base of a tree, or the grass growing in the shelter of a gravestone.  These structurally-generated subtleties suggest to us that there is an alive world behind this object.  Kevin Lynch\u2019s influential <a href=\"https:\/\/mitpress.mit.edu\/books\/image-city\">\u201cImage of the City\u201d<\/a> demonstrates that there are factors that make cities memorable and describable.  Perhaps there are other aesthetic rules that we can discover, too.<\/p>\n<h2>Conclusions:<\/h2>\n<p>Oh, my, this turned into a monster of a blog post.  It\u2019s probably full of errors and omissions, but I hope it will be of use to you.<\/p>\n<p>If you want to begin playing with generativity right away, here are some great tools to get your feet wet:<\/p>\n<ul>\n<li><a href=\"http:\/\/cheapbotsdonequick.com\/\">http:\/\/cheapbotsdonequick.com\/<\/a>: the Tracery twitterbot maker, now with SVG supprt<\/li>\n<li><a href=\"http:\/\/www.contextfreeart.org\/\">http:\/\/www.contextfreeart.org\/<\/a><\/li>\n<li><a href=\"http:\/\/ncase.me\/simulating\/\">http:\/\/ncase.me\/simulating\/<\/a> Simulating the World in Emoji, a brilliant playground for emoji-based cellular automata<\/li>\n<\/ul>\n<p>Want to learn more? Or meet like-minded people?<\/p>\n<ul>\n<li>There\u2019s a <a href=\"http:\/\/pcgbook.com\/\">free online PCG textbook<\/a> written by the top academic researchers in generation for games<\/li>\n<li>I\u2019m absolutely in love with this <a href=\"http:\/\/natureofcode.com\/\">book by the brilliant Daniel Shiffman<\/a> that teaches Processing through the lens of nature\u2019s processes<\/li>\n<li>The <a href=\"http:\/\/ccg.doc.gold.ac.uk\/\">Computational Creativity Group at Goldsmiths<\/a> does extremely varied work in computational creativity, the practice of trying to make computers \u201ccreative\u201d.  <a href=\"https:\/\/www.youtube.com\/watch?v=ZT-bUTYwpao\">The International Conference on Computational Creativity<\/a> is a place where many of these people meet to share ideas.  Their past papers are a great resource on generating art, poetry, music, memes, and more!<\/li>\n<li>The <a href=\"https:\/\/games.soe.ucsc.edu\/eis\">Expressive Intelligence Studio<\/a> is my home at UCSC, where we work on AI for <em>expressive<\/em> purposes, not just problem solving.<\/li>\n<li><a href=\"http:\/\/www.foundationsofdigitalgames.org\/\">Foundations of Digital Games<\/a> is a yearly conference on experimental ideas about games, and has a Procedural Content workshop (and a new Crafts in Games workshop, too)<\/li>\n<li>Superstar academic\/gamemaker Michael Cook runs the <a href=\"https:\/\/itch.io\/jam\/procjam\">ProcJam<\/a>, an annual jam that features lectures and tutorials and tools.<\/li>\n<li>Darius Kazemi runs the <a href=\"https:\/\/github.com\/dariusk\/NaNoGenMo\">National Novel Generating Month<\/a>, a challenge to make a program that can write a whole book.  He also write a ton of bots, and writes a ton <a href=\"http:\/\/tinysubversions.com\/2013\/03\/basic-twitter-bot-etiquette\/\">about bots<\/a><\/li>\n<\/ul>\n<p>I\u2019ll be on Twitter, @galaxykate, to answer further questions, hear about typos, and take feedback<\/p>\n<figure class=\"tmblr-full\"><img decoding=\"async\" src=\"https:\/\/66.media.tumblr.com\/eee9c9dd743065c86d157e2980685025\/tumblr_inline_pa2cutoIDh1qb76wj_540.png\" alt=\"image\" \/><\/figure>\n<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>galaxykate0: This is a beginner-level advice essay for people just getting started with building generators. It\u2019s also for practiced experts who want a way to organize their knowledge. The advice is meant for any kind of generators: humorous twitterbots, fanciful art-making bots, level generators, planet builders, makers of music, architecture, poetry, and cocktails. (edit: it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[10],"tags":[],"class_list":["post-8443","post","type-post","status-publish","format-standard","hentry","category-words"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p6PWot-2cb","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/posts\/8443","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/comments?post=8443"}],"version-history":[{"count":0,"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/posts\/8443\/revisions"}],"wp:attachment":[{"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/media?parent=8443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/categories?post=8443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rafaelfajardo.com\/portfolio\/wp-json\/wp\/v2\/tags?post=8443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}