-
Notifications
You must be signed in to change notification settings - Fork 0
/
codeGen_enc.lp
76 lines (61 loc) · 2.12 KB
/
codeGen_enc.lp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
dir(left).
dir(up).
dir(down).
dir(right).
goal_reg(R) :- goal_in(_,_,_,R).
init_tile(X,Y) :- goal_in(X,Y,_,_).
in(AX,AY,C,R,AX,AY,0) :- init_tile(AX,AY),
init_reg(R),
init_count(C).
1 {
move(R,RR,D,T) : reg(R), reg(RR), dir(D);
add(R,RA,RB,T) : reg(R), reg(RA), reg(RB);
sub(R,RA,RB,T) : reg(R), reg(RA), reg(RB);
null(T)
} 1 :- moves(M), T = 1..M.
in(AX,AY,C,R,X,Y,T) :- move(R,RR,left ,T),
in(AX,AY,C,RR,X+1,Y,T-1).
in(AX,AY,C,R,X,Y,T) :- move(R,RR,up ,T),
in(AX,AY,C,RR,X,Y-1,T-1).
in(AX,AY,C,R,X,Y,T) :- move(R,RR,right,T),
in(AX,AY,C,RR,X-1,Y,T-1).
in(AX,AY,C,R,X,Y,T) :- move(R,RR,down ,T),
in(AX,AY,C,RR,X,Y+1,T-1).
in(AX,AY,C,R,X,Y,T) :- add(R,RA,RB,T),
in(AX,AY,CA,RA,X,Y,T-1),
in(AX,AY,CB,RB,X,Y,T-1),
C=CA+CB.
in(AX,AY,C,R,X,Y,T) :- add(R,RA,RB,T),
in(AX,AY,C,RA,X,Y,T-1),
not in(AX,AY,_,RB,X,Y,T-1).
in(AX,AY,C,R,X,Y,T) :- add(R,RA,RB,T),
in(AX,AY,C,RB,X,Y,T-1),
not in(AX,AY,_,RA,X,Y,T-1).
in(AX,AY,C,R,X,Y,T) :- sub(R,RA,RB,T),
in(AX,AY,CA,RA,X,Y,T-1),
in(AX,AY,CB,RB,X,Y,T-1),
C=CA-CB.
in(AX,AY,C,R,X,Y,T) :- sub(R,RA,RB,T),
in(AX,AY,C,RA,X,Y,T-1),
not in(AX,AY,_,RB,X,Y,T-1).
in(AX,AY,C,R,X,Y,T) :- sub(R,RA,RB,T),
in(AX,AY,-C,RB,X,Y,T-1),
not in(AX,AY,_,RA,X,Y,T-1).
reset(R,T) :- move(R,_,_,T).
reset(R,T) :- add(R,_,_,T).
reset(R,T) :- sub(R,_,_,T).
in(AX,AY,C,R,X,Y,T+1) :- in(AX,AY,C,R,X,Y,T),
not reset(R,T+1),
not moves(T).
:- in(AX,AY,CA,R,X,Y,T),
in(AX,AY,CB,R,X,Y,T),
CA!=CB.
:- goal_in(AX,AY,C,R), moves(M),
not in(AX,AY,C,R,0,0,M).
:- in(AX,AY,C,R,0,0,M), goal_reg(R), moves(M), C!=0,
not goal_in(AX,AY,C,R).
#maximize{1,T:null(T)}.
#show move/4.
#show add/4.
#show sub/4.
#show null/1.