Proposal

advertisement
Evolution of a Grand Adventure
A Genetic Algorithm Application in Interactive Fiction
By:
Ryen Wilkins
Adviser:
Dr. David Shaffer
Abstract:
With this project, a venture is made into finding out if a genetic algorithm can be
used to see noticeable results in creating a world in interactive fiction that will appear to
adapt to the player and their actions and decisions. The hope is to find that through the use
of genetic algorithms an author of interactive fiction can create a story/world that is more
personalized to the player to create both a challenging and more fun experience for the
player.
1
Introduction:
When approaching an idea for a capstone project I was holding my passion for video
games in the back of my mind. I wanted to implement a genetic algorithm, as well, and so I
began to brain storm possible ways to integrate the two together. I came up with an idea to
use a genetic algorithm in a RPG style game in order to evolve the enemies in areas to the
player’s play style and thus create a greater challenge for the player. This would allow what
are usually mundane areas to take shape and keep a player there longer.
While working on this idea, though, another idea and “platform” was brought to my
attention: implementing a genetic algorithm in interactive fiction. This is the route I have
chosen to take. In many ways interactive fiction is similar to playing a video game and there
has been no implementation of a genetic algorithm anywhere in interactive fiction as far as I
could find.
I have decided to go this route because the overall idea seems more interesting and
appealing to me and less similar to things already done in games which use different
methods. There is a lot of room for making this something innovative, or at least generally
different, in the area of interactive fiction and my hope is to create a system that provides
both a really cool concept and a lot of fun for the reader.
Project Description:
The project to be implemented with my capstone is to investigate the application of
genetic algorithms in the interactive fiction medium to create an enjoyable and changing
experience for the reader. The genetic algorithm will need to be applied in a way that leads
the reader to believe the world is changing around them in some way to fit the way they
have been “playing” the story. This would present readers with the promise of varied
experience through different plays/reads of the interactive fiction work.
2
By implementing genetic algorithms, additional depth can be added to interactive
fiction that currently seems to be absent in the medium. Such depth could potentially
broaden the appeal of the medium or at least make for a more enjoyable experience in
general for readers.
Genetic Algorithms:
Genetic algorithms began under the title “machine evolution” and saw very little
success in their implementation. Since that time, they have gained the new title of genetic
algorithm (GA) and have seen higher levels of success [5 - pg. 21]. A genetic algorithm can be
defined as “a variant of stochastic beam search in which successor states are generated by
combining two parent states rather than by modifying a single state.” A difference between
genetic algorithms and stochastic beam search is that in genetic algorithms reproduction is
akin to a sexual rather than an asexual form, as is seen in stochastic beam search [5 - pg. 126].
When putting a genetic algorithm together, the genetic algorithm will start off with a
group of pre-determined number of states (or individuals) called a population [5 - pg. 127].
Each individual is represented as a series of finite bit strings or digits (though the two can
behave in different ways) [5 - pg. 127].
In order to create a subsequent generation of the population to work with, a fitness
function is used to evaluate the individuals in the population. This function returns greater
values for individuals that perform the best and lower values for individuals that perform
poorly. Those individuals who have performed best will then be randomly selected to mate
with one another and produce sets of individuals for the next generation of individuals [5 pg. 127].
After selection of the individuals has taken place and the reproduction is set to begin,
crossover is performed. A random position in the string is chosen called the crossover point.
The digits before the crossover point from the first parent are combined with the digits after
3
the crossover point from the second parent. The combination is then the child of those two
parents [5 - pg. 128]. A second child is created using the same method on a new set of
parents, and the pattern is continued for as long as desired to create as many children as
needed.
The final stage of the algorithm is called mutation. At every location on the string for
each individual that will move on/be born into the next generation, a very small random
chance exists that the value can be mutated into another value [5 - pg.128].
Definitions Relevant to Interactive Fiction:
Author: The programmer coding and “authoring” the story. It is up to the author to create a
world for a reader to experience and move through.
PC (Player Character): The PC is the player controlled character - the character through
which the player is going to experience, and “play” through, the story. The PC can be a predetermined character that the player takes control of in the story. The player is then limited
to behave in a manner characteristic of the player they are given. Alternatively, the reader
can be provided near limitless customization of their character (name, gender, height,
weight, etc.).
NPC (Non-Player Character): A non-player character is any character within the story that
the player will encounter that they do not control. NPCs can be used for things as basic as
place holders to add to the story (where they may just repeat a few lines of information, say
describing a city). On the opposite spectrum, NPCs can be pivotal to the player’s success. The
player might be required to perform some quest or action for the NPC in order to progress
the story.
4
World: The world is the setting in which the story takes place. It can be as diverse and varied
as is the programmer’s/author’s imagination.
Interactive Fiction:
Wikipedia provides the following general definition of Interactive Fiction (IF):
“software simulating environments in which players use text commands to control
characters and influence the environment. Works in this form can be understood as
literary narratives and as video games. In common usage, the term refers to text
adventures, a type of adventure game where the entire interface can be "text-only".”
[7]
As with any novel, IF comes in all different genre styles ranging from horror to sci-fi to
modern day romance. In addition, IF can vary by how it allows the player to play out the
story. One style of story is a choose-your-own-adventure style where the player comes across
points in the story that present them with choices. Each choice leads the player down a
different path through the story and leads to different endings. There are more open-ended
stories, as well. In these, a player wanders around the land as they see fit. The objective may
or may not be clear and the player will need to be resourceful to find objects, NPCS and/or
places to help them progress the story. They may also be given a number of choices that they
can make and “test-out” at pre-defined locations/situations, such as in the work “First Draft
of the Revolution” by Emily Short [6].
The author of an IF has two responsibilities: They must choose a software
tool/environment under which to program their story and then they must make use of that
environment for writing their story in accordance with the language associated with it.
A well written IF has great potential to immerse the reader into its world and allow
them to feel like they are a part of it. Being able to then implement a system into that world
to create a better experience for a reader is a major goal of the project.
5
Genetic Algorithms in “Games”:
There appears to be little previous work with genetic algorithms and IF. One example
that relates genetic algorithms with interactive fiction is a system called HEFTI (Hybrid
Evolutionary-Fuzzy Time-based Interactive) created by TeongJoo Ong and John Leggett from
Texas A&M University. HEFTI uses a genetic algorithm to directly build a story rather than
being used to shape certain elements in the story itself [4].
Chen, et al. [2] use of genetic algorithms and other means, like Probabilistic
Incremental Program Evolution (PIPE) and a Cooperative Coevolutionary Algorithm
(CCEA), to test a way of balancing game mechanics and abilities in massively multiplayer
online role-playing games (MMORPGS) is another example. Their results indicate their
methods are successful and that the other methods perform better than a simple genetic
algorithm.
The closest research to the goals of the project can be found in [3], where the author
talks about using a genetic algorithm to adapt enemies to a player. The idea is to have a
dungeon in which the monsters “remember” what happens in battle, providing they can
escape. They then leave the battle and go tell the other monsters about what happened. This
allows the monsters to adapt to the player’s strategies to take advantage of their weaknesses.
While not a pure genetic algorithm, the idea has similarities to the ideas presented by a
genetic algorithm. It is not clear if the author actually implemented this algorithm into a
game, though.
Proposed Project:
In order to combine the use of a genetic algorithm with interactive fiction I’ve had to
come up with a way that it makes sense and can be properly applied. The idea that has come
to fruition is to use genetic algorithms in shaping the way certain NPCs interact with the PC,
6
specifically, pitting the PC to play different games against the NPCs in which an algorithm
will be used to have future NPCs learn from prior encounters and become more difficult to
play against. This will create a greater challenge for the reader and it will also create a sort of
feeling that the world around is adapting.
The games will vary to keep the reader from continually playing the same one over
and over again through the story, but one game will be chosen in particular to occur more
often and be used in a sort of final battle against a boss needed to be defeated to complete the
story.
Story:
In order to keep a reader’s attention, rather than just having them see how the genetic
algorithm works out in the story, a compelling and desirable story and world will be
implemented. The reader will take control of, and see through the eyes of, an aspiring
mage/wizard. In the beginning of the story the PC may not yet have magical powers and will
have to go through a trial or two to obtain them/learn them. This will be an initial place for
the use of the genetic algorithm.
The PC may have to escape from a dungeon or travel through a dark forest to a secret
temple to find their way to obtaining the powers they seek to master. The exact details are
not yet formed but upon finding these powers the reader will be introduced to the main
game of the story, Waving Hands created by Richard Bartle, which will be described shortly.
This scenario will put the player through a sort of tutorial to get used to how the game
works/is played since it could very well be overwhelming for a first time player.
Some time close to when the player gains control of their magical powers the reader
will be introduced to the main quest of the story, or at least some direction that will lead
them towards discovering the main quest. The PC will travel the world abound to improve
their skills and eventually face off against either a dark wizard that needs to be defeated to
7
save the world or a powerful, noted wizard in order to gain access into the Wizard’s
Association and gain use of the Wizard’s Tower.
Waving Hands:
Andrew Buchanan describes “Waving Hands” as: “… a game concerning the
imaginary conflict between two powerful wizards in a duel of sorcery” [1]. To implement it into
my story, it will be used with the basis that the combatants in game are actual wizards fighting
one another, as opposed to just playing the game in the story. To explain, the game is played out
in a sequence of turns; every turn both players write down a motion (simplified to a single letter)
that they will make with each hand, such that they can make two gestures each turn. To cast
spells the players must string together a series of motions over several turns in accordance with
predefined motions for spells.
Five single-hand motions exist:
- The wiggled fingers (F)
- The proferred palm (P)
- The snap (S)
- The wave (W)
- The digit pointing (D)
There is also a move that requires both hands: Clap (C) and two non-gestures: stab (stab) and
nothing ( ). The goal of the game is to cause 15 or more points of damage to the opponent
(killing them) or to cause them to surrender by putting up two Ps in one turn. The real trick to the
game is that you can combine series of gestures to cast multiple spells. For example, if one spell
would use FFPS and another spell would use PSWD then you would only have to go through 6
turns putting out FFPSWD on one hand to cast those two spells. There’s a great level of strategy
involved with the game as the player has to be able to take advantage of openings you see in
your opponents strategy and sequence as well as try to be able to respond to attacks from your
opponent with defensive spells.
The spells used fall under several categories: Protection, Summoning, Damaging and
Enchantment. Effectively being able to string together and combine all of the different types of
8
spells creates a challenging and thought-requiring game for the reader to partake in and also fits
perfectly into the story of the game, bringing the two together as a coherent idea that makes
sense. Such a game as this probably wouldn’t be used if the player were to be a fighter instead,
but since they are a mage the game will hopefully create a fun challenge for the player to master.
Implementation of Genetic Algorithm:
The genetic algorithm will play a major part in shaping the way the world reacts to
the PC. It will allow the reader to feel like the world is reasonably adapting to the actions of
their PC. With this in mind, it would be difficult, tiresome and overbearing to have the
reader play against hundreds to thousands of opponents at each game in order to correctly
evolve the opponents. For this reason, some liberties and background work will be done in
order to make use of a genetic algorithm without forcing the reader into the “mundane” task
of being a test puppet.
In order to accomplish the feat of using a genetic algorithm without requiring vast
amounts of tests to be completed by the reader, 100s of background tests will be run for each
of the reader’s single actions. The idea is to have the reader’s PC up against an NPC and the
reader will make a decision for their first move and the first move made by the NPC will be
randomly chosen. After this point, though, the genetic algorithm will run in the background
comparing the previous move (initially the player’s first move) up against a selection of
versions of that one NPC that would have randomly chosen different actions for their first
move. The results would then be compared using the fitness function and so the next move
made by the NPC would be based on the PC’s first move. This would continue on with each
move made by the PC evolving the NPC through a large number of generations.
To make this clear I will use an example as if the PC is playing rock-paper-scissors
against an NPC:
1st round: The PC chooses paper and the NPC randomly selects rock.
9
- The PC wins this first round and the genetic algorithm now pits paper against
hundreds of other copies of that NPC who choose randomly. Those copies who randomly
choose scissors will receive the highest score and those who choose paper will be in the
middle, while those who choose rock will receive a 0. The NPCs second choice will now be
weighted based on these values so the NPC will be more likely to choose scissors, somewhat
more likely to choose paper and less likely to choose rock.
This system will play out until either the PC or the NPC win the match. When the
match is over the data gained won’t disappear, though. There is a chance that the game will
appear again later on in the story and the new NPC will have heard of the exploits and
tactics of the PC through word of mouth or reconnaissance and will thus start off at a skill
similar to what the previous NPC had just started getting to. The nature of games that will be
created will prevent a genetic algorithm from creating NPCs that are impossible to beat but
will hopefully see results indicating that the NPC does efficiently adapt to the PC and create
a greater challenge; creating a belief that the NPCs in the world are aware of the PC and
their actions and skill.
An alternative method will be to create a probability chart of each move for the
player and use that to randomly choose a move the player makes for each generation of the
NPCs. As the story progresses the probability chart will continue to be edited with updated
probabilities. This will hopefully allow for a more dynamic adaptation of the NPCs.
Language/Software Used:
Authors of IF have many different languages they can choose from. One example is
Inform, which is described on its own site as
“a design system for interactive fiction based on natural language. It is a radical
reinvention of the way interactive fiction is designed, guided by contemporary work
10
in semantics and by the practical experience of some of the world’s best-known
writers of IF” [8].
An interesting aspect of Inform is that the source code generally looks like English and is
thus more accessible to people who would be considered non-programmers. However,
programming a genetic algorithm in such a language could prove very difficult.
A better choice is TADS, specifically TADS 3 (the newest version of the language).
TADS is advertised as such on the Tads website:
“TADS is the programmer’s power tool for IF authoring. It offers a robust and modern
language that’ll be instantly familiar to anyone who knows Javascript or C++, and a fullfeatured suite of development tools from text editing to debugging.”[9]
Having experience in C++ and looking through some examples of the source code, I deduced
that it could allow me to accomplish my goals and be relatively easy to pick up and become
accustomed to
TADS 3 has features which will allow for an efficient implementation of genetic
algorithms and also allow room for customization and extra features. TADS 3 includes a
dynamic complier which will allows the creation of a more project specific library. TADS 3 also
allows for the ability to program a story to be read/played over the Internet, rather than having to
download the software [9].
11
Timeline:
October 16 – November 5
Become accustomed to TADS 3 language. Make a short story or two and gain good
grounding in knowledge of how to build a story.
November 6 - 12
Attempt a proof of concept on a single game to determine if any effects can be seen
through the use of a genetic algorithm before advancing on with a full implementation.
November 13 – December 3
Develop full-fledged story and come up with detailed list of games and
implementations into story.
December 4 – January 7
Begin full implementation of genetic algorithm in story.
January 8 – February 4
Fine-tune and debug any issues that arise with the genetic algorithm.
February 5 – March 4
Begin intensive testing with multiple users to determine if effects are noticeable to a
broad audience
March 5 – Presentations
Fine tune any remaining issues and problems and examine data to determine final
result of implementation.
12
Works Cited:
[1] Buchanan, Andrew. “Waving Hands from Duel Purpose”. 3 March 1993. Edited by
Ken Tidwell, 9 April 1994. Web. 16 Oct. 2012.
http://www.gamecabinet.com/rules/WavingHands.html
[2] Chen, Haoyang, Ikuo Matsuba and Yasukuni Mori. Solving the Balance Problem of
On-Line Role-Playing Games Using Evolutionary Algorithms. 22 June 2012. PDF.
Journal of Software Engineering and Applications, 2012. 16 Oct. 2012.
[3] “Game AI, or Do Game AI’s Feel pain?” 10 Nov. 2007. Web-Blog. 16 Oct. 2012.
http://www.oddco.ca/zeroth/zblog/category/genetic-algorithms/
[4] Leggett, John and TeongJoo Ong. A Genetic Algorithm Approach to Interactive
Narrative Generation. Web – Powerpoint. 16 Oct. 2012
http://www.powershow.com/view/9d63cODNhY/A_Genetic_Algorithm_Approach_To_Interactive_Narrative_Generation_powerpoi
nt_ppt_presentation
[5] Norvig, Peter, Stuart J. Russel, et al. Artifical Intelligence: A Modern Approach. 3rd ed.
New Jersey: Upper Saddle River, 2010. Print.
[6] Short, Emily. First Draft of the Revolution Released. Word Press. 24 Sep. 2012. Web.
16 Oct. 2012. http://emshort.wordpress.com/
[7] http://en.wikipedia.org/wiki/Interactive_fiction
[8] http://inform7.com/
[9] http://www.tads.org/index.htm
13
Download