-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfig25_6.pl
65 lines (44 loc) · 1.44 KB
/
fig25_6.pl
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
% Figure 25.6 Two problem definitions for explanation-based generalization.
% For compatibility with some Prologs the following predicates
% are defined as dynamic:
:- dynamic gives/3, would_please/2, would_comfort/2, feels_sorry_for/2,
go/3, move/2, move_list/2.
% A domain theory: about gifts
gives( Person1, Person2, Gift) :-
likes( Person1, Person2),
would_please( Gift, Person2).
gives( Person1, Person2, Gift) :-
feels_sorry_for( Person1, Person2),
would_comfort( Gift, Person2).
would_please( Gift, Person) :-
needs( Person, Gift).
would_comfort( Gift, Person) :-
likes( Person, Gift).
feels_sorry_for( Person1, Person2) :-
likes( Person1, Person2),
sad( Person2).
feels_sorry_for( Person, Person) :-
sad( Person).
% Operational predicates
operational( likes( _, _)).
operational( needs( _, _)).
operational( sad( _)).
% An example situation
likes( john, annie).
likes( annie, john).
likes( john, chocolate).
needs( annie, tennis_racket).
sad( john).
% Another domain theory: about lift movement
% go( Level, GoalLevel, Moves) if
% list of moves Moves brings lift from Level to GoalLevel
go( Level, GoalLevel, Moves) :-
move_list( Moves, Distance), % A move list and distance travelled
Distance =:= GoalLevel - Level.
move_list( [], 0).
move_list( [Move1 | Moves], Distance + Distance1) :-
move_list( Moves, Distance),
move( Move1, Distance1).
move( up, 1).
move( down, -1).
operational( A =:= B).