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4,1,2,[* ]],[4,2,2,[* ]],[4,3,2,[* ]],[4,4,2,[* ]],[4,5,2,[* ]], [4,1,1,[* ]],[4,2,1,[* ]],[4,3,1,[* ]],[4,4,1,[* ]],[4,5,1,[* ]] ]). %% 1 start %% key to chest->machete %% machete to vine->exit /** [debug] ?- traverse(2,2,6). [2,2,6][] [2,2,5][] [2,3,5][] [2,3,4][] [2,3,3][] [2,2,3][] [2,2,2][] [2,3,2][] [3,3,2][v] [3,3,3][v] [3,2,3][v] [3,2,4][v] [3,3,4][v] [3,4,4][v] [3,4,5][v] [3,3,5][v] [3,2,5][v] [3,2,6][v] [3,3,6][v] [2,3,6][v,k] [2,3,7][v,k] [2,3,8][v,k] [2,4,8][v,k] [3,4,8][v,k] [3,3,8][v,k] [3,2,7][v,k] [2,4,5][v,k,c,m,e] Game Over % Execution Aborted **/ traverse(Z,X,Y) :- traverse(Z,X,Y,[],_,[],_). traverse(Z,X,Y,Explored,Explored,Inventory,Inventory) :- rainforest(Map), member([Z,X,Y,Cell],Map), Cell=[*],!. traverse(Z,X,Y,Explored,Explored,Inventory,Inventory) :- member([Z,X,Y],Explored),!. traverse(Z,X,Y,Explored1,Explored2,Inventory1,Inventory2) :- rainforest(Map), member([Z,X,Y,Cell],Map), write([Z,X,Y]), (Cell=[]->Inventory4a=Inventory1; (Cell=[Item],append(Inventory1,[Item],Inventory3), apply_all_to_all(Inventory3,Inventory4),Inventory4a=Inventory4)), writeln(Inventory4a), (member(e,Inventory4a)->(writeln("Game Over"),abort);true), append(Explored1,[[Z,X,Y]],Explored3), Xm1 is X-1, Ym1 is Y-1, Xp1 is X+1, Yp1 is Y+1, Zm1 is Z-1, Zp1 is Z+1, traverse(Z,Xm1,Y,Explored3,Explored4,Inventory4a,Inventory5), traverse(Z,X,Ym1,Explored4,Explored5,Inventory5,Inventory6), traverse(Z,Xp1,Y,Explored5,Explored6,Inventory6,Inventory7), traverse(Z,X,Yp1,Explored6,Explored7,Inventory7,Inventory8), traverse(Zm1,X,Y,Explored7,Explored8,Inventory8,Inventory9), traverse(Zp1,X,Y,Explored8,Explored2,Inventory9,Inventory2). apply_all_to_all(Inventory1,Inventory2) :- findall(Item3,(member(Item1,Inventory1), member(Item2,Inventory1),not(Item1=Item2), apply(Item1,Item2,Item3), not(member(Item3,Inventory1))), AddedItems), (AddedItems=[]->Inventory1=Inventory2; (append(Inventory1,AddedItems,Inventory3), apply_all_to_all(Inventory3,Inventory2))). apply(k,c,m). apply(m,v,e).