Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Programming Interactive Worlds with Linear Logic

Chris
August 31, 2015

Programming Interactive Worlds with Linear Logic

Ph.D. thesis defense

Chris

August 31, 2015
Tweet

More Decks by Chris

Other Decks in Research

Transcript

  1. 1

    View Slide

  2. 2

    View Slide

  3. 3
    Attack

    (Starts at 1)
    Health

    (Starts at 3)

    View Slide

  4. 4
    Buff:

    Add 1 to
    attack

    View Slide

  5. 5
    Attack: Enemy subtracts
    your attack from

    their health

    View Slide

  6. 6
    Yellow Team Go!
    BUFF
    ATTACK

    View Slide

  7. 7
    Buff other:

    Spend your turn to increase
    someone else’s attack

    View Slide

  8. 8
    Blue Team Go!
    BUFF

    (self or other)
    ATTACK

    View Slide

  9. 9

    View Slide

  10. 10

    View Slide

  11. 11

    View Slide

  12. 12
    PROBLEM

    View Slide

  13. 13
    Formal Language

    for Game Sketching
    Executable

    Rules First

    Platform-agnostic

    General

    View Slide

  14. 14
    Formal Language

    for Game Sketching
    Executable

    Rules First

    Platform-agnostic

    General

    View Slide

  15. 15
    Formal Language

    for Game Sketching
    Executable

    Rules First

    Platform-agnostic

    General

    View Slide

  16. 16
    Formal Language

    for Game Sketching
    Executable

    Rules First

    Platform-agnostic

    General

    View Slide

  17. 17
    Interactive Worlds

    (Definition)
    An interactive world is

    an initial configuration

    (e.g. your cards at the start of the game)

    !
    together with rules for evolving configurations,

    (e.g.: buffing increases your attack)

    !
    some of which are mediated by human interaction, randomness,
    or other processes.

    View Slide

  18. 18

    View Slide

  19. 19
    A formal language

    for describing interactive worlds

    makes it easier to sketch and invent

    novel game & story designs.
    Thesis Statement
    (Take 1)

    View Slide

  20. 20
    Thesis Statement
    (Take 1)
    A formal language

    for describing interactive worlds

    makes it easier to sketch and invent

    novel game & story designs.

    View Slide

  21. 21
    Authoring Potential Narratives
    [Diagram credit: Sam Kabo Ashwell]

    View Slide

  22. 22
    Authoring Potential Narratives

    View Slide

  23. 23
    Authoring Potential Narratives
    choose character stats branch on character stats

    View Slide

  24. 24
    A formal language for describing interactive worlds

    enables rapid prototyping of experimental game designs

    and deeper understanding of narrative structure.
    Thesis Statement
    (Take 2)

    View Slide

  25. 25
    Thesis Statement
    (Take 2)
    A formal language for describing interactive worlds

    enables rapid prototyping of experimental game designs

    and deeper understanding of narrative structure.

    View Slide

  26. 26
    THESIS STATEMENT
    Using linear logic to model interactive worlds enables rapid
    prototyping of experimental game designs and deeper understanding
    of narrative structure.

    View Slide

  27. Programming language (Ceptre)
    Causal analysis for games & narratives
    Case studies
    Meta-reasoning methodology
    27
    Contributions

    View Slide

  28. 28
    Programming language (Ceptre)
    Causal analysis for games & narratives
    Case studies
    Meta-reasoning methodology
    Contributions

    View Slide

  29. 29
    APPROACH

    Linear Logic Programming

    View Slide

  30. 30
    Logic
    Facts about the world are propositions:

    !
    The player is in the foyer

    Juliet loves Romeo

    Roger has 2 health points

    View Slide

  31. 31
    Facts about the world are propositions:

    !
    !
    !
    Logic

    View Slide

  32. 32
    Action and Change

    View Slide

  33. 33
    Action and Change
    [Girard 1987, Girard/LaFont 87, Chang et al. 2003]

    View Slide

  34. 34

    View Slide

  35. 35

    View Slide

  36. 36
    Movement rule, take 2

    View Slide

  37. 37

    View Slide

  38. 38

    View Slide

  39. 39
    Movement rule, take 3

    View Slide

  40. 40
    Movement rule, take 3’

    View Slide

  41. 41
    Program Rules
    move : in player Room * adjacent Room Room’
    —o
    in player Room’.
    !
    adjacent/foyer-kitchen : adjacent foyer kitchen.

    View Slide

  42. 42
    Author-defined terms and predicates,

    quantified Variables,

    tensor (*), bang (!), and lolli (—o)

    are all we need

    to specify action & change on a logical level.
    Linear Logic

    View Slide

  43. 43
    A * $B —o C
    !
    ==
    !
    A * B —o C * B
    Derived Syntax

    View Slide

  44. 44
    Programming language (Ceptre)
    Causal analysis for games & narratives
    Case studies
    Meta-reasoning methodology
    Contributions

    View Slide

  45. 45
    Linear Logic Programming
    Configuration (linear context)
    term/predicate declarations,

    permanent facts, and rules
    [Harland et al. 2000; Lopez et al. 2005]
    e.g.
    Signature (permanent rules)

    View Slide

  46. 46
    Multiset Rewriting
    [Cervesato & Scevdrov 2009]
    (synonym: forward chaining)

    View Slide

  47. 47
    EXAMPLE WORLD:

    Defense Defense

    View Slide

  48. 48
    Buffing
    buff :
    turn Player * attack Player Att
    -o attack Player (Att + 1).

    View Slide

  49. 49
    Buffing Others
    buff :
    turn Player * attack Player’ Att
    -o attack Player’ (Att + 1).

    View Slide

  50. attack :
    turn Player
    * $attack Player A
    * health Enemy H
    -o health Enemy (H - A).
    !
    die : health P 0 -o dead P.
    50
    Attacking

    View Slide

  51. 51
    Configurations (Contexts)
    { turn player1,
    turn player4, […],
    on_team player1 blue,
    on_team player2 yellow,
    health player1 3,
    attack player2 2,
    […] }
    Multisets of ground propositions

    View Slide

  52. 52
    Running a program
    context init = {…}
    #trace init.
    0

    View Slide

  53. 53
    Running a program
    Quiescence: no more rules in can fire
    0 … n

    View Slide

  54. 54
    Prior linear logic programming languages:

    Celf, LolliMon, Lygon
    Ceptre: Adding Interactivity and
    Stages

    View Slide

  55. 55
    stage yellow_team = {
    attack : …
    buff : …
    }
    !
    stage blue_team = {
    attack : …
    buff : …
    }

    View Slide

  56. 56
    stage play = {
    attack : …
    buff : …
    }
    !
    stage generate_turns = {

    }

    View Slide

  57. 57
    stage play = {
    attack : …
    buff : …
    }
    !
    qui * stage play * team_turn T * opp T T’
    -o stage generate_turns * team_turn T.
    !
    stage generate_turns = {

    }
    !
    qui * stage generate_turns
    -o stage play.

    View Slide

  58. 58
    stage play = {
    attack : …
    buff : …
    } #interactive play.
    !
    !
    !
    stage generate_turns = {

    }

    View Slide

  59. 59
    0: (quiesce)
    1: (buff chris 1)
    2: (buff andre 1)
    […]
    7: (target chris yellow blue frank 1 3)
    8: (target chris yellow blue gwenn 1 3)
    !
    ?-

    View Slide

  60. 60
    Ceptre
    Persistent backward-chaining

    Linear forward-chaining

    Terms, predicates

    Stages and quiescence rules

    (Sensing and acting predicates)
    http://www.github.com/chrisamaphone/interactive-lp
    Chapter 4 - AIIDE 2015

    View Slide

  61. 61
    Ceptre
    Compilable to Celf

    via interleaved (linear) backward and forward chaining

    http://www.github.com/chrisamaphone/interactive-lp
    Chapter 4 - AIIDE 2015

    View Slide

  62. Programming language (Ceptre)
    Causal analysis for games & narratives
    Case studies
    Meta-reasoning methodology
    62
    Contributions

    View Slide

  63. 63
    63
    Proof Construction

    View Slide

  64. 64
    64

    View Slide

  65. 65
    65

    View Slide

  66. 66
    66

    View Slide

  67. 67
    67

    View Slide

  68. 68
    68

    View Slide

  69. 69
    Concurrent Structure
    let b = r1 a1 let c = r2 a2
    a1 a2
    =
    b c
    let b = r1 a1
    let c = r2 a2

    View Slide

  70. 70
    Concurrent Structure
    r1
    c
    r2
    b
    a1 a2

    View Slide

  71. 71
    Causal Structure
    attack
    buff
    die
    buff

    View Slide

  72. 72
    TAKEAWAY:

    Concurrent structure in proofs

    yields causal structure among actions
    [Bosser et al. 2010, 2011;
    Watkins et al. 2002]

    View Slide

  73. Programming language (Ceptre)
    Causal analysis for games & narratives
    Case studies
    Meta-reasoning methodology
    73
    Contributions

    View Slide

  74. 74
    Case Study:

    Shakespearean Tragedy

    Story World
    do/becomeSuicidal
    : at C L *
    depressed C * depressed C * depressed C * depressed C
    -o at C L * suicidal C * wants C weapon.

    View Slide

  75. 75
    Causal Structure
    do/murder
    romeo capulet town
    do/insult/private
    tybalt town montague
    do/becomeSuicidal
    montague town
    do/m
    juliet tow
    do/suicide
    romeo town
    x147
    do/mourn
    montague town romeo
    x154 x153
    x152
    x151
    x155
    x182
    x188
    x187 x186
    x185
    x184
    x198
    x197 x196
    x200
    x199

    View Slide

  76. 76
    init
    emmaSpendsYearsInCovent
    leonFallsInLove
    emmaReadsRomanticNovels
    emmaReadsRomanticNovels
    emmaMarriesCharles
    emmaInvitedToBall
    emmaDiscoversLeonsLove
    emmaPushesLeonAway
    emmaContractsDebts
    emmaDoesNotGoToBall
    rodolpheDecidesToSeduceEmma
    emmaAcceptsRodolpheAdvances emmaContractsDebts
    rodolpheRelationshipFalters
    charlesDecidesToOperateHypolyte
    hypolyteIsAmputated
    emmaPurchasesGift
    emmaOffersGift
    emmaPurchasesProstheticLeg
    rodolpheBreaksUp
    emmaJumpsThroughWindow
    OR
    Causal Structure

    View Slide

  77. 77
    Narrative Generation

    Chapter 3/INT 2014/LPNMR 2013

    View Slide

  78. 78

    View Slide

  79. 79
    Tamara

    View Slide

  80. 80
    Tamara

    View Slide

  81. 81
    !
    b9_aelis_monologue

    : aelis b9 diningroom -o aelis c12 atrium.

    !
    b10_dante_despiga

    : dante b10 atrium * despiga b10 atrium

    -o dante c12 atrium * despiga c12 atrium.

    !
    b11_dannunzio_luisa

    : dannunzio b11 dannunzioroom * luisa b11 dannunzioroom

    -o dannunzio c12 atrium * luisa c12 above-atrium.

    View Slide

  82. 82
    x12
    a1_dannunzio_exits
    x17
    x16
    a1_grp2_aelis
    b4_carlotta_kisses_finzi
    x20 x19
    x18
    b2_despiga_monologue
    a1_grp1_luisa
    x22 x21
    b9_aelis_monologue a1_grp2_emilia
    x23
    b10_dante_despiga
    x25
    x24
    b3_luisa_monologue
    a1_grp1_dannunzio
    x2
    x26
    x27
    c12_finzi_exit
    x28
    b11_dannunzio_luisa
    x30
    a1_emilia_exits
    x32 x31
    b6_dannunzio_monologue
    x33
    x34
    x36
    x35
    x37
    x39
    x38
    b7_emilia_monologue
    x41
    x40
    x42
    b8_emilia_carlotta
    x44
    x43
    b5_finzi_monologue
    x46
    x45
    x47
    x53
    x51

    View Slide

  83. 83
    a1_emilia_exits
    a1_dannunzio_exits
    x14
    a1_grp1_dannunzio
    x16
    a1_grp2_emilia
    b2_despiga_monologue a1_grp2_aelis
    a1_grp1_luisa
    x23
    b10_dante_despiga
    x25
    x24
    b3_luisa_monologue
    x28 x27
    b6_dannunzio_monologue
    x30 x29
    c12_finzi_exit
    x31
    b11_dannunzio_luisa
    x32
    b4_carlotta_kisses_finzi
    x35 x34
    b9_aelis_monologue
    x36
    x38
    x37
    b7_emilia_monologue
    x39
    x41
    x40
    c_final
    x43
    x42
    b8_emilia_carlotta
    b5_finzi_monologue
    x44
    x45 x47
    x46
    c12_gunshot
    x53
    x52
    x51
    x50
    x49
    x48
    c12_emilia_carlotta_aelis_luisa_leave_atrium
    c12_take_presents_to_leda
    x56
    x55
    x54
    c13_finzi_luisa_confrontation
    x60
    x59 x58
    x57
    c13_emilia_aelis_carlotta_luisa_sidehall
    x62 x61
    x66 x65
    x64
    x63
    x70 x69 x68 x67
    c14_emilia_enter_leda
    x74 x73 x72 x71
    c14_all_exit_leda
    x78 x77 x76 x75

    View Slide

  84. 84
    Interactive World

    Case Studies
    Chapter 5
    Interactive storytelling (BuffyWorld)

    Action/reaction model

    !
    !
    !
    !

    View Slide

  85. 85
    Interactive World

    Case Studies
    Chapter 5
    Interactive storytelling (BuffyWorld)

    Action/reaction model

    !
    Board/card games: die rolls and distribution

    !
    !

    View Slide

  86. 86
    Interactive storytelling (BuffyWorld)

    Action/reaction model

    !
    Board/card games: die rolls and distribution

    !
    Novel designs: generative simulation games

    (RPG and GardenSim worlds)
    Interactive World

    Case Studies
    Chapter 5

    View Slide

  87. 87
    Limitations?
    Negation

    Comprehension

    Rule ordering

    etc.

    View Slide

  88. 88
    Limitations?
    Programming Tricks

    (see Chapter 4)
    Negation

    Comprehension

    Rule ordering

    etc.

    View Slide

  89. 89
    Fun with Ceptre
    Debugging automatic/generative stages

    Experimenting with player control schemes

    View Slide

  90. 90
    Fun with Ceptre
    “Fuzz testing” player input

    Augmenting rules w/AI strategies

    View Slide

  91. buff :
    turn Player
    * $on_team Player T
    * $on_Team Player’ T
    * attack Player’ Att
    -o attack Player’ (s Att).
    91
    Augmenting rules with strategies:

    Buffing Only Friends

    View Slide

  92. attack :
    turn Player
    * $on_team Player Team
    * opp Team Team’
    * $on_team Enemy Team’
    * $attack Player Att * health Enemy H
    -o subtract Enemy H Att.
    92
    Augmenting rules with strategies:

    Attacking Only Enemies

    View Slide

  93. 93
    Fun with Ceptre
    Evaluating for Balance

    View Slide

  94. 94
    (Actual) Limitations
    buff :
    turn Player
    * attack Player A
    -o attack Player (A+1).
    Invariants:

    each player should only
    ever have 1 turn active

    !
    a character should either
    be dead or have a team

    !
    a character with a team
    should always have an
    attack value

    !

    View Slide

  95. 95
    Contributions
    Programming language (Ceptre)
    Causal analysis for games & narratives
    Case studies
    Meta-reasoning methodology

    View Slide

  96. 96
    (Chapter 6)
    Reasoning Framework

    View Slide

  97. 97
    Program Invariants
    INV holds of all initial configurations;

    !
    and for all rules and all contexts ,

    !
    whenever INV holds of sdfa

    !
    !
    INV holds of j
    Invariant INV holds for a specification iff:

    View Slide

  98. 98
    Propositional Ceptre (similar to Horn clauses):

    !
    !
    !
    where can be atoms a or !a.
    Program Invariants

    View Slide

  99. 99
    Generative invariants (Simmons ’12)
    Program Invariants
    =
    =

    View Slide

  100. 100
    Decidability Result
    Via vector addition systems, the problem can be reduced to
    Presburger arithmetic (known decidable.)
    Upshot:

    Whether or not a given (propositional Ceptre)
    program satisfies a flat invariant is decidable.

    View Slide

  101. 101
    DISCUSSION

    View Slide

  102. 102
    To PL theory:
    Better understanding of forward-chaining logic programming

    Theoretical result about checking properties of evolving systems

    Large base of application examples
    !
    To game & narrative design:
    Better understanding of structure for potential narratives

    Unification of rule languages for narratives and systems

    Sandbox for prototyping, analyzing, and iterating upon designs
    Thesis Contributions

    View Slide

  103. 103
    Future Work
    Narrative representation:

    modal and higher-order logics

    (character-based reasoning about other characters’ beliefs;

    theory of mind)

    !
    Automated reasoning tools

    !
    Accessible game design framework

    View Slide

  104. 104
    Thesis Statement, reprise
    Ceptre (Ch 4)

    Reasoning Tools (Ch 6)
    Using linear logic to model interactive worlds enables rapid
    prototyping of experimental game designs and deeper understanding
    of narrative structure.

    View Slide

  105. 105
    Thesis Statement, reprise
    Using linear logic to model interactive worlds enables rapid
    prototyping of experimental game designs and deeper understanding
    of narrative structure.
    Case Studies (Ch 5)

    View Slide

  106. 106
    Thesis Statement, reprise
    Chapters 2 & 3
    Using linear logic to model interactive worlds enables rapid
    prototyping of experimental game designs and deeper understanding
    of narrative structure.

    View Slide

  107. Thanks!
    Using linear logic to model interactive worlds enables rapid
    prototyping of experimental game designs and deeper understanding
    of narrative structure.
    Thesis Statement, reprise
    http://www.cs.cmu.edu/~cmartens/thesis.pdf

    View Slide

  108. 108
    Bonus Slides

    View Slide

  109. 109
    Backward chaining

    (goal directed)

    !
    vs

    !
    Forward chaining

    (context-directed)

    View Slide

  110. 110
    Backward Chaining

    View Slide

  111. 111
    Backward Chaining

    View Slide

  112. 112
    Backward Chaining

    View Slide

  113. 113
    Forward Chaining

    View Slide

  114. 114
    Forward Chaining

    View Slide

  115. 115
    Forward Chaining

    View Slide

  116. 116
    Forward Chaining

    View Slide

  117. attack :
    turn Player
    * $on_team Player Team
    * opp Team Team’
    * $on_team Enemy Team’
    * $attack W Att * health Enemy H
    * nat_minus H Att H’
    -o health Enemy H’.
    !
    die : health P z -o dead P.
    117
    Backward-Chaining Subtraction

    View Slide

  118. 118
    } Prove with goal-directed

    rules
    } Find in linear context
    attack :
    turn Player
    * $on_team Player Team
    * $on_team Enemy Team’
    * $attack W Att
    * health Enemy H
    * opp Team Team’
    * nat_minus H Att H’
    -o health Enemy H’.

    View Slide

  119. 119
    attack :
    turn Player
    * $attack W Att * health Enemy H
    -o subtract Enemy H Att.
    Attacking

    View Slide

  120. 120
    subtract/s :
    subtract P (s Health) (s Att)
    -o subtract P Health Att.
    !
    subtract/done :
    subtract P H z -o health P H.
    !
    subtract/die :
    subtract P z Att -o dead P.
    Forward-Chaining Subtraction

    View Slide

  121. 121
    nat_minus nat nat nat : bwd.
    minus/z- : nat_minus z N z.
    minus/-z : nat_minus N z N.
    minus/s : nat_minus (s N) (s M) P
    <- nat_minus N M P.
    Backward-Chaining Subtraction

    View Slide

  122. opp team team : bwd.
    opp blue yellow.
    opp yellow blue.
    122
    Persistent Predicates

    View Slide

  123. 123
    Types and Predicates
    team : type.
    blue : team.
    yellow : team.
    !
    player : type.
    !
    on_team player team : pred.
    health player nat : pred.
    attack player nat : pred.

    View Slide

  124. 124
    Types and Predicates
    nat : type.
    z : nat.
    s nat : nat.
    (Operators on numbers can be defined in the language via backward
    chaining, or by accessing built-in functions.)

    View Slide

  125. 125

    View Slide

  126. 126
    PROBLEM 2: Feature Creep

    View Slide

  127. 127
    Interactive Fiction (IF)

    View Slide

  128. 128
    Interactive Fiction (IF)

    View Slide

  129. 129
    Twine
    Graph

    +

    hidden state

    View Slide

  130. 130
    Forward Chaining

    View Slide

  131. 131
    A formal language

    for describing stories and games

    makes it easier to sketch and invent

    novel designs.
    Thesis Statement
    (Take 1)

    View Slide

  132. 132
    Thesis Statement
    (Take 1)
    A formal language

    for describing stories and games

    makes it easier to sketch and invent

    novel designs.

    View Slide