root/trunk/examples/searching/farmer.lgt

Revision 4601, 1.5 KB (checked in by pmoura, 7 weeks ago)

Added svn:mime-type property to source files (set to text/x-logtalk).

  • Property svn:mime-type set to text/x-logtalk
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2:- object(farmer,
3    instantiates(state_space)).
4
5
6    :- info([
7        version is 1.0,
8        author is 'Paulo Moura',
9        date is 1998/3/23,
10        comment is 'Farmer, cabbage, goat, and wolf state space search problem.']).
11
12
13    initial_state(start, (north, north, north, north)).
14
15
16    goal_state(end, (south, south, south, south)).
17
18
19    next_state((Cabbage, Goat, Wolf, Farmer), (FCabbage, Goat, Wolf, FFarmer)) :-
20        same_side(Farmer, Cabbage),
21        \+ same_side(Goat, Wolf),
22        flip(Farmer, FFarmer),
23        flip(Cabbage, FCabbage).
24
25    next_state((Cabbage, Goat, Wolf, Farmer), (Cabbage, FGloat, Wolf, FFarmer)) :-
26        same_side(Farmer, Goat),
27        flip(Farmer, FFarmer),
28        flip(Goat, FGloat).
29
30    next_state((Cabbage, Goat, Wolf, Farmer), (Cabbage, Goat, FWolf, FFarmer)) :-
31        same_side(Farmer, Wolf),
32        \+ same_side(Cabbage, Goat),
33        flip(Farmer, FFarmer),
34        flip(Wolf, FWolf).
35
36    next_state((Cabbage, Goat, Wolf, Farmer), (Cabbage, Goat, Wolf, FFarmer)) :-
37        \+ same_side(Cabbage, Goat),
38        \+ same_side(Goat, Wolf),
39        flip(Farmer, FFarmer).
40
41
42    flip(north, south).
43   
44    flip(south, north).
45
46
47    same_side(north, north).
48
49    same_side(south, south).
50
51
52    print_state((Cabbage, Goat, Wolf, Farmer)) :-
53        (Cabbage = north -> write(c); write('_')),
54        (Goat = north -> write(g); write('_')),
55        (Wolf = north -> write(w); write('_')),
56        (Farmer = north -> write('f.<__>.........._'); write('_..........<__>.f')),
57        (Cabbage = north -> write('_'); write(c)),
58        (Goat = north -> write('_'); write(g)),
59        (Wolf = north -> write('_'); write(w)),
60        nl.
61
62
63:- end_object.
Note: See TracBrowser for help on using the browser.