瓷砖游戏。我无法行动

发布于 2024-12-22 01:53:15 字数 1780 浏览 1 评论 0原文

我试图在序言中提出 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文