Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- constants
- max = 1000
- domains
- board = step*
- x, y, sign = byte
- tries = integer
- step = symbol
- facts
- spot(board, x, y, sign)
- route(board, integer, integer)
- moves(board, board, board, integer)
- bestmove(board, board, board, integer)
- lastmoves(board, board, board, integer)
- predicates
- mygoal
- routeprint
- move(board, board)
- equal(board, board)
- solve(board, board, tries)
- equalWO2(board, board, sign)
- spotWOS(board, x, y, sign, sign)
- difference(board, board, integer)
- y_powerS(board, integer, sign)
- setBM(board, board, board)
- y_power(board, integer)
- passed(board)
- clauses
- mygoal :-
- assert(spot([last], 1, 1, 1)),
- assert(spot([last], 2, 1, 2)),
- assert(spot([last], 3, 1, 3)),
- assert(spot([last], 1, 2, 8)),
- assert(spot([last], 2, 2, 0)),
- assert(spot([last], 3, 2, 4)),
- assert(spot([last], 1, 3, 7)),
- assert(spot([last], 2, 3, 6)),
- assert(spot([last], 3, 3, 5)),
- /*
- assert(spot([first], 1, 1, 2)),
- assert(spot([first], 2, 1, 0)),
- assert(spot([first], 3, 1, 3)),
- assert(spot([first], 1, 2, 1)),
- assert(spot([first], 2, 2, 8)),
- assert(spot([first], 3, 2, 5)),
- assert(spot([first], 1, 3, 7)),
- assert(spot([first], 2, 3, 4)),
- assert(spot([first], 3, 3, 6)),
- assert(spot([first], 1, 1, 0)),
- assert(spot([first], 2, 1, 8)),
- assert(spot([first], 3, 1, 3)),
- assert(spot([first], 1, 2, 2)),
- assert(spot([first], 2, 2, 1)),
- assert(spot([first], 3, 2, 5)),
- assert(spot([first], 1, 3, 7)),
- assert(spot([first], 2, 3, 4)),
- assert(spot([first], 3, 3, 6)),
- */
- assert(spot([first], 1, 1, 1)),
- assert(spot([first], 2, 1, 2)),
- assert(spot([first], 3, 1, 3)),
- assert(spot([first], 1, 2, 8)),
- assert(spot([first], 2, 2, 5)),
- assert(spot([first], 3, 2, 7)),
- assert(spot([first], 1, 3, 4)),
- assert(spot([first], 2, 3, 6)),
- assert(spot([first], 3, 3, 0)),
- assert(moves([last], [], [first], 0)),
- solve([last], [first], max),
- routeprint./*;
- nl,fail;
- bestmove(A,B,C,D),write(A," ",B," ",C," ",D),nl,fail;
- nl,fail;
- lastmoves(A,B,C,D),write(A," ",B," ",C," ",D),nl,fail;
- nl,fail;
- moves(A,B,C,D),write(A," ",B," ",C," ",D),nl,fail;
- nl,fail;
- spot(A,B,C,D),write(A," ",B," ",C," ",D),nl,fail.*/
- difference(A, B, C) :-
- spot(A, 1, 1, S11),
- spot(A, 2, 1, S21),
- spot(A, 3, 1, S31),
- spot(A, 1, 2, S12),
- spot(A, 2, 2, S22),
- spot(A, 3, 2, S32),
- spot(A, 1, 3, S13),
- spot(A, 2, 3, S23),
- spot(A, 3, 3, S33),
- spot(A, X0a, Y0a, 0),
- spot(B, X11, Y11, S11),
- spot(B, X21, Y21, S21),
- spot(B, X31, Y31, S31),
- spot(B, X12, Y12, S12),
- spot(B, X22, Y22, S22),
- spot(B, X32, Y32, S32),
- spot(B, X13, Y13, S13),
- spot(B, X23, Y23, S23),
- spot(B, X33, Y33, S33),
- spot(B, X0b, Y0b, 0),
- y_power(A, Y0), y_power(B, Y1), %write(A, " ", Y0), nl, write(B, " ", Y1), nl,
- C = abs(X11-1) + abs(Y11-1) + abs(X21-2) + abs(Y21-1) + abs(X31-3) + abs(Y31-1) +
- abs(X12-1) + abs(Y12-2) + abs(X22-2) + abs(Y22-2) + abs(X32-3) + abs(Y32-2) +
- abs(X13-1) + abs(Y13-3) + abs(X23-2) + abs(Y23-3) + abs(X33-3) + abs(Y33-3) -
- abs(X0b-X0a) - abs(Y0b-Y0a) + 3 * abs(Y1 - Y0).
- y_power(A, B) :-
- y_powerS(A, B1, 1),
- y_powerS(A, B2, 2),
- y_powerS(A, B3, 3),
- y_powerS(A, B4, 4),
- y_powerS(A, B5, 5),
- y_powerS(A, B6, 6),
- y_powerS(A, B7, 7),
- y_powerS(A, B8, 8),
- B = B1 + B2 + B3 + B4 + B5 + B6 + B7 + B8.
- y_powerS(A, 1, S) :- spot(A, 2, 2, S), !.
- y_powerS(A, 0, 8) :- spot(A, 1, 1, 8), spot(A, 2, 1, 1), !.
- y_powerS(A, 0, S) :- spot(A, 1, 1, S), spot(A, 2, 1, S1), S1 = S + 1, !.
- y_powerS(A, 2, S) :- spot(A, 1, 1, S), spot(A, 2, 1, _), !.
- y_powerS(A, 0, 8) :- spot(A, 2, 1, 8), spot(A, 3, 1, 1), !.
- y_powerS(A, 0, S) :- spot(A, 2, 1, S), spot(A, 3, 1, S1), S1 = S + 1, !.
- y_powerS(A, 2, S) :- spot(A, 2, 1, S), spot(A, 3, 1, _), !.
- y_powerS(A, 0, 8) :- spot(A, 3, 1, 8), spot(A, 3, 2, 1), !.
- y_powerS(A, 0, S) :- spot(A, 3, 1, S), spot(A, 3, 2, S1), S1 = S + 1, !.
- y_powerS(A, 2, S) :- spot(A, 3, 1, S), spot(A, 3, 2, _), !.
- y_powerS(A, 0, 8) :- spot(A, 3, 2, 8), spot(A, 3, 3, 1), !.
- y_powerS(A, 0, S) :- spot(A, 3, 2, S), spot(A, 3, 3, S1), S1 = S + 1, !.
- y_powerS(A, 2, S) :- spot(A, 3, 2, S), spot(A, 3, 3, _), !.
- y_powerS(A, 0, 8) :- spot(A, 3, 3, 8), spot(A, 2, 3, 1), !.
- y_powerS(A, 0, S) :- spot(A, 3, 3, S), spot(A, 2, 3, S1), S1 = S + 1, !.
- y_powerS(A, 2, S) :- spot(A, 3, 3, S), spot(A, 2, 3, _), !.
- y_powerS(A, 0, 8) :- spot(A, 2, 3, 8), spot(A, 1, 3, 1), !.
- y_powerS(A, 0, S) :- spot(A, 2, 3, S), spot(A, 1, 3, S1), S1 = S + 1, !.
- y_powerS(A, 2, S) :- spot(A, 2, 3, S), spot(A, 1, 3, _), !.
- y_powerS(A, 0, 8) :- spot(A, 1, 3, 8), spot(A, 1, 2, 1), !.
- y_powerS(A, 0, S) :- spot(A, 1, 3, S), spot(A, 1, 2, S1), S1 = S + 1, !.
- y_powerS(A, 2, S) :- spot(A, 1, 3, S), spot(A, 1, 2, _), !.
- y_powerS(A, 0, 8) :- spot(A, 1, 2, 8), spot(A, 1, 1, 1), !.
- y_powerS(A, 0, S) :- spot(A, 1, 2, S), spot(A, 1, 1, S1), S1 = S + 1, !.
- y_powerS(A, 2, S) :- spot(A, 1, 2, S), spot(A, 1, 1, _), !.
- setBM(A, B, _) :- move(B, C), not(passed(C)), moves(A, _, B, K), N = K + 1, assert(moves(A, B, C, N)),
- difference(A, C, X), F = N + X, assert(lastmoves(A, B, C, F)), fail.
- setBM(A, B, _) :- retract(lastmoves(A, _, B, _)), fail.
- setBM(A, _, _) :- retract(bestmove(A, _, _, _)), fail.
- setBM(A, _, _) :- lastmoves(A, B, C, D), assert(bestmove(A, B, C, D)), fail.
- setBM(A, _, _) :- bestmove(A, _, _, Q), bestmove(A, B, C, D), Q < D, retract(bestmove(A, B, C, D)), fail.
- setBM(A, _, C) :- bestmove(A, _, C, _), !.
- routeprint :- route(A, P, G), write(A, " ", P, " ", G), nl, fail.
- solve(A,B,P) :- equal(A,B), !, Q = max - P, moves(A, _, B, K), assert(route(B, K, Q)).
- % solve(A, B, N) :- K = max - N, G = K div 100, K = G * 100, write(K), nl, storage(), write(B), nl, bestmove(A, Q, W, E), write(Q, " ", W, " ", E), nl, nl, fail.
- solve(A,B,N) :- !, N > 0, K = N - 1, setBM(A, B, C), solve(A, C, K).
- move(B,C) :- spot(B, Xb, Yb, 0), Xb<3, Xc=Xb+1, Yc=Yb, spot(B, Xc, Yc, S),
- str_int(STR1, S), concat(" -<|", STR1, STR2), concat(STR2, "|<- ", STR),
- C=[STR/*-Ноль вправо-"*/|B], equalWO2(B,C,S).
- move(B,C) :- spot(B, Xb, Yb, 0), Xb>1, Xc=Xb-1, Yc=Yb, spot(B, Xc, Yc, S),
- str_int(STR1, S), concat(" ->|", STR1, STR2), concat(STR2, "|>- ", STR),
- C=[STR/*"-Ноль влево-"*/|B], equalWO2(B,C,S).
- move(B,C) :- spot(B, Xb, Yb, 0), Yb<3, Yc=Yb+1, Xc=Xb, spot(B, Xc, Yc, S),
- str_int(STR1, S), concat(" -^|", STR1, STR2), concat(STR2, "|^- ", STR),
- C=[STR/*"-Ноль вниз-"*/|B], equalWO2(B,C,S).
- move(B,C) :- spot(B, Xb, Yb, 0), Yb>1, Yc=Yb-1, Xc=Xb, spot(B, Xc, Yc, S),
- str_int(STR1, S), concat(" -v|", STR1, STR2), concat(STR2, "|v- ", STR),
- C=[STR/*"-Ноль вверх-"*/|B], equalWO2(B,C,S).
- equalWO2(A,B,S) :-
- spot(A, 1, 1, S11),
- spot(A, 2, 1, S21),
- spot(A, 3, 1, S31),
- spot(A, 1, 2, S12),
- spot(A, 2, 2, S22),
- spot(A, 3, 2, S32),
- spot(A, 1, 3, S13),
- spot(A, 2, 3, S23),
- spot(A, 3, 3, S33),
- spotWOS(B, 1, 1, S11, S),
- spotWOS(B, 2, 1, S21, S),
- spotWOS(B, 3, 1, S31, S),
- spotWOS(B, 1, 2, S12, S),
- spotWOS(B, 2, 2, S22, S),
- spotWOS(B, 3, 2, S32, S),
- spotWOS(B, 1, 3, S13, S),
- spotWOS(B, 2, 3, S23, S),
- spotWOS(B, 3, 3, S33, S).
- spotWOS(A, X, Y, 0, S) :- not(spot(A, X, Y, S)), assert(spot(A, X, Y, S)).
- spotWOS(A, X, Y, S, S) :- not(spot(A, X, Y, 0)), assert(spot(A, X, Y, 0)).
- spotWOS(A, X, Y, S1, S) :- S1 <> 0, S1 <> S, not(spot(A, X, Y, S1)), assert(spot(A, X, Y, S1)).
- equal(A,A).
- equal(A,B) :-
- spot(A, 1, 1, S11),
- spot(A, 2, 1, S21),
- spot(A, 3, 1, S31),
- spot(A, 1, 2, S12),
- spot(A, 2, 2, S22),
- spot(A, 3, 2, S32),
- spot(A, 1, 3, S13),
- spot(A, 2, 3, S23),
- spot(A, 3, 3, S33),
- spot(B, 1, 1, S11),
- spot(B, 2, 1, S21),
- spot(B, 3, 1, S31),
- spot(B, 1, 2, S12),
- spot(B, 2, 2, S22),
- spot(B, 3, 2, S32),
- spot(B, 1, 3, S13),
- spot(B, 2, 3, S23),
- spot(B, 3, 3, S33).
- passed(A) :- moves(_, _, B, _), equal(A,B).
- goal
- mygoal.
Add Comment
Please, Sign In to add comment