2:- dynamic iAmAt/1. 3:- dynamic simMood/1. 4:- dynamic working/1. 5:- dynamic atMultiple/3. 6:- dynamic lastUsed/1. 7:- dynamic expired/1. 8iAmAt(fridge).
9simMood(50).
10atMultiple(coin,trashcan,2).
11atMultiple(fridge_part,trashcan,1).
12atMultiple(oven_part,trashcan,1).
13atMultiple(food,fridge,1).
14usable(fridge_part,fridge).
15usable(oven_part,oven).
16usable(coin,computer).
17usable(food,oven).
18simCallable(singAGram).
19simCallable(fridgeTechnician).
20simCallable(ovenTechnician).
21path(fridge,w,oven).
22path(fridge,n,trashcan).
23path(fridge,e,computer).
24path(computer,e,bed).
25path(oven,e,fridge).
26path(trashcan,s,fridge).
27path(computer,w,fridge).
28path(bed,w,computer).
29lastUsed(nothing).
30
31hasMood(X):-
32 simMood(Mood),
33 Mood>X.
34updateMood(Delta):-
35 retract(simMood(Mood)),
36 NewMood is Mood+Delta,
37 assert(simMood(NewMood)),
38 NewMood >= 100,
39 finish.
40updateMood(_).
41
42updateLastUsedObject(X):-
43 lastUsed(Object),
44 retract(lastUsed(Object)),
45 assert(lastUsed(X)).
46
47at(X,Y):-
48 atMultiple(X,Y,Count),
49 Count > 0.
50
51updateCount(X,Place,Delta):-
52 at(X,Place),
53 retract(atMultiple(X,Place,OldCount)),
54 NewCount is OldCount+Delta,
55 assert(atMultiple(X,Place,NewCount)).
56updateCount(X,Place,Delta):-
57 assert(atMultiple(X,Place,Delta)).
58
59go(Direction):-
60 iAmAt(Place),
61 path(Place,Direction,NextLocation),
62 retract(iAmAt(Place)),
63 assert(iAmAt(NextLocation)),
64 look,!.
65go(_):-
66 write('You cannot go that way').
67
68s:-
69 go(s).
70w:-
71 go(w).
72e:-
73 go(e).
74n:-
75 go(n).
76i:-
77 at(X,sim),
78 write('there is a '),write(X),write(' in your pocket'),nl,
79 fail.
80i.
81
82describe(fridge) :-
83 working(fridge),
84 write('Here is a fridge. The fridge is working now. You can grab food from fridge and cook it in the oven'), nl,!.
85
86describe(fridge):-
87 write('Here is a fridge. The fridge is broken. You cannot open it. Try to get yourself some parts to fix it. You can obtain parts from salvaging the trash can, or call a repair techinician for 1 coin.'),nl.
88
89describe(oven):-
90 working(oven),
91 at(food,sim),
92 write('Here is an oven. The oven is working now. You can cook food to boost your mood'),nl,!.
93
94describe(oven):-
95 working(oven),
96 write('Here is an Oven. The oven is working now. But you don\'t have any food. Get some from the fridge'),nl,!.
97
98describe(oven):-
99 write('Here is an oven. The oven is broken. You cannot use it. Try to get yourself some parts to fix it. You can obtain parts from salvaging the trash can, or call a repair techinician for 1 coin.'),nl.
100
101describe(bed):-
102 write('Here is a bed. Have a good rest! You can elevate your mood up to 50 directly.'),nl.
103
104describe(trashcan):-
105 write('Here is a trash can. The trash can is a good place to find surprising stuff.'),nl.
106
107describe(computer):-
108 \+ expired(computer),
109 write('You\'re at a computer. The computer has had the latest Sims game nstalled! Why not give it a try to boost mood?'),nl,!.
110
111describe(computer):-
112 write('You\'re at a computer. However you cannot use it because its only game has expired.'),nl.
113
114instructions :-
115 nl,
116 write('Enter commands using standard Prolog syntax.'), nl,
117 write('Available commands are:'), nl,
118 write('start. -- to start the game.'), nl,
119 write('stat. -- show current sim\'s mood value.'),nl,
120 write('n. s. e. w. -- to go in that direction.'), nl,
121 write('i -- show what the player is holding.'),nl,
122 write('take(Object). -- to pick up an object.'), nl,
123 write('use(Object). -- to use an object in your pocket at the current location.'), nl,
124 write('use. -- to use an object.'), nl,
125 write('look. -- to look around you again.'), nl,
126 write('instructions. -- to see this message again.'), nl,
127 write('halt. -- to end the game and quit.'), nl,
128 write('dial. -- to call a service. call [fridge/oven]RepairTechnician to call a repair technician. Call SingAGram to call for an SingAGram to boost your mood. Both services cost 1 coin.'),nl,
129 nl.
130take(X):-
131 at(X,sim),
132 write('You have no room to hold it!'),
133 nl,!,fail.
134
135take(X):-
136 iAmAt(Place),
137 at(X,Place),
138 updateCount(X,Place,-1),
139 updateCount(X,sim,1),
140 write('Ok.'),
141 nl,!.
142
143take(_):-
144 write('The item isn\'t here.'),
145 nl.
146
147use:-
148 iAmAt(fridge),
149 working(fridge),
150 at(food,fridge),
151 hasMood(10),!,
152 take(food),
153 updateMood(-10),
154 write('You searched hard and found some raw food.'),nl,
155 updateLastUsedObject(fridge),!.
156use:-
157 iAmAt(fridge),
158 working(fridge),
159 hasMood(10),
160 write('You searched hard and found no food. It took effort. Your mood went down by 10.'),nl,
161 updateLastUsedObject(fridge),!.
162
163use:-
164 iAmAt(fridge),
165 hasMood(10),
166 write('You cannot use the fridge because it is broken.'),nl,!.
167use:-
168 iAmAt(fridge),
169 write('Your sim is too tired to do that. Try get some sleep.'),nl,!.
170
171use:-
172 iAmAt(oven),
173 working(oven),
174 at(food,sim),
175 write('You cooked some food. You elevated your mood by 20.'),nl,
176 updateCount(food,sim,-1),
177 updateMood(20),
178 updateLastUsedObject(oven),!.
179use:-
180 iAmAt(oven),
181 working(oven),
182 at(food,sim),
183 write('Your sim is too tired to operate the oven. Try get some sleep.'),nl,!.
184
185use:-
186 iAmAt(oven),
187 working(oven),
188 write('You must get food first before you can use the oven. Food is in the fridge'),nl,!.
189use:-
190 iAmAt(oven),
191 write('The oven is broken. You must fix it before you can use it.'),nl,!.
192use:-
193 iAmAt(trashcan),
194 lastUsed(trashcan),
195 write('You just searched the trash can. It\'s empty now. Try salvage it again later for surpirses.'),nl,!.
196use:-
197 iAmAt(trashcan),
198 at(fridge_part,trashcan),
199 hasMood(20),
200 take(fridge_part),
201 write('Through hard dumpster diving, you found a fridge part. It seems like you can you can use it to fix your fridge. Your mod went down by 20 because the trash can smelled bad.'),nl,
202 updateMood(-20),
203 updateLastUsedObject(trashcan),!.
204use:-
205 iAmAt(trashcan),
206 at(oven_part,trashcan),
207 hasMood(20),
208 take(oven_part),
209 write('Through hard dumpster diving, you found an oven part. It seems like you can use it to fix your oven. Your mood went down by 20 because the trash can smelled bad.'),nl,
210 updateMood(-20),
211 updateLastUsedObject(trashcan),!.
212use:-
213 iAmAt(trashcan),
214 working(oven),
215 working(fridge),
216 at(coin,trashcan),
217 hasMood(20),
218 write('Through hard dumpster diving, you found a coin. You can use it to do whatever you want. Your mood went down by 20 because the trash can smelled bad.'),nl,
219 updateLastUsedObject(trashcan),!,
220 take(coin),updateMood(-20),!.
221use:-
222 iAmAt(trashcan),
223 hasMood(20),
224 write('Oh no. You found nothing here after a hard search. You mood went down by 20.'),nl,
225 updateMood(-20),!.
226use:-
227 iAmAt(trashcan),
228 write('You\'re too tired to dumpster dive. You need to take a rest.'),nl,!.
229
230use:-
231 iAmAt(computer),
232 \+ expired(computer),
233 \+ lastUsed(computer),
234 write('The Sims game is so much fun. You mood went up by 15. Unfortunately its licence just went expired, so your sim can no longer play it unless you pay 1 coin by using the pay command.'),nl,
235 updateMood(15),
236 updateLastUsedObject(computer),
237 assert(expired(computer)),!.
238use:-
239 iAmAt(computer),
240 \+ expired(computer),
241 write('Your eyes are sour because of the intriguing Sims game. Take a break before playing it again!'),nl,!.
242use:-
243 iAmAt(computer),
244 write('Your copy of The Sims game has expired. You need to pay 1 coin to renew your Sims game.'),nl,!.
245use:-
246 iAmAt(bed),
247 hasMood(50),
248 write('You are energized. You cannot fall into sleep.'),nl,
249 updateLastUsedObject(bed),!.
250use:-
251 iAmAt(bed),
252 simMood(Mood),
253 updateMood(50-Mood),
254 write('Your mood went up to 50 after a tight sleep.'),nl,
255 updateLastUsedObject(bed),!.
256
257use(Object):-
258 \+ at(Object,sim),
259 write('You do not have '),
260 write(Object),
261 write(' with you.'),nl,!.
262use(Object):-
263 iAmAt(Place),
264 \+ usable(Object,Place),
265 write('You do not know how to use '),
266 write(Object),
267 write(' at '),
268 write(Place),nl,!.
269use(_):-
270 iAmAt(fridge),
271 hasMood(20),
272 updateMood(-20),
273 write('You used your fridge part to fix the fridge. Your fridge is working now! Your mood went down by 20 due to the hard work.'),nl,
274 updateCount(fridge_part,sim,-1),
275 assert(working(fridge)),!.
276
277use(_):-
278 iAmAt(oven),
279 hasMood(20),
280 updateMood(-20),
281 write('You used your oven part to fix the oven. Your oven is working now! Your mood went down by 20 due to the hard work.'),nl,
282 updateCount(oven_part,sim,-1),
283 assert(working(oven)),!.
284
285
286use(_):-
287 iAmAt(computer),
288 expired(computer),
289 write('You used your coin to renew your The Sims game licence. You can play it one more time!'),nl,!,
290 retract(expired(computer)),
291 updateCount(coin,sim,-1),!.
292use(_):-
293 iAmAt(computer),
294 write('You do not need a coin to activate the game. Hurray up and play it when it\'s free!'),nl,!.
295
296use(_):-
297 write('You are too tired to fix anything. Try to get some sleep.'),nl,!.
298
299dial(Someone):-
300 \+ simCallable(Someone),
301 write('You forgot the number of '),
302 write(Someone),
303 write('.'),nl,!.
304dial(_):-
305 \+ at(coin,sim),
306 write('You do not have enough coin to call anyone'),nl,!.
307
308dial(Someone):-
309 Someone = fridgeTechnician,
310 assert(working(fridge)),
311 write('The fridge technician came and inspected your fridge and made sure your fridge is working properly. You lost 1 coin to pay for his work.'),nl,!.
312
313dial(Someone):-
314 Someone = ovenTechnician,
315 assert(working(oven)),
316 write('The oven technician came and inspected your oven and made sure your oven is working properly. You paid 1 coin to him for his hard work.'),nl,!.
317
318dial(_):-
319 write('\'Da-Da-Di-Da-Di, we like the party.\' sings the sing-a-gram. Your mood is elevated by 30 for this beautiful song. You lost 1 coin at the same time, though.'),nl
320 ,updateMood(30),!.
321
322
323look:-
324 iAmAt(Place),
325 describe(Place),
326 nl.
327start:-
328 instructions,
329 look.
330
331finish :-
332 nl,
333 write('Congratulations! Your mood is now maximized. You have reached your goal. Please enter the halt. command.'),
334 nl, !.
335stat:-
336 simMood(Mood),
337 write('Your current mood is '),write(Mood),write('.')