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

Ceptre: A Language for Modeling Interactive Worlds

Chris
September 24, 2015
150

Ceptre: A Language for Modeling Interactive Worlds

Slides for Future Programming Workshop at Strange Loop

Chris

September 24, 2015
Tweet

Transcript

  1. 1
    CEPTRE
    A Language for Modeling

    Interactive Worlds
    Chris Martens

    Future Programming Workshop @ Strange Loop

    September 24, 2015

    View Slide

  2. 2
    CEPTRE
    A Language for Modeling

    Interactive Worlds
    Chris Martens

    Future Programming Workshop @ Strange Loop

    September 24, 2015

    View Slide

  3. 3
    Attack

    (Starts at 1)
    Health

    (Starts at 3)
    Defense Defense

    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
    Buff other:

    Spend your turn to increase
    someone else’s attack

    View Slide

  7. 7
    BUFF

    (self or other)
    ATTACK

    View Slide

  8. 8

    View Slide

  9. 9

    View Slide

  10. 10

    View Slide

  11. 11
    PROBLEM

    View Slide

  12. 12
    Formal Language

    for Game Sketching
    Executable

    Rules First

    Platform-agnostic

    General

    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

    View Slide

  17. 17

    View Slide

  18. 18
    Interactive Worlds
    An interactive world is

    an initial configuration

    (e.g. players’ stats at the start of the game)

    !
    together with rules for evolving configurations,

    (e.g.: buffing increases player’s attack)

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

    View Slide

  19. 19
    CEPTRE

    !
    PAYOFF

    !
    DISCUSSION
    Outline

    View Slide

  20. 20
    CEPTRE

    Linear Logic Programming
    Stages & Interaction

    !
    PAYOFF

    !
    DISCUSSION
    Outline

    View Slide

  21. 21
    Logic
    Facts about the world are propositions:

    !
    The player is in the foyer

    Juliet loves Romeo

    Roger has 2 health points

    View Slide

  22. 22
    Facts about the world are propositions:

    !
    !
    !
    Logic

    View Slide

  23. 23
    Action and Change

    View Slide

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

    View Slide

  25. 25

    View Slide

  26. 26

    View Slide

  27. 27
    Movement rule, take 2

    View Slide

  28. 28

    View Slide

  29. 29

    View Slide

  30. 30
    Movement rule, take 3

    View Slide

  31. 31
    Movement rule, take 3’

    View Slide

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

    View Slide

  33. 33
    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

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

    View Slide

  35. 35
    LANGUAGE

    (Logic Programming)

    View Slide

  36. 36
    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

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

    View Slide

  38. 38
    EXAMPLE WORLD:

    Defense Defense

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  42. 42
    Configurations (Contexts)
    context init =
    { on_team chris blue,
    on_team gwenn yellow,
    health chris 3,
    attack gwenn 2,
    […] }
    Multisets of ground propositions

    View Slide

  43. 43
    Traces
    buff : […]
    attack : […]
    die : […]
    !
    !
    context init
    = {…}
    !
    !
    #trace init.
    }
    }
    0

    View Slide

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

    View Slide

  45. 45
    Interactivity?
    #interactive.
    #trace init.

    View Slide

  46. 46
    Interactivity?
    1: (buff gwenn chris (s z))
    2: (buff gwenn karl (s z))
    […]
    17: (target chris (s z) gwenn (s (s (s z))) (s (s z)))
    18: (target chris (s z) chris (s (s (s z))) (s (s z)))
    ?-

    View Slide

  47. 47
    Interactivity?
    1: (buff gwenn chris (s z))
    2: (buff gwenn karl (s z))
    […]
    17: (target chris (s z) gwenn (s (s (s z))) (s (s z)))
    18: (target chris (s z) chris (s (s (s z))) (s (s z)))
    ?-
    yellow team
    blue team

    View Slide

  48. 48
    CEPTRE

    Linear Logic Programming

    Stages & Interaction

    !
    PAYOFF

    !
    DISCUSSION
    Outline

    View Slide

  49. 49
    CEPTRE

    Linear Logic Programming

    Stages & Interaction
    !
    PAYOFF

    !
    DISCUSSION
    Outline

    View Slide

  50. 50
    heads_wins : heads * tails -o heads.
    tails_wins : heads * tails -o tails.
    !
    overall_heads : heads -o heads_overall.
    overall_tails : tails -o tails_overall.

    View Slide

  51. 51
    heads_wins
    : $stage tournament
    * heads * tails -o heads.
    !
    tails_wins
    : $stage tournament
    * heads * tails -o tails.
    !
    !
    !
    overall_heads
    : $stage tally * heads -o heads_overall.
    overall_tails
    : $stage tally * tails -o heads_overall.

    View Slide

  52. 52
    heads_wins
    : $stage tournament
    * heads * tails -o heads.
    !
    tails_wins
    : $stage tournament
    * heads * tails -o tails.
    !
    [???] stage tournament -o stage tally.
    !
    overall_heads
    : $stage tally * heads -o heads_overall.
    overall_tails
    : $stage tally * tails -o heads_overall.

    View Slide

  53. 53
    heads_wins
    : $stage tournament
    * heads * tails -o heads.
    !
    tails_wins
    : $stage tournament
    * heads * tails -o tails.
    !
    qui * stage tournament -o stage tally.
    !
    overall_heads
    : $stage tally * heads -o heads_overall.
    overall_tails
    : $stage tally * tails -o heads_overall.

    View Slide

  54. 54
    stage tournament = {
    heads_wins : heads * tails -o heads.
    tails_wins : heads * tails -o tails.
    }
    !
    qui * stage tournament -o stage tally.
    !
    stage tally = {
    overall_heads : heads -o heads_wins.
    overall_tails : tails -o tails_wins.
    }

    View Slide

  55. 55
    stage tournament = {
    heads_wins : heads * tails -o heads.
    tails_wins : heads * tails -o tails.
    } #interactive tournament.
    !
    qui * stage tournament -o stage tally.
    !
    stage tally = {
    overall_heads : heads -o heads_wins.
    overall_tails : tails -o tails_wins.
    }

    View Slide

  56. 56
    BUFF

    (self or other)
    ATTACK
    Returning to Defense Defense…

    View Slide

  57. 57
    Ceptre
    User-defined terms, predicates

    Multiset rewriting rules

    Prolog-style rules

    Stages, quiescence, and interactivity
    http://www.github.com/chrisamaphone/interactive-lp

    View Slide

  58. 58
    Limitations?
    Negation

    Comprehension

    Rule ordering

    etc.

    View Slide

  59. 59
    Limitations?
    Programming Tricks (See: Chapter 4 of my thesis)
    Negation

    Comprehension

    Rule ordering

    etc.

    View Slide

  60. 60
    Credits

    !
    Prior linear logic programming languages:

    Lygon [1996], LolliMon [2005], Celf [2008]

    !
    Ceptre adds interactivity and stages.

    View Slide

  61. CEPTRE

    !
    PAYOFF
    Case Studies

    Experiments

    !
    DISCUSSION
    61
    Outline

    View Slide

  62. 62
    Case Studies
    Narrative Generation
    Multi-agent interactive social simulation
    Roguelike-likes (combat & monster gen)
    Board games (Settlers of Catan)

    View Slide

  63. 63
    “Fuzzing” player input &

    augmenting rules w/AI strategies
    Ceptre as

    Game Chemistry Lab

    View Slide

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

    Buffing Only Friends

    View Slide

  65. 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.
    65
    Augmenting rules with strategies:

    Attacking Only Enemies

    View Slide

  66. 66
    Evaluating for Balance

    View Slide

  67. 67
    Evaluating for Balance
    (c.f. LUDI system for game synthesis & evaluation)

    View Slide

  68. 68
    CEPTRE

    !
    PAYOFF

    !
    DISCUSSION
    Invariants

    Future Work

    Lessons
    Outline

    View Slide

  69. 69
    (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 should always
    have an attack value

    !

    View Slide

  70. 70
    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

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

    View Slide

  72. 72
    Decidability Result
    Whether or not a given (propositional Ceptre)
    program satisfies an invariant is decidable.
    n.b.: O(2^(2^n))

    Not a tractable checking algorithm!

    Future work: automation & integration into the PL.

    View Slide

  73. 73
    Future Work
    Accessible game design frameworks
    Ceptre

    Program
    Hypertext

    front-end
    2D tile

    front-end
    Twine

    output
    PuzzleScript

    output

    View Slide

  74. 74
    Lessons for

    !
    PL Design

    View Slide

  75. 75
    Lessons for

    Domain-Specific?

    PL Design

    View Slide

  76. 76
    Lessons for

    Domain-Oriented

    PL Design

    View Slide

  77. The Curry-Howard homeomorphism
    LC'90
    77
    Logical Basis

    View Slide

  78. 78
    Minimalism

    View Slide

  79. 79
    Revisionism

    View Slide

  80. Thanks!
    Ceptre: github.com/chrisamaphone/interactive-lp

    !
    Me: Chris Martens

    Web: http://www.cs.cmu.edu/~cmartens

    Thesis: [Web]/thesis

    Twitter: @chrisamaphone

    Research Blog: lambdamaphone.blogspot.com
    80

    View Slide

  81. Bonus Slides
    81

    View Slide

  82. Backward chaining

    (goal directed)

    !
    vs

    !
    Forward chaining

    (context-directed)
    82

    View Slide

  83. Backward Chaining
    83

    View Slide

  84. Backward Chaining
    84

    View Slide

  85. Backward Chaining
    85

    View Slide

  86. Forward Chaining
    86

    View Slide

  87. Forward Chaining
    87

    View Slide

  88. Forward Chaining
    88

    View Slide

  89. Forward Chaining
    89

    View Slide

  90. } 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’.
    90

    View Slide

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

    View Slide

  92. 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
    92

    View Slide

  93. 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
    93

    View Slide

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

    View Slide

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

    View Slide

  96. 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.)
    96

    View Slide

  97. 97
    stage yellow_team = {
    attack : …
    buff : …
    }
    !
    stage blue_team = {
    attack : …
    buff : …
    }
    Returning to Defense Defense…

    View Slide

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

    }

    View Slide

  99. 99
    stage play = {
    attack : turn P * …
    buff : turn P * …
    }
    !
    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

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

    }

    View Slide

  101. Causal Analysis
    101

    View Slide

  102. 102
    Proof Construction
    102

    View Slide

  103. 103
    103

    View Slide

  104. 104
    104

    View Slide

  105. 105
    105

    View Slide

  106. 106
    106

    View Slide

  107. 107
    107

    View Slide

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

    View Slide

  109. Concurrent Structure
    r1
    c
    r2
    b
    a1 a2
    109

    View Slide

  110. Causal Structure
    attack
    buff
    die
    buff
    110

    View Slide

  111. do/genturns
    attack
    gwenn blue yellow chris (s (s z)) (s z) z
    buff_other
    chris yellow roger (s (s z)) x176
    buff
    frank (s (s (s z)))
    do/gen_turn
    blue frank
    do/gen_turn
    blue gwenn
    x191
    do/genturns
    another_round
    x192
    x194
    do/play
    x193
    buff
    roger (s (s (s z)))
    x202
    do/gen_gen_turns
    x201
    x203
    do/gen_turn
    yellow karl
    x208
    x207
    x206
    x209
    x211
    switch_team_turn
    blue yellow
    x210
    x214
    x213
    x212
    do/gen_turn
    frank
    x217 x216
    x215
    do/restore_team
    gwenn blue
    do/gen_turn
    gwenn
    x221
    x220
    x219
    x218
    x223
    x222
    x224
    x226
    x227
    x228
    x233 x232
    x231
    die
    chris yellow
    x234
    x238 x237
    111

    View Slide

  112. Concurrent structure in proofs

    yields causal structure among actions
    112

    View Slide

  113. 113

    View Slide