rule-based interactive fiction

38
Rule-based Interactive Fiction Chris Martens * Zachary Sparks * Claire Alvis * Will Byrd Carnegie Mellon * Indiana University ! * o- >_

Upload: others

Post on 12-Sep-2021

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Rule-based Interactive Fiction

Rule-based Interactive Fiction

Chris Martens * Zachary Sparks * Claire Alvis * Will Byrd

Carnegie Mellon * Indiana University

! * o- >_

Page 2: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 2

Intro to IFWest of House

You are standing in an open field west of a white house, with a boarded front door.There is a small mailbox here.

>_

Page 3: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 3

Intro to IF

Game World

Descriptions of game state

Commands

Page 4: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 4

Intro to IFWest of House

You are standing in an open field west of a white house, with a boarded front door.There is a small mailbox here.

>_

Page 5: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 5

Intro to IF> x houseThe house is a beautiful colonial house which is painted white. It is clear that the owners must have been extremely wealthy.

Page 6: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 6

Intro to IF> open mailboxOpening the mailbox reveals a small leaflet.

Page 7: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 7

Intro to IF> take leafletTaken.

Page 8: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 8

Intro to IF> inventoryYou are carrying:

A leaflet

Page 9: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 9

Intro to IF

Game descriptionGame World

Descriptions of game state

Commands

Page 10: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 10

Game descriptionGame World

Rendering

Interpreting

Intro to IF

Page 11: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 11

Really, this is a suggestion that we study all interactive programs in a declarative way.

IF is just fun :)

A good domain for PL!

Page 12: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 12

Logic ProgrammingCurry-Howard:

Props as Types / Proofs as Programs

Miller: (“Proof search foundations for logic programming,” WOLLIC'03)

Props as ProgramsProof search as execution

Page 13: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 13

TakeawayInteractive proof search as interactive execution

(i.e. gameplay)

Page 14: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 14

“[Building [proof] scripts is surprisingly addictive, in a videogame kind of way...”

Xavier Leroy“Formal certification of a compiler back-end”POPL'06

TakeawayInteractive proof search as interactive execution

Page 15: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 15

The Author's Task● Describe the world (map, locations of objects, win conditions)

● Describe the state transitions that move the game forward

● Anticipate player input

Page 16: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 16

Inform7 (see inform7.com)

3 There is a room called West of House. "You are standing in an open field 4 west of a white house, with a boarded front door." 5 6 The white house is a backdrop in West of House. 7 The description of the house is 8 "The house is a beautiful colonial house which is painted white. It is 9 clear that the owners must have been extremely wealthy." 10 11 The small mailbox is a container in West of House. 12 The small mailbox is closed and openable. 13 After opening the mailbox, say "Opening the small mailbox reveals a 14 leaflet." 15 Instead of taking the mailbox, say "It is securely anchored." 16 17 The leaflet is in the small mailbox. 18 The description of the leaflet is 19 "'WELCOME TO ZORK!'"

Page 17: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 17

Inform7 3 There is a room called West of House. "You are standing in an open field 4 west of a white house, with a boarded front door." 5 6 The white house is a backdrop in West of House. 7 The description of the house is 8 "The house is a beautiful colonial house which is painted white. It is 9 clear that the owners must have been extremely wealthy." 10 11 The small mailbox is a container in West of House. 12 The small mailbox is closed and openable. 13 After opening the mailbox, say "Opening the small mailbox reveals a 14 leaflet." 15 Instead of taking the mailbox, say "It is securely anchored." 16 17 The leaflet is in the small mailbox. 18 The description of the leaflet is 19 "'WELCOME TO ZORK!'”

Page 18: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 18

Inform7 3 There is a room called West of House. "You are standing in an open field 4 west of a white house, with a boarded front door." 5 6 The white house is a backdrop in West of House. 7 The description of the house is 8 "The house is a beautiful colonial house which is painted white. It is 9 clear that the owners must have been extremely wealthy." 10 11 The small mailbox is a container in West of House. 12 The small mailbox is closed and openable. 13 After opening the mailbox, say "Opening the small mailbox reveals a 14 leaflet." 15 Instead of taking the mailbox, say "It is securely anchored." 16 17 The leaflet is in the small mailbox. 18 The description of the leaflet is 19 "'WELCOME TO ZORK!'"

Page 19: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 19

Logic Programming

> take leaflet

?- take(leaflet, X).

Page 20: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 20

Logic Programming

> take leafletTaken.

?- take(leaflet, X).X = say(“Taken.”)

Page 21: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 21

Logic ProgrammingTry: X = say “taken”

. .

. .

. .visible(leaflet) portable(leaflet)___________________________________take(leaflet, say “taken”).

Page 22: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 22

Logic ProgrammingThere is a room called West of House."You are standing..."

in(player, westofhouse).description(westofhouse, "You are standing...").

Page 23: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 23

Logic ProgrammingThe small mailbox is a container in West of House.The small mailbox is closed and openable.

in(mailbox, westofhouse).closed(mailbox).openable(mailbox).

Page 24: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 24

Logic Programming(Inform7 has defaults!)

examine(X, say(D)) :- visible(X), description(X, D).

Page 25: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 25

Logic Programmingopen(C, say("opened")) :- openable(C), closed(C).%% But also change state! Mailbox opened; contents visible...?

Page 26: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 26

Logic Programmingtake(X, say("taken")) :- portable(X), visible(X).%% But also change in(X,Y) to in(X,player)!

%% And then there are all the failure conditions...

Page 27: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 27

*, -o, !

Linear Logic Programming

*, -o, !

A logic for reasoning about resources and state. * conjoins 2 resources, -o consumes a resource and produces another, ! recovers the original logic.

Page 28: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 28

Linear Logic Programming

in(mailbox, westofhouse).closed(mailbox).!openable(mailbox).

Page 29: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 29

Linear Logic Programmingopen(C, say("opened")) * opened(C) o- !openable(C) * closed(C).

take(X, say("taken")) * in(X,player) * visible(X) o- !portable(X) * visible(X) * in(X,Y).

But there's a problem with this that we don't yet know how to solve...

Page 30: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 30

Linear Logic Programmingtake(X,say("taken"))* in(X,player)* visible(X) %% ???

o- !portable(X)* visible(X)* in(X,Y).

It isn't clear whether to conserve this resource. How is it defined?

Page 31: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 31

Linear Logic Programmingvisible(X) o- in(player,R) * in(X,R).visible(X) o- in(X,C) * open(C) * visible(C).

Page 32: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 32

Linear Logic Programmingvisible(X) * in(player,R) * in(X,R) o- in(player,R) * in(X,R).visible(X)

* in(X,C) * open(C) * visible(C) o- in(X,C) * open(C) * visible(C).

Page 33: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 33

Linear Logic Programming

Old state S New state S'Condition(S)

“Read-Only Access to Resources” a la Garg & Pfenning

Page 34: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 34

Possibly Fruitful?Proof IrrelevanceHybrid LogicOther Kripke-style modal logic

Page 35: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 35

Other ChallengesOverriding Defaults

It's visible unless the room is darkunless the player carries a flashlightunless the batteries are dead(and so on)

Plotkin, A. Rule-based programming. http://eblong.com/zarf/rule-language.html, June 2010.

Page 36: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 36

Other ChallengesNegation

Taking something: check whether the player already has it!

Could put the failure rule first...

Page 37: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 37

Other ChallengesIn general, giving the author control of rule precedence.

Possibly fruitful: Defeasible Logic (Donald Nute, defeasible.org)

Page 38: Rule-based Interactive Fiction

06/02/12 Rule-based Interactive Fiction - OBT 2012 38

SummaryInteractive programs as interactive proof search!Richer logics for hard problems!Some systems to check out:

● Lolli: http://www.cs.cmu.edu/~fp/courses/15816-f01/software.html ● Lollibot/Ollibot: https://github.com/clf/ollibot