From 1c7e355c29bb1f9057dca927701d24deb913bb1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar?= Date: Tue, 28 Feb 2023 18:27:29 +0100 Subject: [PATCH] ajout application sokoban article univ --- TP1/Prolog/sokoban/board.pl | 32 ++++++++++++++++++++++++ TP1/Prolog/sokoban/main.pl | 5 ++++ TP1/Prolog/sokoban/screen0.pl | 38 +++++++++++++++++++++++++++++ TP1/Prolog/sokoban/solver.pl | 46 +++++++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 TP1/Prolog/sokoban/board.pl create mode 100644 TP1/Prolog/sokoban/main.pl create mode 100644 TP1/Prolog/sokoban/screen0.pl create mode 100644 TP1/Prolog/sokoban/solver.pl diff --git a/TP1/Prolog/sokoban/board.pl b/TP1/Prolog/sokoban/board.pl new file mode 100644 index 0000000..232ef78 --- /dev/null +++ b/TP1/Prolog/sokoban/board.pl @@ -0,0 +1,32 @@ +next_location(Start, End, up) :- top(Start, End). +next_location(Start, End, down) :- top(End, Start). +next_location(Start, End, right) :- top(Start, End). +next_location(Start, End, left) :- top(End, Start). + +% explication nécessaire +corner(X) :- \+ noncorner(X). +noncorner(X) :- top(_, X), top(X, _). +noncorner(X) :- right(_, X), right(X, _). + +% explication nécessaire +stuck(X, Y) :- + (right(X, Y) ; right(Y, X)), + (\+ storage(X); \+ storage(Y)), + (\+ top(X,_), \+ top(Y,_); \+ top(_,X), \+ top(_,Y)), + !. +stuck(X,Y):- + (top(X,Y);top(Y,X)), + (\+ storage(X); \+ storage(Y)), + (\+ right(X,_), \+ right(Y,_); \+ right(_,X), \+ right(_,Y)), + !. + +insert_list(X, [], [X]). +insert_list(X, [Y|Ysuite], [X, Y|Ysuite]) :- + X @=storage(Loc);true), +% foreach(BoxLoc in BoxLocs, \+ stuck(BoxLoc,Loc)). + +possible_dest(Pos, []). +possible_dest(Pos, [BoxPos|BoxPosSuite]) :- + \+ Pos = BoxPos, + (corner(Pos)->storage(Pos);true), + \+ stuck(BoxPos, Pos), + possible_dest(Pos, BoxPosSuite). + +next_dest(Pos, NextPos, _Dir, Destination, NewSokobanPos, _BoxsPos) :- + Destination = NextPos, + NewSokobanPos = BoxPos. +next_dest(Pos, NextPos, Dir, Destination, NewSokobanPos, BoxsPos) :- + next_location(NextPos, NextNextPos, Dir), + possible_dest(NextNextPos, BoxsPos), + next_dest(NextPos, NextNextPos, Dir, Destination, NewSokobanPos, BoxsPos).