-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseaduck.js
109 lines (105 loc) · 2.74 KB
/
seaduck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
let seaduck = require("seaduck")
require('seedrandom');
let seed = 12345
Math.seedrandom(seed);
console.log(`In the beginning, there was the seed, and the seed was ${seed}.\n`);
let n = new seaduck.Narrative({
"nouns": [
{
"name": "Chris",
"properties": {
"sleepiness": 0
},
"tags": ["person"]
},
{
"name": "king-size bed",
"properties": {
"occupied": false
},
"tags": ["bed"]
},
],
"actions": [
{
"match": ["Chris"],
"when": function(a) {
return a.properties.sleepiness < 10;
},
"action": function*(a) {
a.properties.sleepiness++;
yield new seaduck.StoryEvent("moreSleepy", a);
}
},
{
"match": ["Chris"],
"when": function(a) {
return a.properties.sleepiness == 7;
},
"action": function*(a) {
yield new seaduck.StoryEvent("reallySleepy", a);
}
},
{
"match": ["Chris", "king-size bed"],
"when": function(a, b) {
return a.properties.sleepiness >= 10
&& !this.isRelated("sleepingIn", a, b)
&& !b.properties.occupied;
},
"action": function*(a, b) {
this.relate("sleepingIn", a, b);
b.properties.occupied = true;
yield new seaduck.StoryEvent("getsInto", a, b);
}
},
{
"match": ["Chris", "king-size bed"],
"when": function(a, b) {
return this.isRelated("sleepingIn", a, b);
},
"action": function*(a, b) {
yield new seaduck.StoryEvent("asleep", a, b);
}
}
],
"traceryDiscourse": {
"moreSleepy": [
"#nounA# yawns.",
"#nounA#'s eyelids droop.",
"#nounA# nods off for a second, then perks up.",
"#nounA# says, 'I could use a cup of coffee.'",
"'I don't think I can stay awake a minute longer,' says #nounA# to no one in particular.",
"#nounA# checks their watch."
],
"adverb": ["at last", "finally", "not a moment too soon"],
"getsInto": [
"#adverb.capitalize#, #nounA# gets into the #nounB#.",
"#adverb.capitalize#, #nounA# climbs into the #nounB#."
],
"asleep": [
"#nounA# is asleep in the #nounB#.",
"#nounA# snores beneath the covers of the #nounB#.",
"#nounA# sleep-mumbles peacefully in the #nounB#."
],
"reallySleepy": [
"#nounA# is really sleepy.",
"'I'm just about ready to hit the hay,' says #nounA#.",
"You can tell just by looking at them that #nounA# really needs some rest."
],
"_end": [
"Good night."
]
}
});
for (let i = 0; i < 100; i++) {
let storyEvents = n.stepAndRender();
if (storyEvents.length > 0) {
for (let ev of storyEvents) {
console.log(ev);
}
}
else {
break;
}
}