Skip to content

Instantly share code, notes, and snippets.

@paniq
Last active August 15, 2024 09:52
Show Gist options
  • Save paniq/2ab7c75bbdda197a492879302e94464d to your computer and use it in GitHub Desktop.
Save paniq/2ab7c75bbdda197a492879302e94464d to your computer and use it in GitHub Desktop.
pg := DRIL:
enum Place : i64
Foyer
LivingRoom
Office
Kitchen
Bedroom
Bathroom
Cellar
using Place
.event start place entered idle prompt action list-actions leave exit
start :-
place Foyer :- start
.event
enter_foyer
enter_living_room
enter_office
enter_kitchen
enter_bedroom
enter_bathroom
enter_cellar
enter_foyer :- case place Foyer
enter_living_room :- case place LivingRoom
enter_office :- case place Office
enter_kitchen :- case place Kitchen
enter_bedroom :- case place Bedroom
enter_bathroom :- case place Bathroom
enter_cellar :- case place Cellar
entered :- enter_foyer, print "You are standing in the foyer."
entered :- enter_living_room, print "You are standing in the living room."
entered :- enter_office, print "You are standing in the office."
entered :- enter_kitchen, print "You are standing in the kitchen."
entered :- enter_bedroom, print "You are standing in the bedroom."
entered :- enter_bathroom, print "You are standing in the bathroom."
entered :- enter_cellar, print "You are standing in the cellar."
idle :- not entered, print "todo: place" place
exit :- leave, print "Goodbye."
idle :- entered
list-actions :- idle
prompt :- idle, print "\nChoose an action:"
action x :- prompt, list-actions, x = scan, print ""
#do
.event debug
debug :- print "chose" action
# turn declarative statement into error handler :)
.event maxaction handled oops status
handled :- leave
handled :- _0 = action >= 1, _1 = action <= maxaction, _2 = _0 and _1, ? _2
oops :- action, not handled
status :- oops, print "You made an indescribable choice.\n\n"
# hack to trigger restating the obvious
place place :- status
do
# useless flashlight DLC!
.event
flashlight
flashlight-on
flashlight-off
flashlight-toggled
flashlight 0 :- start
flashlight-off :- entered, case flashlight 0
flashlight-on :- entered, case flashlight 1
prompt :- list-actions, print "0) Toggle flashlight."
idle :- flashlight-off, print "It is dark."
idle :- flashlight-on, print "Your flashlight illuminates the place."
flashlight-toggled :- case action 0
handled :- case action 0
flashlight x :- flashlight-toggled, print "You toggle your flashlight.",
\ x = not flashlight
status :- flashlight-toggled
prompt :- list-actions, enter_foyer, print
""""1) Leave the apartment.
2) Go to living room.
3) Go to the office.
4) Go down to the cellar.
leave :- enter_foyer, case action 1
place LivingRoom :- enter_foyer, case action 2
place Office :- enter_foyer, case action 3
place Cellar :- enter_foyer, case action 4
maxaction 4 :- enter_foyer
prompt :- list-actions, enter_living_room, print
""""1) Go back to foyer.
2) Go to the kitchen.
3) Go to the bedroom.
4) Go to the office.
place Foyer :- enter_living_room, case action 1
place Kitchen :- enter_living_room, case action 2
place Bedroom :- enter_living_room, case action 3
place Office :- enter_living_room, case action 4
maxaction 4 :- enter_living_room
prompt :- list-actions, enter_office, print
""""1) Go back to foyer.
2) Go to the living room.
place Foyer :- enter_office, case action 1
place LivingRoom :- enter_office, case action 2
maxaction 2 :- enter_office
prompt :- list-actions, enter_kitchen, print
""""1) Go back to living room.
place LivingRoom :- enter_kitchen, case action 1
maxaction 1 :- enter_kitchen
prompt :- list-actions, enter_bedroom, print
""""1) Go back to living room.
2) Go to bathroom.
place LivingRoom :- enter_bedroom, case action 1
place Bathroom :- enter_bedroom, case action 2
maxaction 2 :- enter_bedroom
prompt :- list-actions, enter_bathroom, print
""""1) Go back to bedroom.
place Bedroom :- enter_bathroom, case action 1
maxaction 1 :- enter_bathroom
prompt :- list-actions, enter_cellar, print
""""1) Go back to foyer.
place Foyer :- enter_cellar, case action 1
maxaction 1 :- enter_cellar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment