Chris
September 24, 2015
170

# Ceptre: A Language for Modeling Interactive Worlds

Slides for Future Programming Workshop at Strange Loop

## Chris

September 24, 2015

## Transcript

1. ### 1 CEPTRE A Language for Modeling Interactive Worlds Chris Martens

Future Programming Workshop @ Strange Loop September 24, 2015
2. ### 2 CEPTRE A Language for Modeling Interactive Worlds Chris Martens

Future Programming Workshop @ Strange Loop September 24, 2015

Defense

attack

General

General

General

General

18. ### 18 Interactive Worlds An interactive world is an initial conﬁguration

(e.g. players’ stats at the start of the game) ! together with rules for evolving conﬁgurations, (e.g.: bufﬁng increases player’s attack) ! some of which are mediated by human interaction, randomness, or other processes.

20. ### 20 CEPTRE Linear Logic Programming Stages & Interaction ! PAYOFF

! DISCUSSION Outline
21. ### 21 Logic Facts about the world are propositions: ! The

player is in the foyer Juliet loves Romeo Roger has 2 health points

Logic

al. 2003]

32. ### 32 Program Rules move : in player Room * adjacent

Room Room’ —o in player Room’. ! adjacent/foyer-kitchen : adjacent foyer kitchen.
33. ### 33 Author-deﬁned terms and predicates, quantiﬁed Variables, tensor (*), bang

(!), and lolli (—o) are all we need to specify action & change on a logical level. Linear Logic
34. ### 34 A * \$B —o C ! == ! A

* B —o C * B Derived Syntax

36. ### 36 Linear Logic Programming Conﬁguration (linear context) term/predicate declarations,  permanent

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

39. ### 39 Bufﬁng buff : turn Player * attack Player Att

-o attack Player (Att + 1).
40. ### 40 Bufﬁng Others buff : turn Player * attack Player’

Att -o attack Player’ (Att + 1).
41. ### attack : turn Player * \$attack Player A * health

Enemy H -o health Enemy (H - A). ! die : health P 0 -o dead P. 41 Attacking
42. ### 42 Conﬁgurations (Contexts) context init = { on_team chris blue,

on_team gwenn yellow, health chris 3, attack gwenn 2, […] } Multisets of ground propositions
43. ### 43 Traces buff : […] attack : […] die :

[…] ! ! context init = {…} ! ! #trace init. } } 0

ﬁre 0 … n

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))) ?-
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
48. ### 48 CEPTRE Linear Logic Programming Stages & Interaction ! PAYOFF

! DISCUSSION Outline
49. ### 49 CEPTRE Linear Logic Programming Stages & Interaction ! PAYOFF

! DISCUSSION Outline

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

57. ### 57 Ceptre User-deﬁned terms, predicates Multiset rewriting rules Prolog-style rules

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

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

Negation Comprehension Rule ordering etc.
60. ### 60 Credits ! Prior linear logic programming languages: Lygon [1996],

LolliMon [2005], Celf [2008] ! Ceptre adds interactivity and stages.

62. ### 62 Case Studies Narrative Generation Multi-agent interactive social simulation Roguelike-likes

(combat & monster gen) Board games (Settlers of Catan)
63. ### 63 “Fuzzing” player input & augmenting rules w/AI strategies Ceptre

as Game Chemistry Lab
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: Bufﬁng Only Friends
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

67. ### 67 Evaluating for Balance (c.f. LUDI system for game synthesis

& evaluation)

Outline
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 ! …
70. ### 70 Program Invariants INV holds of all initial conﬁgurations; !

and for all rules and all contexts , ! whenever INV holds of sdfa ! ! INV holds of j Invariant INV holds for a speciﬁcation iff:

72. ### 72 Decidability Result Whether or not a given (propositional Ceptre)

program satisﬁes an invariant is decidable. n.b.: O(2^(2^n)) Not a tractable checking algorithm! Future work: automation & integration into the PL.
73. ### 73 Future Work Accessible game design frameworks Ceptre Program Hypertext

front-end 2D tile front-end Twine output PuzzleScript output

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

82

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
91. ### attack : turn Player * \$attack W Att * health

Enemy H -o subtract Enemy H Att. Attacking 91
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
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
94. ### opp team team : bwd. opp blue yellow. opp yellow

blue. Persistent Predicates 94
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
96. ### Types and Predicates nat : type. z : nat. s

nat : nat. (Operators on numbers can be deﬁned in the language via backward chaining, or by accessing built-in functions.) 96
97. ### 97 stage yellow_team = { attack : … buff :

… } ! stage blue_team = { attack : … buff : … } Returning to Defense Defense…
98. ### 98 stage play = { attack : … buff :

… } ! stage generate_turns = { … }
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.
100. ### 100 stage play = { attack : … buff :

… } #interactive play. ! ! ! stage generate_turns = { … }

108. ### Concurrent Structure let b = r1 a1 let c =

r2 a2 a1 a2 = b c let b = r1 a1 let c = r2 a2 108

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