Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Could someone please explain how this code works

Status
Not open for further replies.

SynAmardo

Technical User
Dec 13, 2022
1
0
0
DE
Im working on solving a task, where i have to walk thorugh a labyrinth with doors to get to a specific room and i have to find out the way. I created this program with help but don't quite understand it, could someone please do so?

(tuer=door; richtung=direction/arrow; weg=the path; Start/Ende=start/end; Loesung=solution; Punkt =Point, Knot)

[pre]tuer(a,b).
tuer(b,e).
tuer(b,c).
tuer(d,e).
tuer(c,d).
tuer(e,f).
tuer(g,e).

richtung(X, Y):-tuer (X,Y).
richtung(X,Y):-tuer (Y, X).

%Now is the point of not understanding anything
weg(Start,Ziel, Loesung): -richtung (Start, X), richtung (Y, Ziel),
weg (Start, [Start], Ziel, Loesung).

weg(Ziel, Weg,Ziel, Loesung):-Loesung = Weg.

weg(PunktA, Weg, Ziel, Loesung):-
richtung (PunktA, PunktX),
\+(member(PunktX, Weg)),
append(Weg, [PunktX], WegNeu),
weg (PunktX, WegNeu, Ziel, Loesung).


Thank you in advance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top