-
Notifications
You must be signed in to change notification settings - Fork 0
/
completionist.pl
55 lines (40 loc) · 1.42 KB
/
completionist.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
?- style_check(-discontiguous).
:- [dynamics].
can_visit_branch(Equipment, [H|T]) :-
(forall(member(R, H), member(R, Equipment))), !;
(can_visit_branch(Equipment, T)).
can_visit(Location, Equipment) :-
requires(Location, REQUIREDS),
length(REQUIREDS, L),
(L == 0 -> (
true
);
(
can_visit_branch(Equipment, REQUIREDS)
)).
find_new_to_visit(Visited, Equipment, NewToVisit) :-
findall(L, (location(L), can_visit(L, Equipment), \+ member(L, Visited)), NewToVisit).
visit_multiple(Visited, Equipment, [], NewVisited, NewEquipment) :-
NewVisited = Visited,
NewEquipment = Equipment.
visit_multiple(Visited, Equipment, [H|T], NewVisited, NewEquipment) :-
contains(H, Item),
UpdatedVisited = [H|Visited],
append(Equipment, [Item], TempEquipment),
visit_multiple(UpdatedVisited, TempEquipment, T, NewVisited, NewEquipment).
completable(Target) :-
completable([], [], Target),
!.
completable(Visited, Equipment, Target) :-
find_new_to_visit(Visited, Equipment, NewToVisit),
(
member(Target, NewToVisit);
length(NewToVisit, L),
L == 0 -> (
false
);
(
visit_multiple(Visited, Equipment, NewToVisit, NewVisited, NewEquipment),
completable(NewVisited, NewEquipment, Target)
)
).