20
A Genetic Algorithm A Genetic Algorithm Approach To Approach To Interactive Narrative Interactive Narrative Generation Generation TeongJoo Ong and John TeongJoo Ong and John Leggett Leggett Texas A&M University Texas A&M University

A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

Embed Size (px)

Citation preview

Page 1: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

A Genetic Algorithm A Genetic Algorithm Approach ToApproach To

Interactive Narrative Interactive Narrative GenerationGeneration

TeongJoo Ong and John LeggettTeongJoo Ong and John Leggett

Texas A&M UniversityTexas A&M University

Page 2: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

IntroductionIntroduction

Stories are used to convey Stories are used to convey information, cultural values, and information, cultural values, and experiencesexperiences

New technologies have constantly New technologies have constantly provided increasingly sophisticated provided increasingly sophisticated means to tell storiesmeans to tell stories

Recent trend is the convergence of Recent trend is the convergence of technology, entertainment, and art technology, entertainment, and art in the computerin the computer

Page 3: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

BackgroundBackground

Interactive storytelling is a major Interactive storytelling is a major research arearesearch area

Many overlapping approaches have Many overlapping approaches have been used:been used:

AI community (Narrative intelligence):AI community (Narrative intelligence): Immersive storytellingImmersive storytelling Emergent storytellingEmergent storytelling Plot-based systemsPlot-based systems Interactive authoring of storiesInteractive authoring of stories Character-based systemsCharacter-based systems

Page 4: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

Background (cont.)Background (cont.)

Hypertext community:Hypertext community: Hypertext narrativesHypertext narratives Adaptive hypermediaAdaptive hypermedia Sculptural hypertextSculptural hypertext

Partial listing of related work from these Partial listing of related work from these areas:areas: CHOROS (N. M. CHOROS (N. M. Sgouros) Sgouros) Façade (M. Mataes, A. Stern)Façade (M. Mataes, A. Stern) Card Shark and Storyspace (M. Bernstein)Card Shark and Storyspace (M. Bernstein) Metalinear Cinematic Narrative (K.M. Metalinear Cinematic Narrative (K.M.

Brooks)Brooks) StoryBeads (B. Barry)StoryBeads (B. Barry)

Page 5: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

MotivationMotivation The HEFTI storytelling engine attempts to The HEFTI storytelling engine attempts to

merge results and ideas from both merge results and ideas from both communitiescommunities

Recombination, mutation, selection of Recombination, mutation, selection of authored story elements with Genetic authored story elements with Genetic Algorithm (GA)Algorithm (GA)

Generate, remove and traverse links in the Generate, remove and traverse links in the story elements as the story unfolds using the story elements as the story unfolds using the author’s predefined rulesauthor’s predefined rules

Story elements and rules are encoded in XMLStory elements and rules are encoded in XML Provides a small drag-and-drop tool and tree-Provides a small drag-and-drop tool and tree-

view tools for authors to create their storiesview tools for authors to create their stories

Page 6: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

DefinitionsDefinitions Story elements – Smallest units in Story elements – Smallest units in

HEFTI’s story search spaceHEFTI’s story search space Story template – Describes Story template – Describes

combinations of various story elements combinations of various story elements at a particular stage in the storyat a particular stage in the story

Template sequences – Subdivision of Template sequences – Subdivision of story template to depict time-based story template to depict time-based relationships among story elementsrelationships among story elements

Story component – Combination of Story component – Combination of story elements, agent scripts and story elements, agent scripts and variables generated by HEFTI based variables generated by HEFTI based on the given set of story templates and on the given set of story templates and elementselements

Page 7: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

Generating a StoryGenerating a Story

A story is divided into multiple time steps A story is divided into multiple time steps Chromosomes represent a story componentChromosomes represent a story component Genes represent a collection of story Genes represent a collection of story

elements pertaining to a template elements pertaining to a template sequence within a story templatesequence within a story template

Genes are encoded as floating point Genes are encoded as floating point numbers for convenience of manipulation numbers for convenience of manipulation (as shown later)(as shown later)

Page 8: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

Generating a Story (cont.)Generating a Story (cont.)

A gene is generated by constructing valid A gene is generated by constructing valid story element sets based on the current story element sets based on the current state of the story and various conditions and state of the story and various conditions and rules imposed by the author (Encoding)rules imposed by the author (Encoding)

The encoding process is sequential due to The encoding process is sequential due to dependencies and ordering of story elementsdependencies and ordering of story elements

The encoding process is repeated several The encoding process is repeated several times to generate individuals in the GA times to generate individuals in the GA populationpopulation

Page 9: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

Generating a Story (cont.)Generating a Story (cont.)

After the evolution process, the After the evolution process, the decoding process steps through each decoding process steps through each of the genes, decoding each gene of the genes, decoding each gene based on its story contextbased on its story context

The end result is a story component The end result is a story component that describes the next story that describes the next story sequencesequence

The process is repeated to generate The process is repeated to generate subsequent story sequencessubsequent story sequences

Page 10: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

Generating a Story (cont.)Generating a Story (cont.)

Page 11: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

Operations on Story Operations on Story ComponentsComponents

The original genetic operators are The original genetic operators are modified to handle authored ordering modified to handle authored ordering of story elementsof story elements

Chromosome level operators:Chromosome level operators: Single point crossoverSingle point crossover Multi point crossoverMulti point crossover

Gene level operators:Gene level operators: Crossover operatorsCrossover operators MutationMutation

Page 12: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

Chromosome OperatorsChromosome Operators

The offsets are chosen to share The offsets are chosen to share similar starting conditions and similar starting conditions and consequencesconsequences

The operator generates permutations The operator generates permutations of the template sequencesof the template sequences

Chromosome A

Chromosome B

Chosen offsets for multipoint crossover

Chromosome A*

Chromosome B*

Page 13: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

Chromosome Operators Chromosome Operators (cont.)(cont.)

An example from The Three Little Pigs An example from The Three Little Pigs ……

Given two chromosomes (A and B) with:Given two chromosomes (A and B) with:Starting conditions: Starting conditions:

Wolf shows up in front of Angela Pig’s houseWolf shows up in front of Angela Pig’s house

Consequences: Consequences:

Wolf eats Angela PigWolf eats Angela Pig If the state of the story is the same for both, If the state of the story is the same for both,

the intermediary stages can be swapped the intermediary stages can be swapped between A and Bbetween A and B

Page 14: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

Gene OperatorsGene Operators Alter selection of story Alter selection of story

elementselements Crossover operators are the Crossover operators are the

same as at the chromosome same as at the chromosome level except they crossover level except they crossover story elements instead of story elements instead of genesgenes

Mutation operator changes Mutation operator changes the offset into a list of the offset into a list of possible story elementspossible story elements

Gene A (Before mutation)

Gene A* (After mutation)

1

6

4

3

……

1

6

4

……

1Chosen offset for mutation

Page 15: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

Story ThreadsStory Threads

Authors create Authors create potentialpotential story threads story threads Story thread is an Story thread is an indicatorindicator for: for:

1.1. Length of storyLength of story

2.2. Choice of story elements from a story Choice of story elements from a story templatetemplate

3.3. Sets of story templates to be used at Sets of story templates to be used at certain story time stepscertain story time steps

4.4. Rules that change the flow of the storyRules that change the flow of the story

5.5. Evaluation criteria for chromosome fitnessEvaluation criteria for chromosome fitness

Page 16: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

Fitness EvaluationFitness Evaluation

HEFTI is free to generate stories that adhere HEFTI is free to generate stories that adhere only so closely (within a threshold) to a story only so closely (within a threshold) to a story threadthread

Fitness evaluation takes place on the Fitness evaluation takes place on the chromosomes of a story threadchromosomes of a story thread

Authors can indicate Authors can indicate preference, preference, indifference, or dislike towards certain story indifference, or dislike towards certain story elements by assigning positive or negative elements by assigning positive or negative values to the story elements values to the story elements

The existence of certain story elements in The existence of certain story elements in story components are influenced accordingly story components are influenced accordingly through the selection mechanisms of GAthrough the selection mechanisms of GA

Page 17: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

Story Thread with Story Thread with Fitness EvaluationFitness Evaluation

<timestep order="4" name="wolf's plan" <timestep order="4" name="wolf's plan" loop="{isPigStillAvailable.value} == loop="{isPigStillAvailable.value} == true true AND {isWolfDead.value} == false">AND {isWolfDead.value} == false">

<set type="wolf's plan" ><set type="wolf's plan" > <element name="act_13" <element name="act_13"

addfitness="0.8"/>addfitness="0.8"/></set></set>

</timestep></timestep>

Page 18: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

Scenarios of UseScenarios of Use

Interactive fiction: A murder mystery Interactive fiction: A murder mystery with multiple dynamically generated with multiple dynamically generated story threadsstory threads

Sub-module of a computer game Sub-module of a computer game engine that dynamically combines engine that dynamically combines various story and agent scripts from various story and agent scripts from existing story elementsexisting story elements

An educational environment that can An educational environment that can present new concepts in various forms present new concepts in various forms while preserving the goals of the storywhile preserving the goals of the story

Page 19: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

ConclusionsConclusions

HEFTI needs a large enough set of HEFTI needs a large enough set of story elements and templates for it to story elements and templates for it to create the story componentscreate the story components

Authoring a story from scratch can be Authoring a story from scratch can be tedioustedious

Story templates allow authors to Story templates allow authors to create story elements at different create story elements at different granularitiesgranularities

Story elements can be reused in Story elements can be reused in similar story settingssimilar story settings

Page 20: A Genetic Algorithm Approach To Interactive Narrative Generation TeongJoo Ong and John Leggett Texas A&M University

Future WorkFuture Work

Genetic programming might be used Genetic programming might be used to generate agent scripts given the to generate agent scripts given the starting and ending agent actionsstarting and ending agent actions

Evaluation of fitness data on all of Evaluation of fitness data on all of the story variants that HEFTI is the story variants that HEFTI is capable of generatingcapable of generating

Better support for user interaction Better support for user interaction and control of the storyand control of the story