Article View: fj.lang.prolog
Article #94Looking For 8-Puzzle Problem Prolog Program Solution?
From: R. Sihattha
Date: Mon, 22 Apr 1996 00:00
Date: Mon, 22 Apr 1996 00:00
85 lines
4078 bytes
4078 bytes
Looking For 8-Puzzle Problem Prolog Program Solution?
Any one know this kind of 8-Puzzle Prolog Program.if so,
please give me some advice about the Thinking and Program
List of 8-Puzzle Problem! Thankx for advance.
%%
%% $B(#(!(!(!(!(!(!(!(!(!($(B $B(#(!(!(!(!(!(!(!(!(!($(B
%% $B("(#(!($(#(!($(#(!($("(B $B("(#(!($(#(!($(#(!($("(B
%% $B("("(B2 $B("("(B1 $B("("(B6 $B("("(B $B("("(B1 $B("("(B2 $B("("(B3 $B("("(B
%% $B("(&(!(%(&(!(%(&(!(%("(B $B("(&(!(%(&(!(%(&(!(%("(B
%% $B("(#(!($(B $B(#(!($("(B $B"M(B $B("(#(!($(B $B(#(!($("(B
%% $B("("(B4 $B("(B hole $B("(B8 $B("("(B $B"M(B $B("("(B8 $B("(B hole $B("(B4 $B("("(B
%% $B("(&(!(%(B $B(&(!(%("(B $B"M(B $B("(&(!(%(B $B(&(!(%("(B
%% $B("(#(!($(#(!($(#(!($("(B $B("(#(!($(#(!($(#(!($("(B
%% $B("("(B7 $B("("(B5 $B("("(B3 $B("("(B $B("("(B7 $B("("(B6 $B("("(B5 $B("("(B
%% $B("(&(!(%(&(!(%(&(!(%("(B $B("(&(!(%(&(!(%(&(!(%("(B
%% $B(&(!(!(!(!(!(!(!(!(!(%(B $B(&(!(!(!(!(!(!(!(!(!(%(B
%% Initial state Goal State
%%
%% $B(#(!(!(!(!(!(!(!(!(!($(B
%% $B("(#(!($(#(!($(#(!($("(B
%% $B("("(B2 $B("("(B1 $B("("(B6 $B("("(B
%% $B("(&(!(%(&(!(%(&(!(%("(B
%% $B("(#(!($(B $B(#(!($("(B $B(#(!(!(!(!(!(!(!(!(!(!(!(!($(B
%% $B("("(B4 $B("(B hole $B("(B8 $B("(""M("(B(x1 x2 x3 ........x8 x9)$B("(B
%% $B("(&(!(%(B $B(&(!(%("(B $B(&(!(!(!(!(!(!(!(!(!(!(!(!(%(B
%% $B("(#(!($(#(!($(#(!($("(B
%% $B("("(B7 $B("("(B5 $B("("(B3 $B("("(B
%% $B("(&(!(%(&(!(%(&(!(%("(B
%% $B(&(!(!(!(!(!(!(!(!(!(%(B
%% $B(#(!(!(!(!(!(!(!(!(!(!($(B $B(#(!(!(!(!(!(!(!(!(!(!($(B
%% $B("(B(2 1 6 4 S 8 7 5 3) $B(""M(B....... $B"M("(B(1 2 3 8 S 4 7 6 5) $B("(B
%% $B(&(!(!(!(!(!(!(!(!(!(!(%(B $B(&(!(!(!(!(!(!(!(!(!(!(%(B
%% Start Node Goal Node
%% 8-Puzzle Program.
hole(1).
answer(X,Z) :- repeat,hole(LM1),abolish(hole,1),LM2 is LM1+1,
assert(hole(LM2)),
answerlist(X,[1,2,3,8,x,4,7,6,5],Z,LM2),!,
abolish(hole,1),assert(hole(1)).
%% AnswerList(A,B,C,L) : A is the Answer list.
%% B is Goal State.
%% C is the next Answer list.
%% L is Depth-first search of the hole value.
answerlist(X,Y,X,LMAX) :- listend(X,Y),!.
answerlist(X,Y,Z,LMAX) :- listend(X,Y1),move(Y1,[1,2,3,8,x,4,7,6,5]),
answerlist([[1,2,3,8,x,4,7,6,5]|X},Y,Z,LMAX),!.
answerlist(X,Y,Z,LMAX) :- listend(X,Y1),move((Y1,Y2),/+ member(Y2,X),
length(X,L),L=<LMAX,answerlist([Y2|X],Y,Z,LMAX).
listend([Y|X],Y).
listend(X,X).
.....
.....
.....
.....
.....
Some thing like this,so please give me your Whole answer and any advice.
any thing are ok!!!!
Thank you very much for your help.
("`-/")_.-'"``-._
. . `; -._ )-;-,_`) Write the thing that you know
(v_,)' _ )`-.\ ``-' Be yourself no matter one they said
_.- _..-_/ / ((.'
((,.-' ((,/
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
---- Tha --------
Sihattha Rasphone
Department of Information Systems
Language Design Laboratory
Graduate School of Information Science,
Japan Advanced Institute of Science and Technology(JAIST), HOKURIKU
Technical Details
Message-ID:
<4lgfb2$l9l@rinji-news.jaist.ac.jp>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: Japanese,JIS X-Google-Thread: 1217ff,30a2f98f2bbc1074,start X-Google-Attributes: gid1217ff,public From: sihattha@jaist.ac.jp (R. Sihattha) Subject: Looking For 8-Puzzle Problem Prolog Program Solution? Date: 1996/04/22 Message-ID: <4lgfb2$l9l@rinji-news.jaist.ac.jp> X-Deja-AN: 150839366 organization: Japan Advanced Institute of Science and Technology, Ishikawa, Japan newsgroups: fj.lang.prolog