This repository has been archived by the owner on Nov 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayable-only.txt
318 lines (306 loc) · 7.83 KB
/
playable-only.txt
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
;; Calculate win
(deffunction calculate-win (?ascore ?cscore)
(bind ?advantage (- ?ascore ?cscore)) ;; difference in scores
(if (>= ?advantage 2) then (bind ?result win))
(if (<= ?advantage -2) then (bind ?result loss))
(if (eq ?advantage 0) then (bind ?result draw))
(if (eq ?advantage 1) then
(bind ?luck (mod (random) 2))
(if (eq ?luck 1) then (bind ?result win)
else (bind ?result draw)
)
)
(if (eq ?advantage -1) then
(bind ?luck (mod (random) 2))
(if (eq ?luck 0) then (bind ?result loss)
else (bind ?result draw)
)
)
(return ?result)
)
;; Creature template
(deftemplate creature
(slot name)
(slot weapon)
(slot speed)
(slot intelligence)
(slot attitude)
)
;; Player Stats and Items
(deffacts adventurer
(creature
(name Adventurer)
(weapon 2)
(speed 3)
(intelligence 4)
)
;; Gadget that should be removed after used
;; Effect +2weapon +3speed +2int
(specials flashgun jetpack textbook)
)
;; Reset stats after using a special
(defrule reset-stats
(declare (salience 200))
?adventurer <- (creature (name Adventurer)
(weapon ?wep)
(speed ?speed)
(intelligence ?int)
)
?u <- (just-use ?gadget)
(not (creature (name ~Adventurer)))
=>
(printout t "Your stats have reset back to normal." crlf crlf)
(retract ?u)
(if (eq ?gadget flashgun)
then
(modify ?adventurer (weapon (- ?wep 2)))
)
(if (eq ?gadget jetpack)
then
(modify ?adventurer (speed (- ?speed 3)))
)
(if (eq ?gadget textbook)
then
(modify ?adventurer (intelligence (- ?int 2)))
)
)
;; Turn
(deffacts game-facts
(turn-counter 0)
)
;; Generate creature
(defrule gen-creature
(not (creature (name ~Adventurer)))
(turn-counter ?n) ;; updating this will refresh this rule
=>
(bind ?wep (+ 1 (mod (random) 5)))
(bind ?speed (+ 1 (mod (random) 5)))
(bind ?int (+ 1 (mod (random) 5)))
(bind ?att (+ 1 (mod (random) 3)))
(if (eq ?att 1)
then (bind ?atttext scared))
(if (eq ?att 2)
then (bind ?atttext curious))
(if (eq ?att 3)
then (bind ?atttext aggressive))
(assert (creature
(name (random))
(weapon ?wep)
(speed ?speed)
(intelligence ?int)
(attitude ?atttext)))
;;; The next lines are all for user interface purposes
(bind ?weptypeno (+ 1 (mod (random) 3)))
;; Weapon description
(if (eq ?weptypeno 1)
then (bind ?weptype teeth))
(if (eq ?weptypeno 2)
then (bind ?weptype claws))
(if (eq ?weptypeno 3)
then (bind ?weptype rocks))
(if (eq ?wep 1)
then (bind ?weptext "very blunt"))
(if (eq ?wep 2)
then (bind ?weptext "blunt"))
(if (eq ?wep 3)
then (bind ?weptext "fairly sharp"))
(if (eq ?wep 4)
then (bind ?weptext "sharp"))
(if (eq ?wep 5)
then (bind ?weptext "razor sharp"))
;; Speed description
(if (eq ?speed 1)
then (bind ?speedtext "very slow"))
(if (eq ?speed 2)
then (bind ?speedtext "slow"))
(if (eq ?speed 3)
then (bind ?speedtext "fairly fast"))
(if (eq ?speed 4)
then (bind ?speedtext "fast"))
(if (eq ?speed 5)
then (bind ?speedtext "lightning quick"))
;; Intelligence description
(if (eq ?int 1)
then (bind ?inttext "very dumb"))
(if (eq ?int 2)
then (bind ?inttext "dumb"))
(if (eq ?int 3)
then (bind ?inttext "fairly smart"))
(if (eq ?int 4)
then (bind ?inttext "smart"))
(if (eq ?int 5)
then (bind ?inttext "really smart"))
;; Monster description
(printout t "A creature appears!" crlf
"It has " ?weptext " " ?weptype "." crlf
"It looks " ?speedtext " and " ?inttext "." crlf
"It acts in a " ?atttext " manner." crlf crlf)
)
;; Choose gadget
(defrule choose_special
(creature (name ~Adventurer))
(specials $?gadgets)
(test (>= (length$ $?gadgets) 1))
(not (just-use ?))
(turn-counter ?n)
=>
(printout t "Choose gadget from " $?gadgets " :" crlf
"[1] Flashgun" crlf
"[2] Jetpack" crlf
"[3] Textbook" crlf
"[4] Nothing" crlf
)
(bind ?gadget (read))
(if (eq ?gadget 1)
then (assert (use flashgun)))
(if (eq ?gadget 2)
then (assert (use jetpack)))
(if (eq ?gadget 3)
then (assert (use textbook)))
)
;; Use gadget
(defrule use-gadget
(declare (salience 190))
?adventurer <- (creature (name Adventurer)
(weapon ?wep)
(speed ?speed)
(intelligence ?int)
)
?u <- (use ?gadget)
?s <- (specials $?first ?gadget $?last)
=>
(retract ?u)
(retract ?s)
(assert (just-use ?gadget))
(printout t "You used " ?gadget "." crlf crlf)
(assert (specials $?first $?last))
(if (eq ?gadget flashgun)
then (modify ?adventurer (weapon (+ ?wep 2))))
(if (eq ?gadget jetpack)
then (modify ?adventurer (speed (+ ?speed 3))))
(if (eq ?gadget textbook)
then (modify ?adventurer (intelligence (+ ?int 2))))
)
;; Choose action
(defrule choose-action
;; A creature exists which isn't the Adventurer
(creature (name ~Adventurer))
=>
(printout t "Choose an action [type 1-5]:" crlf
"[1] Fight" crlf
"[2] Flee" crlf
"[3] Hypnotise" crlf
"[4] Do nothing" crlf
)
(bind ?act (read))
(if (eq ?act 1)
then (assert (action fight)))
(if (eq ?act 2)
then (assert (action flee)))
(if (eq ?act 3)
then (assert (action hypnotise)))
(if (eq ?act 4)
then (assert (action do_nothing)))
)
;; Fight
(defrule fight
?turn <- (turn-counter ?n)
(creature (name Adventurer)
(weapon ?aWeapon))
?c <- (creature (name ~Adventurer)
(weapon ?cWeapon))
?a <- (action fight)
=>
(retract ?a)
(bind ?result (calculate-win ?aWeapon ?cWeapon))
(if (eq ?result win)
then (printout t "You killed the creature." crlf crlf))
(if (eq ?result draw)
then (printout t "It’s a draw and the creature ran away." crlf crlf))
(if (eq ?result loss)
then (printout t "The creature killed you." crlf
"You lasted " ?n " turns." crlf crlf)
(halt))
(if (neq ?result loss)
then
(retract ?turn)
(retract ?c)
(assert (turn-counter (+ ?n 1)))
)
)
;; Flee
(defrule flee
?turn <- (turn-counter ?n)
(creature (name Adventurer)
(speed ?aSpeed))
?c <- (creature (name ~Adventurer)
(speed ?cSpeed))
?a <- (action flee)
=>
(retract ?a)
(bind ?result (- ?aSpeed ?cSpeed))
(if (> ?result 0)
then (printout t "You ran away." crlf crlf))
(if (eq ?result 0)
then (printout t "It’s a draw and the creature ran away." crlf crlf))
(if (< ?result 0)
then (printout t "The creature caught and killed you." crlf
"You lasted " ?n " turns." crlf crlf)
(halt))
(if (>= ?result 0)
then
(retract ?turn)
(retract ?c)
(assert (turn-counter (+ ?n 1)))
)
)
;; Hypnotise
(defrule hypnotise
?turn <- (turn-counter ?n)
(creature (name Adventurer)
(intelligence ?aInt))
?c <- (creature (name ~Adventurer)
(intelligence ?cInt))
?a <- (action hypnotise)
=>
(retract ?a)
(bind ?result (calculate-win ?aInt ?cInt))
(if (eq ?result win)
then (printout t "The creature falls asleep." crlf crlf))
(if (eq ?result draw)
then (printout t "It’s a draw and the creature runs away." crlf crlf))
(if (eq ?result loss)
then (printout t "The creature hypnotised and killed you." crlf
"You lasted " ?n " turns." crlf crlf)
(halt))
(if (neq ?result loss)
then
(retract ?turn)
(retract ?c)
(assert (turn-counter (+ ?n 1)))
)
)
;; Do nothing
(defrule do_nothing
?turn <- (turn-counter ?n)
(creature (name Adventurer))
?c <- (creature (name ~Adventurer)
(attitude ?att))
?a <- (action do_nothing)
=>
(retract ?a)
(if (eq ?att scared)
then (printout t "The " ?att " creature ran away." crlf crlf))
(if (eq ?att curious)
then (printout t "The " ?att " creature watches you pass by." crlf crlf))
(if (eq ?att aggressive)
then (printout t "The " ?att " creature killed you." crlf
"You lasted " ?n " turns." crlf crlf)
(halt))
(if (neq ?att aggressive)
then
(retract ?turn)
(retract ?c)
(assert (turn-counter (+ ?n 1)))
)
)