资源描述:
《人工智能迷宫问题》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、人工智能迷宫问题学院信息工程学院专业计算机科学与技术班级学生姓名学号任课老师题目:迷宫问题迷宫算符:上、下、右、左。状态空间图求解的状态空间图OPEN表和CLOSED表:程序:DOMAINSstate=symbolDATABASE-mydatabaseopen(state,integer)closed(integer,state,integer)res(state)mark(state)fail_PREDICATESsolvesearch(state,state)resultsearchingstep4(integer,state)step56(integer,state)equal(
2、state,state)repeatresulting(integer)rule(state,state)road(state,state)GOALsolve.CLAUSESsolve:-search(s0,sg),result.search(Begin,End):-retractall(_,mydatabase),assert(closed(0,Begin,0)),assert(open(Begin,0)),assert(mark(End)),repeat,searching,!.result:-not(fail_),retract(closed(0,_,0)),closed(M,_
3、,_),resulting(M),!.result:-beep,write("sorrydon'tfindaroad!").searching:-open(State,Pointer),retract(open(State,Pointer)),closed(No,_,_),No2=No+1,asserta(closed(No2,State,Pointer)),!,step4(No2,State).searching:-assert(fail_).step4(_,State):-mark(End),equal(State,End).step4(No3,State):-step56(No3
4、,State),!,fail.step56(No4,StateX):-rule(StateX,StateY),not(open(StateY,_)),not(closed(_,StateY,_)),assertz(open(StateY,No4)),fail.step56(_,_):-!.equal(X,X).repeat.repeat:-repeat.resulting(N):-closed(N,X,M),asserta(res(X)),resulting(M).resulting(_):-res(X),write(X),nl,fail.resulting(_):-!.rule(X,
5、Y):-road(X,Y).road(s0,s1).road(s1,s4).road(s1,s2).road(s1,s0).road(s4,s1).road(s2,s5).road(s2,s3).road(s2,s1).road(s5,s2).road(s5,s8).road(s3,s6).road(s3,s2).road(s8,s5).road(s8,s9).road(s8,s7).road(s6,s3).road(s6,sg).road(s9,s8).road(s7,s8).road(sg,s6).运行结果: