瓷砖游戏。我无法行动
我试图在序言中提出 8-tiles 问题,但我的代码不是 跑步 。
更具体地说,当我输入一个操作时,我会采取 false 。
move([0, Y, Z], [Y, 0, Z], right).
move([X, 0, Z], [0, X, Z], left).
move([X, 0, Z], [X, Z, 0], right).
move([X, Y, 0], [X, 0, Y], left).
arc_horiz([X, Y, Z], [X1, Y, Z], Direction) :- move(X, X1, Direction).
arc_horiz([X, Y, Z], [X, Y1, Z], Direction) :- move(Y, Y1, Direction).
arc_horiz([X, Y, Z], [X, Y, Z1], Direction) :- move(Z, Z1, Direction).
switch([[X1, Y1, Z1], [X2, Y2, Z2], [X3, Y3, Z3]], [[X1, X2 , X3], [Y1, Y2 , Y3], [Z1, Z2, Z3]]).
arc_vert(RowState1, RowState2, up) :- switch(RowState1, ColState1),
arc_horiz(ColState1, ColState2, left),
switch(RowState2, ColState2).
arc_vert(RowState1, RowState2, down) :- switch(RowState1, ColState1),
arc_horiz(ColState1, ColState2, right),
switch(RowState2, ColState2).
arc(State1, State2,left) :- arc_horiz(State1, State2, left).
arc(State1, State2,up) :- arc_vert(State1, State2, up).
arc(State1, State2,right):- arc_horiz(State1, State2, right).
arc(State1, State2,down) :- arc_vert(State1, State2, down).
search([[1,2,3],[8,0,4],[7,6,5]]) :- write('Goal'),nl,nl.
search(X) :- writeln('Actions : left, right, up, down'),
read(Action),
arc(X,State2,Action),
write(State2),
search(State2).
start :-
INITIAL = start([[2, 8, 3], [1, 6, 4], [7, 0, 5]]),
writeln(INITIAL),
assert(INITIAL),
search(INITIAL).
例如,
1?- start.
start([[2,8,3],[1,6,4],[7,0,5]])
Actions : left, right, up, down
|: left.
false.
提前非常感谢
I am trying to make 8-tiles problem in prolog but my code is not
running .
To be more specific when I type an action then I take false.
move([0, Y, Z], [Y, 0, Z], right).
move([X, 0, Z], [0, X, Z], left).
move([X, 0, Z], [X, Z, 0], right).
move([X, Y, 0], [X, 0, Y], left).
arc_horiz([X, Y, Z], [X1, Y, Z], Direction) :- move(X, X1, Direction).
arc_horiz([X, Y, Z], [X, Y1, Z], Direction) :- move(Y, Y1, Direction).
arc_horiz([X, Y, Z], [X, Y, Z1], Direction) :- move(Z, Z1, Direction).
switch([[X1, Y1, Z1], [X2, Y2, Z2], [X3, Y3, Z3]], [[X1, X2 , X3], [Y1, Y2 , Y3], [Z1, Z2, Z3]]).
arc_vert(RowState1, RowState2, up) :- switch(RowState1, ColState1),
arc_horiz(ColState1, ColState2, left),
switch(RowState2, ColState2).
arc_vert(RowState1, RowState2, down) :- switch(RowState1, ColState1),
arc_horiz(ColState1, ColState2, right),
switch(RowState2, ColState2).
arc(State1, State2,left) :- arc_horiz(State1, State2, left).
arc(State1, State2,up) :- arc_vert(State1, State2, up).
arc(State1, State2,right):- arc_horiz(State1, State2, right).
arc(State1, State2,down) :- arc_vert(State1, State2, down).
search([[1,2,3],[8,0,4],[7,6,5]]) :- write('Goal'),nl,nl.
search(X) :- writeln('Actions : left, right, up, down'),
read(Action),
arc(X,State2,Action),
write(State2),
search(State2).
start :-
INITIAL = start([[2, 8, 3], [1, 6, 4], [7, 0, 5]]),
writeln(INITIAL),
assert(INITIAL),
search(INITIAL).
For example
1?- start.
start([[2,8,3],[1,6,4],[7,0,5]])
Actions : left, right, up, down
|: left.
false.
Thanks a lot in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论