-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonkey_n_banana.pl
47 lines (34 loc) · 1.34 KB
/
monkey_n_banana.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
% state(where_monkey, on_crate?, where_crate, banana).
% we must specify that transition to win state is possible.
% state(_, _, _, has). = win state
% creating transition states
% take banana
move(state(at_middle, on_box, at_middle, has_not),
grab,
state(at_middle, on_box, at_middle, has)). % struct with initial state and next state
% climb box
move(state(X, on_floor, X, Y), climb, state(X, on_box, X, Y)).
% push box
move(state(X1, on_floor, X1, Y), push(X1, X2), state(X2, on_floor, X2, Y)).
% walk
move(state(X1, on_floor, XC, Y), walk(X1, X2), state(X2, on_floor, XC, Y)).
% win
victory(state(_, _, _, has), []).
% M and L are lists, M - transitions (currentMoves) list, L - nextMoves
victory(CurrentState, [CurrentMoveDescription | NextMoves]) :-
move(CurrentState, CurrentMoveDescription, NextState), % S2 state is that
victory(NextState, NextMoves). % S2 state is victory
% Add new element to linked-list end
addHead(H, T, [H | T]).
% Add multiple elements to linked-list start, backward recursive step
concat([], L2, L2).
concat([H | T], L2, [H | L3]) :-
concat(T, L2, L3).
% Check if element is in list
contains(X, [X, _]).
contains(X, [_ | T]) :-
contains(X, T).
% Show ways how we can delete certain X element in list
showDelete(X, [X | T], T).
showDelete(X, [H | T], [H | T2]) :-
showDelete(X, T, T2).