Start New Discussion within our Software Development Community

Hi, 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.
So the new state is not printed.

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.

Could you help me please ?

Your logic does not make sense. You try to unify start of arity 1 but you only have start/0 defined.

This article has been dead for over six months. Start a new discussion instead.