feature Creativity In Code: Generating rules for video games Mediums such as fine art and poetry are common subjects in computational creativity—but what about something closer to home? Can computers be as creative in programming as they are in poetry?

By Michael Cook DOI: 10.1145/2460436.2460449

omputational creativity research is littered with work in various high-culture domains: fine art, poetry, musical composition, and more. Both the general public and researchers themselves are fascinated by questions of aesthetics, whether machines can evoke emotion from us, and whether there is anything that sets Shakespeare Capart from Siri. Away from the arts lies an equally challenging medium, however; one that thousands of creative people engage with every day, and one that lies closer to computational creativity than any other—programming languages themselves.

Many areas of computer science leveraged for personal creative expres- BAFTA-award winning Journey (see have already tried to tackle the prob- sion. The popularity of the Java-based Figure 1), or the taut depiction of war lem of programs that write programs. processing environment among artists in Spec Ops: The Line, we can also see Some subfields of artificial intelligence and designers is a good example of this. evidence that games are becoming an ex- grew out of kinds of program genera- The popularity of projects like Code pressive medium on an individual level. tion, such as inductive logic program- Year and Codecademy demonstrates Designer and critic Anna Anthropy ming or neural networks. In software the general public’s desire to under- calls for exactly this in her book Rise of engineering many optimization and stand the world of data and code and the Videogame Zinesters: “[the] transmis- abstraction techniques involve code reflects the increasingly prominent role sion of ideas and culture from person to that can “unroll” or automatically se- of programming in modern society. person, as personal artifacts instead of lect code templates for expansion. Perhaps the clearest example of pro- impersonal creations by teams of forty- However, none of these applications gramming being used as a medium five artists and fifteen programmers.” fully appreciate programming as a cre- for creative expression is that of video If we are to tackle code generation ative endeavor. games. Gaming has risen from being from the perspective of computational In his book Creative Code: Aesthet- an idle distraction to a major creative creativity, and to try and understand ics and Computation, John Maeda de- medium, now occupying a broad spec- how software can write software not scribes programming as “not a tool trum from pure entertainment on for purely functional ends but for cre- [but] a new material for expression.” one end to meaningful artistry on the ative ones, video games seem a fine We can see this to be true, program- other. While mainstream gaming now place to start. Their innate interactiv- ming is not merely a means for getting includes complex works such as the ity lends itself well to evaluation; their things done, but increasingly is being religious pilgrimage depicted in the popularity ensures we are never lost for

40 XRDS • summer 2013 • Vol.19 • No.4 contemporary human-authored com- mechanic design, such as the Experi- initely well motivated, but how do we parators (or willing survey participants mental Gameplay Project. get software to write software? What for that matter); and their interrelated- So we know game mechanics are would a mechanic-inventing computer ness with graphical, audio, and cultur- important to people, and building sys- program look like? al content makes them a fascinating tems that can write new ones could For the last few years, I’ve been crucible of artistic mediums, all bound offer exciting new technology to the building a piece of software called up in this central medium: code. games industry. We also know it’s a ANGELINA (A Novel, Game-Evolving But where do we start? If we want to great way to test out new ideas about Labrat I’ve Named ANGELINA). ANGE- begin an investigation into how com- generating program code for creative LINA uses computational evolution to puters can write program code creative- means; because video games are huge produce game elements like level de- ly, which part of a should we programs at their heart, but they also signs, or powerups, and by simulta- begin with? Anna Anthropy sums it up express really creative ideas. We’re def- neously evolving these smaller game best when she describes games as “an components it can design an entire experience created by rules.” To build game, with each component designed systems that engage with the heart of a to fit in with all the others. This modu- video game, we must start with the rules Games are filled lar design has had lots of advantages, that build the game’s inner systems. one of which is that it’s easy to de- There are many different types of with rules, including velop new components over time and rule within games, but by far the most game mechanics, add them into the process. Late last interesting are the rules that govern year, I worked on a brand new compo- what we, the player, are allowed to do. which convey nent called Mechanic Miner that de- These rules, or game mechanics, are experiences on signs game mechanics by changing a the laws that decide what happens game’s program code. when you press X, and what numbers the player. Not just Mechanic Miner performs a three- go up or down when you land on that big experiences stage process. First, it generates game flashing spike over there. Major inter- mechanics by looking at program code. national games industry awards rec- like feeling sad Then, it evaluates the best mechanics ognize innovation in game mechanics, or triumphant, that it finds. Finally, it designs levels like the Independent Games Festival’s that use the new mechanic in their Nuovo Award, and lots of game design but little pockets solution. Although currently operat- events center around unusual game of micro meaning. ing on a small scale, Mechanic Miner’s

XRDS • summer 2013 • Vol.19 • No.4 41 feature

new parts of the level, or until it reach- Figure 1. Journey is an independently-developed award-winning game about es the exit (whichever comes first). If pilgrimage, co-operation, and humanity—and great evidence that games are we do this with the standard template becoming culturally important. game, it’ll tell us it’s not possible. Since we know the level isn’t solv- able using the normal game code, we can make small changes to the game and then record what changes in the solution. So if Mechanic Miner adds one of its generated game mechan- ics, and then discovers that it can reach new areas or complete the lev- el, it knows the new mechanic added something to the game. This black- and-white evaluation technique lets Mechanic Miner evaluate game me- chanics without needing extra infor- mation about how to use the mechanic or what the mechanic does—it keeps trying to use any buttons available to it techniques are general enough to ex- ducts an experiment. Figure 2 is a basic until it reaches the exit, or gets stuck. tend to a wide variety of applications template of a level from a Super Mario- This technique gives such clear and scales, and its integration into like game. Imagine you were the player feedback on how useful a mechanic is ANGELINA will let us explore these trying to get to the exit, you might no- that even with a complex problem like through the project in future research. tice that it’s impossible; Mario can’t code modification Mechanic Miner is To generate new game mechanics, jump high enough to clear the wall in still able to generate and identify use- Mechanic Miner first takes the code the middle of the level. This is the exact ful game mechanics out of thousands for a complete game written in Java. level that Mechanic Miner used in our of potential game variables. Examples For our purposes we use a Java port prototype work to evaluate game me- of game mechanics generated by the of the popular Flixel game library (the chanics. By outfitting Mechanic Miner system include the ability to flip grav- origin of which was the iPhone and with the ability to execute and play the ity upside-down (as seen in the indie online hit game Canabalt), and a basic game, we can ask it to try “solving” this platformer VVVVVV) and to make template with the bare platform level by trying every combina- the player’s character bounce off the basics of moving and jumping. In order tion of moves until it can’t reach any ceiling and floor (similar to ideas in to simplify the design problem for this prototype system, Mechanic Miner currently generates a very specific Figure 2. A basic template level used by Mechanic Miner to test mechanics out type of game mechanic—one that tog- for usability. The player, as Santa, must somehow get to the present. gles between two states each time a but- ton is pressed. Mechanic Miner search- es for variables in the game’s code, and then applies a randomly selected modifier to it, such as addition, sub- traction, or inversion. For example, a generated game mechanic might double the player’s “currentHealth” variable when a button pressed. Most mechanics generated in this way won’t be as useful, of course. In reality, at this stage Mechanic Miner has no understanding of which variables it is choosing. Most of the mechanics it will generate will do nothing—and a good deal of them actually crash the game, by causing program errors and exceptions—so how do we sort the good ideas from the bad ones? Mechanic Miner tests game me-

chanics like any good scientist: It con- Figure 1 image courtesy of thatgamecompany.

42 XRDS • summer 2013 • Vol.19 • No.4 NightSky and Knytt Stories). To be able When we play games, we do not to find mechanics that humans have Programming is not engage directly with the program invented, even on such a small-scale merely a means for code that runs them. When we press experiment, is extremely encouraging. the jump button, we see a character At this point Mechanic Miner can getting things done, animate on screen, and its position generate new game mechanics by look- but increasingly change as it launches itself up into the ing at a game’s program code, and it air. Behind the scenes, numbers are can test these mechanics by trying to is being leveraged changing and little else. We don’t per- use them to solve an impossible level. for personal ceive Mario as an image file with X/Y But there’s more we can get out of this coordinates and a velocity variable. We technique. Up until now, Mechanic creative expression. experience him as an Italian plumber Miner has generated lots of game me- who can jump and collect gold coins. chanics, and sorted the good from the Remember Anna Anthropy’s de- bad by testing them on a single level de- scription of games: “experiences cre- sign. We can turn this process around lots of interesting data through surveys ated by rules.” Games are filled with to generate level designs instead. Me- and game activity logs. We’ll be ana- rules, including game mechanics, chanic Miner can generate lots of po- lyzing this data to improve Mechanic which convey experiences on the play- tential game levels, and use a single Miner, and understand how people in- er. Not just big experiences like feeling game mechanic to test which levels teract with the game mechanics. sad or triumphant, but little pockets are good and which are bad. If we take Mechanic Miner is a very basic sys- of micro meaning. A Mario animation one of the mechanics invented by Me- tem for generating game mechanics moves up the screen, and we interpret chanic Miner, such as gravity flipping, and modifying program code, but it this as jumping. Mario touches an im- and start randomly generating levels, shows us what promising and exciting age of a mushroom, and it disappears we can test levels to see if they need the results we can get from even the sim- while Mario grows bigger. We interpret mechanic in their solution. First, we plest of systems. It also lets us think this as him eating it. We interpret Ma- play the level using the basic template about the next steps we could take to rio’s growth as an increase in strength. game. If we can’t solve it, we play it move this area of research forwards. This is drawing on a lifetime of experi- again with the new mechanic added in. Currently, the system only changes ence in the real world (and often, an ex- If that results in the game level being individual game variables. In order to perience of the unwritten vocabulary of solvable, then we can infer that we need really look at the question of software videogames) that ANGELINA does not the mechanic to complete the level. that writes software we would need to have right now. Of course, we can add in extra evalu- expand this to generate sequences of If we want to build software that ation criteria if we want, too. Perhaps expressions, create new objects in code, can create games autonomously, we want to design levels that have lots and modify existing program code too. right down to the level of code, then of danger in them, or that require long We should also aspire to more com- it seems that we will eventually need pathways to complete them, Mechanic plex output. While the game mechanics to find a way for software like ANGE- Miner uses a technique called compu- generated by Mechanic Miner are inter- LINA to understand this bridge be- tational evolution to produce level de- esting, they don’t match up to the vari- tween the game’s internal logic and signs and game mechanics. This allows ety and depth of mechanics in the av- the real-world concepts and experi- us to combine lots of different criteria erage game released today. Games like ences that those rules and systems into a single evaluation step. Using the Valve’s Portal 2 feature complex game represent. This bridging knowledge, solvability of a level as the central part mechanics that combine and comple- the translation between the game of its evaluation, however, lets Mechan- ment one another in interesting ways. world and the real world, will not ic Miner focus on designing levels that We’ll need to expand our evaluation come easily for computationally cre- require a certain mechanic to solve. techniques, to do more than just test ative systems. But the ability to do Levels and mechanics produced by black-and-white scenarios, in order to so will allow ANGELINA and systems Mechanic Miner made up the core of A get more interesting results out of this. like it to create games with genuine Puzzling Present, a game released on There’s also the thornier issue of meaning and artistic depth, and al- desktop platforms and the whether usefulness is a good way to low computational creativity to flour- store in December 2012. The game fea- evaluate game mechanics. Angry Birds’ ish within the games industry. tured three worlds, each with a unique catapult isn’t just a useful mechanic; it’s mechanic, and 10 levels in each that re- fun. It’s enjoyable to ping cartoon birds Biography quired the player to use the mechanic. across a map and knock things over. Michael Cook is a Ph.D. student at Imperial College’s Nearly 6,000 people played the game Mechanic Miner can detect usefulness Computational Creativity Group, researching techniques for automating the design of videogames. He holds an over the Christmas period, and it en- automatically, but fun is a very difficult M.Eng. in computing from Imperial College. Updates on his tered the Android games charts. This (and controversial) thing to formalize. research, published papers, and playable games made by his Ph.D. project ANGELINA can be found online at http:// was not only a rewarding opportunity For me, one question dominates www.gamesbyangelina.org. to see people interacting with our re- future work over all others—what do search, but we were also able to collect game mechanics mean to players? © 2013 ACM 1529-4972/13/06 $15.00

XRDS • summer 2013 • Vol.19 • No.4 43