Skip to content

Instantly share code, notes, and snippets.

@rndmcnlly
Created February 27, 2010 01:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rndmcnlly/316398 to your computer and use it in GitHub Desktop.
Save rndmcnlly/316398 to your computer and use it in GitHub Desktop.
% This program is intended to be used with LPARSE / SMODELS
% see: http://www.tcs.hut.fi/Software/smodels/
%%%%
%%%% EXAMPLE STORY
%%%% (generated with the constraints shown at the very end of the file)
%% REQUIREMENT
% Tell me a story about an Alice, a Bob, and an Eve. I'd like to see Eve be
% the aggressor, but I don't want to see either Alice or Bob in this role.
% Please include a scene where Alice comforts Bob and one where Bob realizes
% he was been tricked. Also show me Bob killing Alice (gasp!), but also show
% him mourning her. Don't do anything dumb like make Eve kill herself to make
% her an aggressor the easy way, I want some drama.
%
% Oh, and don't drag this out beyond seven actions.
%% CHARACTERS
% Eve is a powerfully insane, devious woman. % Bob is strong, and Eve is
% somewhat of a trickster.
%% NARRATIVE
% Our scene began when Eve tied up Alice, restraining her.
%
% "It's going to be alright", she told Bob, "we can withstand Eve."
%
% Alice reluctantly whispered something into Bob's ear that made his face
% turn sour. She was manipulating him! Bob turned to Alice and silenced her
% once and for all in the name of an unspeakable betrayal, regretting that
% the situation had come this far.
%
% Stunned, staring at Eve, he realized Alice's intentions, as much as he
% wished he hadn't. Angered at his own actions, he turned to Eve, killing her
% for her very involvement.
%
% Alone, Bob mourned the loss of Alice, but at the same time knew her
% manipulation had brought it on herself.
%% ANALYSIS
% But why did Alice indirectly set in place her own destruction? Perhaps
% she made a terrible mistake when attempting to convince Bob to turn on Eve
% sooner. Or maybe people in this universe don't have the means to reason
% through the indirect effects of their actions.
%
% Alice, Bob and Eve are all victims in this story as each was tricked and/or
% killed, but Eve is the only real aggressor. Eve tied up Alice unprovoked,
% setting the regrettable dance between Alice and Bob in motion.
%% FORMAL LOGIC VERSION (this is what the program actually outputs)
% has_trait(insane,eve).
% has_trait(strong,eve).
% has_trait(trickster,eve).
% has_trait(strong,bob).
% has_trait(trickster,alice).
%
% happens(eve,ties_up,alice,0).
% happens(alice,comforts,bob,1).
% happens(alice,tricks,bob,2).
% sentiment(alice,tricks,bob,2,regret).
% happens(bob,kills,alice,3).
% happens(bob,realizes,bob,4).
% sentiment(bob,realizes,bob,4,regret).
% happens(bob,kills,eve,5).
% sentiment(bob,kills,eve,5,regret).
% happens(bob,mourns,alice,6).
% sentiment(bob,mourns,alice,6,regret).
%
% has_role(victim,alice).
% has_role(victim,bob).
% has_role(aggressor,eve).
% has_role(victim,eve).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% VARIABLE DOMAINS
%%%%
% domains
#domain subject(S).
#domain verb(V).
#domain object(O).
#domain t(T).
#domain t(T1).
#domain t(T2).
#domain role(R).
#domain person(P).
#domain person(P1).
#domain person(P2).
#domain person(PQ).
#domain feeling(F).
#domain detail(D).
#domain attribute(A).
#domain trait(I).
subject(P) :- person(P).
#hide subject(_).
object(P) :- person(P).
#hide object(_).
%%%%
%%%% TRAITS
%%%%
trait(strong).
trait(trickster).
trait(insane).
#hide trait(_).
:- required_trait(I,P), not has_trait(I,P).
:- forbidden_trait(I,P), has_trait(I,P).
%%%%
%%%% ROLES
%%%%
has_role(R,P) :-
role_satisfied(R,P),
not role_blocked(R,P).
:- required_role(R,P), not has_role(R,P).
:- forbidden_role(R,P), has_role(R,P).
#hide role(_).
#hide role_satisfied(_,_).
#hide role_blocked(_,_).
%% ROLE: victim (gets harmed)
role(victim).
role_satisfied(victim,P) :-
harms(V),
happens(S,V,P,T),
not harm_nullified(S,V,P,T).
harm_nullified(S,V,O,T) :-
context(S,V,O,T,D),
unharms(D,V).
harm_nullified(S,V,S,T) :-
sentiment(S,V,S,T,desire).
#hide harm_nullified(_,_,_,_).
%% ROLE: aggressor (intentionally harms)
role(aggressor).
role_satisfied(aggressor,P) :-
harms(V),
happens(P,V,O,T),
not aggression_nullified(P,V,O,T).
aggression_nullified(S,V,O,T) :-
sentiment(S,V,O,T,regret).
aggression_nullified(S,V,O,T) :-
holds(S,manipulated,T).
#hide aggression_nullified(_,_,_,_).
%% ROLE: bystander
role(bystander).
role_satisfied(bystander,P).
role_blocked(bystander,P) :-
happens(P,V,O,T).
% TODO: blocking?
%%%%
%%%% EVENTS
%%%%
#const t_max=1.
t(0..t_max).
#hide t(_).
action_satisfied(S,V,O) :- happens(S,V,O,T).
#hide action_satisfied(_,_,_).
:- required_action(S,V,O), not action_satisfied(S,V,O).
:- forbidden_action(S,V,O), happens(S,V,O,T).
:- happens(S,V,O,T), not possible(S,V,O,T).
initiated(O,A,T) :-
happens(S,V,O,T),
initiates(S,V,O,A,T).
terminated(O,A,T) :-
happens(S,V,O,T),
terminates(S,V,O,A,T).
holds(O,A,T+1) :-
holds(O,A,T),
not terminated(O,A,T).
-holds(O,A,T+1) :-
-holds(O,A,T),
not initiated(O,A,T).
holds(O,A,T+1) :-
initiated(O,A,T).
-holds(O,A,T+1) :-
terminated(O,A,T).
holds(O,A,0) :- initially(A).
-holds(O,A,0) :- not initially(A).
#hide holds(_,_,_).
#hide initiated(_,_,_).
#hide terminated(_,_,_).
#hide initiates(_,_,_,_,_).
#hide terminates(_,_,_,_,_).
%%%%
%%%% ABDUCIBLES
%%%%
{ has_trait(Tr,P) } :- trait(Tr).
1 { happens(Su,Ve,Ob,T):subject(Su):verb(Ve):object(Ob) } 1.
{ sentiment(S,V,O,T,Fe):feeling(Fe) } 1 :- happens(S,V,O,T).
{ context(S,V,O,T,D) } :- contextualizes(D,V), happens(S,V,O,T).
%% author goals:
%%%%
%%%% ATTRIBUTES (fluents, initially false if not set true)
%%%%
attribute(alive).
attribute(manipulated).
attribute(restrained).
#hide attribute(_).
initially(alive).
#hide initially(_).
%%%%
%%%% ACTIONS
%%%%
verb(ties_up).
verb(tricks).
verb(kills).
verb(speaks_to).
verb(mourns).
verb(realizes).
verb(comforts).
#hide verb(_).
harms(ties_up).
harms(tricks).
harms(kills).
#hide harms(_).
#hide possible(_,_,_,_).
stronger_than(S,O) :- has_trait(strong,S), not has_trait(strong,O).
stronger_than(S,O) :- not has_trait(weak,S), has_trait(weak,O).
#hide stronger_than(_,_).
different_or_insane(S,O) :- S != O.
different_or_insane(S,O) :- has_trait(insane,S).
#hide different_or_insane(_,_).
possible(S,ties_up,O,T) :-
stronger_than(S,O),
holds(S,alive,T),
not holds(S,restrained,T),
not holds(O,restrained,T),
S != O.
possible(S,tricks,O,T) :- % only works between rational folk
not has_trait(insane,S),
not has_trait(insane,O),
has_trait(trickster,S),
holds(S,alive,T),
holds(O,alive,T),
S != O.
possible(S,kills,O,T) :-
holds(S,alive,T),
holds(O,alive,T),
not holds(S,restrained,T).
possible(S,speaks_to,O,T) :-
different_or_insane(S,O),
holds(S,alive,T),
holds(O,alive,T).
possible(S,mourns,O,T) :-
not has_role(aggressor,O),
holds(S,alive,T),
not holds(O,alive,T).
possible(S,realizes,S,T) :-
holds(S,alive,T),
holds(S,manipulated,T).
possible(S,comforts,O,T) :-
holds(S,restrained,T),
has_role(victim,O),
holds(S,alive,T),
holds(O,alive,T).
initiates(S,ties_up,O,restrained,T).
initiates(S,tricks,O,manipulated,T).
terminates(S,realizes,S,manipulated,T).
terminates(S,kills,O,alive,T).
%%%%
%%%% FEELINGS (create sentiments)
%%%%
feeling(desire).
feeling(regret).
#hide feeling(_).
%%%%
%%%% DETAILS (contextualize actions)
%%%%
contextualizes(weak_ropes,ties_up).
#hide contextualizes(_,_).
unharms(weak_ropes,ties_up).
#hide unharms(_,_).
detail(Detail) :- contextualizes(Detail,V).
#hide detail(_).
%%%%
%%%% PROBLEM SPECIFICATION
%%%%
#hide person(_).
#hide required_role(_,_).
#hide forbidden_role(_,_).
#hide required_trait(_,_).
#hide forbidden_trait(_,_).
#hide required_action(_,_,_).
#hide forbidden_action(_,_,_).
person(alice).
person(bob).
person(eve).
%forbidden_role(aggressor,alice).
%forbidden_role(aggressor,bob).
%required_role(aggressor,eve).
%required_action(alice,comforts,bob).
%required_action(bob,realizes,bob).
%forbidden_action(eve,kills,eve).
%required_action(bob,kills,alice).
%required_action(bob,mourns,alice).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment