Post by Lars Ericson on Aug 2, 2015 12:32:12 GMT -8
LP:
role(robot).
base(cell(M,N,P)) :- row(M), col(N), piece(P).
base(captures(M)) :- scoremap(M,N).
base(step(N)) :- succ(M,N).
input(robot,move(M1,N1,M2,N2)) :- row(M1), col(N1), knightmove(M1,N1,M2,N2).
row(1).
row(2).
row(3).
row(4).
row(5).
row(6).
row(7).
col(1).
col(2).
col(3).
col(4).
col(5).
col(6).
col(7).
piece(knight).
piece(pawn).
piece(blank).
true(cell(1,1,knight),1).
true(cell(1,2,pawn),1).
true(cell(1,3,pawn),1).
true(cell(1,4,pawn),1).
true(cell(1,5,pawn),1).
true(cell(1,6,pawn),1).
true(cell(1,7,pawn),1).
true(cell(2,1,pawn),1).
true(cell(2,2,pawn),1).
true(cell(2,3,pawn),1).
true(cell(2,4,pawn),1).
true(cell(2,5,pawn),1).
true(cell(2,6,pawn),1).
true(cell(2,7,pawn),1).
true(cell(3,1,pawn),1).
true(cell(3,2,pawn),1).
true(cell(3,3,pawn),1).
true(cell(3,4,pawn),1).
true(cell(3,5,pawn),1).
true(cell(3,6,pawn),1).
true(cell(3,7,pawn),1).
true(cell(4,1,pawn),1).
true(cell(4,2,pawn),1).
true(cell(4,3,pawn),1).
true(cell(4,4,pawn),1).
true(cell(4,5,pawn),1).
true(cell(4,6,pawn),1).
true(cell(4,7,pawn),1).
true(cell(5,1,pawn),1).
true(cell(5,2,pawn),1).
true(cell(5,3,pawn),1).
true(cell(5,4,pawn),1).
true(cell(5,5,pawn),1).
true(cell(5,6,pawn),1).
true(cell(5,7,pawn),1).
true(cell(6,1,pawn),1).
true(cell(6,2,pawn),1).
true(cell(6,3,pawn),1).
true(cell(6,4,pawn),1).
true(cell(6,5,pawn),1).
true(cell(6,6,pawn),1).
true(cell(6,7,pawn),1).
true(cell(7,1,pawn),1).
true(cell(7,2,pawn),1).
true(cell(7,3,pawn),1).
true(cell(7,4,pawn),1).
true(cell(7,5,pawn),1).
true(cell(7,6,pawn),1).
true(cell(7,7,pawn),1).
true(captures(0),1).
true(step(1),1).
legal(robot,move(M1,N1,M2,N2),T) :- time(T), true(cell(M1,N1,knight),T), knightmove(M1,N1,M2,N2).
true(cell(M2,N2,knight),T+1) :- time(T), does(robot,move(M1,N1,M2,N2),T).
true(cell(M1,N1,blank),T+1) :- time(T), does(robot,move(M1,N1,M2,N2),T).
true(cell(U,V,pawn),T+1) :- time(T), true(cell(U,V,pawn),T), does(robot,move(M1,N1,M2,N2),T), U!=M2.
true(cell(U,V,pawn),T+1) :- time(T), true(cell(U,V,pawn),T), does(robot,move(M1,N1,M2,N2),T), V!=N2.
true(cell(U,V,blank),T+1) :- time(T), true(cell(U,V,blank),T), does(robot,move(M1,N1,M2,N2),T), U!=M2.
true(cell(U,V,blank),T+1) :- time(T), true(cell(U,V,blank),T), does(robot,move(M1,N1,M2,N2),T), V!=N2.
true(captures(OLD),T+1) :- time(T), does(robot,move(M1,N1,M2,N2),T), true(cell(M2,N2,blank),T), true(captures(OLD),T).
true(captures(NEW),T+1) :- time(T), does(robot,move(M1,N1,M2,N2),T), true(cell(M2,N2,pawn),T), true(captures(OLD),T), succ(OLD,NEW).
true(step(NEW),T+1) :- time(T), true(step(OLD),T), succ(OLD,NEW).
goal(robot,GOAL,T) :- time(T), true(captures(COUNT),T), scoremap(COUNT,GOAL).
terminal(T) :- time(T), true(step(49),T).
knightmove(M1,N1,M2,N2) :- time(T), add1row(M1,M2), add2col(N1,N2).
knightmove(M1,N1,M2,N2) :- time(T), add1row(M1,M2), add2col(N2,N1).
knightmove(M1,N1,M2,N2) :- time(T), add1row(M2,M1), add2col(N1,N2).
knightmove(M1,N1,M2,N2) :- time(T), add1row(M2,M1), add2col(N2,N1).
knightmove(M1,N1,M2,N2) :- time(T), add2row(M1,M2), add1col(N1,N2).
knightmove(M1,N1,M2,N2) :- time(T), add2row(M1,M2), add1col(N2,N1).
knightmove(M1,N1,M2,N2) :- time(T), add2row(M2,M1), add1col(N1,N2).
knightmove(M1,N1,M2,N2) :- time(T), add2row(M2,M1), add1col(N2,N1).
succ(0,1).
succ(1,2).
succ(2,3).
succ(3,4).
succ(4,5).
succ(5,6).
succ(6,7).
succ(7,8).
succ(8,9).
succ(9,10).
succ(10,11).
succ(11,12).
succ(12,13).
succ(13,14).
succ(14,15).
succ(15,16).
succ(16,17).
succ(17,18).
succ(18,19).
succ(19,20).
succ(20,21).
succ(21,22).
succ(22,23).
succ(23,24).
succ(24,25).
succ(25,26).
succ(26,27).
succ(27,28).
succ(28,29).
succ(29,30).
succ(30,31).
succ(31,32).
succ(32,33).
succ(33,34).
succ(34,35).
succ(35,36).
succ(36,37).
succ(37,38).
succ(38,39).
succ(39,40).
succ(40,41).
succ(41,42).
succ(42,43).
succ(43,44).
succ(44,45).
succ(45,46).
succ(46,47).
succ(47,48).
succ(48,49).
add1row(1,2).
add1row(2,3).
add1row(3,4).
add1row(4,5).
add1row(5,6).
add1row(6,7).
add2row(1,3).
add2row(2,4).
add2row(3,5).
add2row(4,6).
add2row(5,7).
add1col(1,2).
add1col(2,3).
add1col(3,4).
add1col(4,5).
add1col(5,6).
add1col(6,7).
add2col(1,3).
add2col(2,4).
add2col(3,5).
add2col(4,6).
add2col(5,7).
scoremap(0,4).
scoremap(1,6).
scoremap(2,8).
scoremap(3,10).
scoremap(4,12).
scoremap(5,14).
scoremap(6,16).
scoremap(7,18).
scoremap(8,20).
scoremap(9,22).
scoremap(10,24).
scoremap(11,26).
scoremap(12,28).
scoremap(13,30).
scoremap(14,32).
scoremap(15,34).
scoremap(16,36).
scoremap(17,38).
scoremap(18,40).
scoremap(19,42).
scoremap(20,44).
scoremap(21,46).
scoremap(22,48).
scoremap(23,50).
scoremap(24,52).
scoremap(25,54).
scoremap(26,56).
scoremap(27,58).
scoremap(28,60).
scoremap(29,62).
scoremap(30,64).
scoremap(31,66).
scoremap(32,68).
scoremap(33,70).
scoremap(34,72).
scoremap(35,74).
scoremap(36,76).
scoremap(37,78).
scoremap(38,80).
scoremap(39,82).
scoremap(40,84).
scoremap(41,86).
scoremap(42,88).
scoremap(43,90).
scoremap(44,92).
scoremap(45,94).
scoremap(46,96).
scoremap(47,98).
scoremap(48,100).
:- does(R,M,T), not legal(R,M,T).
time(1..49).
1{ does(R,M,T) : input(R,M) }1 :- role(R), time(T), 1 <= T, T <= 48.
:- not goal(robot,100,49).
SOLUTION (reaches goal 100, takes 34,358 seconds on my PC altogether with 11 threads, 3171 seconds for the good thread):
does(robot,move(1,1,2,3),1)
does(robot,move(2,3,1,5),2)
does(robot,move(1,5,2,7),3)
does(robot,move(2,7,4,6),4)
does(robot,move(4,6,6,7),5)
does(robot,move(6,7,7,5),6)
does(robot,move(7,5,5,4),7)
does(robot,move(5,4,6,2),8)
does(robot,move(6,2,4,1),9)
does(robot,move(4,1,2,2),10)
does(robot,move(2,2,1,4),11)
does(robot,move(1,4,3,3),12)
does(robot,move(3,3,5,2),13)
does(robot,move(5,2,7,1),14)
does(robot,move(7,1,6,3),15)
does(robot,move(6,3,5,1),16)
does(robot,move(5,1,7,2),17)
does(robot,move(7,2,6,4),18)
does(robot,move(6,4,7,6),19)
does(robot,move(7,6,5,7),20)
does(robot,move(5,7,6,5),21)
does(robot,move(6,5,7,7),22)
does(robot,move(7,7,5,6),23)
does(robot,move(5,6,3,7),24)
does(robot,move(3,7,1,6),25)
does(robot,move(1,6,3,5),26)
does(robot,move(3,5,4,3),27)
does(robot,move(4,3,3,1),28)
does(robot,move(3,1,1,2),29)
does(robot,move(1,2,2,4),30)
does(robot,move(2,4,4,5),31)
does(robot,move(4,5,5,3),32)
does(robot,move(5,3,3,2),33)
does(robot,move(3,2,4,4),34)
does(robot,move(4,4,2,5),35)
does(robot,move(2,5,1,7),36)
does(robot,move(1,7,3,6),37)
does(robot,move(3,6,5,5),38)
does(robot,move(5,5,7,4),39)
does(robot,move(7,4,6,6),40)
does(robot,move(6,6,4,7),41)
does(robot,move(4,7,2,6),42)
does(robot,move(2,6,3,4),43)
does(robot,move(3,4,1,3),44)
does(robot,move(1,3,2,1),45)
does(robot,move(2,1,4,2),46)
does(robot,move(4,2,6,1),47)
does(robot,move(6,1,7,3),48)
role(robot).
base(cell(M,N,P)) :- row(M), col(N), piece(P).
base(captures(M)) :- scoremap(M,N).
base(step(N)) :- succ(M,N).
input(robot,move(M1,N1,M2,N2)) :- row(M1), col(N1), knightmove(M1,N1,M2,N2).
row(1).
row(2).
row(3).
row(4).
row(5).
row(6).
row(7).
col(1).
col(2).
col(3).
col(4).
col(5).
col(6).
col(7).
piece(knight).
piece(pawn).
piece(blank).
true(cell(1,1,knight),1).
true(cell(1,2,pawn),1).
true(cell(1,3,pawn),1).
true(cell(1,4,pawn),1).
true(cell(1,5,pawn),1).
true(cell(1,6,pawn),1).
true(cell(1,7,pawn),1).
true(cell(2,1,pawn),1).
true(cell(2,2,pawn),1).
true(cell(2,3,pawn),1).
true(cell(2,4,pawn),1).
true(cell(2,5,pawn),1).
true(cell(2,6,pawn),1).
true(cell(2,7,pawn),1).
true(cell(3,1,pawn),1).
true(cell(3,2,pawn),1).
true(cell(3,3,pawn),1).
true(cell(3,4,pawn),1).
true(cell(3,5,pawn),1).
true(cell(3,6,pawn),1).
true(cell(3,7,pawn),1).
true(cell(4,1,pawn),1).
true(cell(4,2,pawn),1).
true(cell(4,3,pawn),1).
true(cell(4,4,pawn),1).
true(cell(4,5,pawn),1).
true(cell(4,6,pawn),1).
true(cell(4,7,pawn),1).
true(cell(5,1,pawn),1).
true(cell(5,2,pawn),1).
true(cell(5,3,pawn),1).
true(cell(5,4,pawn),1).
true(cell(5,5,pawn),1).
true(cell(5,6,pawn),1).
true(cell(5,7,pawn),1).
true(cell(6,1,pawn),1).
true(cell(6,2,pawn),1).
true(cell(6,3,pawn),1).
true(cell(6,4,pawn),1).
true(cell(6,5,pawn),1).
true(cell(6,6,pawn),1).
true(cell(6,7,pawn),1).
true(cell(7,1,pawn),1).
true(cell(7,2,pawn),1).
true(cell(7,3,pawn),1).
true(cell(7,4,pawn),1).
true(cell(7,5,pawn),1).
true(cell(7,6,pawn),1).
true(cell(7,7,pawn),1).
true(captures(0),1).
true(step(1),1).
legal(robot,move(M1,N1,M2,N2),T) :- time(T), true(cell(M1,N1,knight),T), knightmove(M1,N1,M2,N2).
true(cell(M2,N2,knight),T+1) :- time(T), does(robot,move(M1,N1,M2,N2),T).
true(cell(M1,N1,blank),T+1) :- time(T), does(robot,move(M1,N1,M2,N2),T).
true(cell(U,V,pawn),T+1) :- time(T), true(cell(U,V,pawn),T), does(robot,move(M1,N1,M2,N2),T), U!=M2.
true(cell(U,V,pawn),T+1) :- time(T), true(cell(U,V,pawn),T), does(robot,move(M1,N1,M2,N2),T), V!=N2.
true(cell(U,V,blank),T+1) :- time(T), true(cell(U,V,blank),T), does(robot,move(M1,N1,M2,N2),T), U!=M2.
true(cell(U,V,blank),T+1) :- time(T), true(cell(U,V,blank),T), does(robot,move(M1,N1,M2,N2),T), V!=N2.
true(captures(OLD),T+1) :- time(T), does(robot,move(M1,N1,M2,N2),T), true(cell(M2,N2,blank),T), true(captures(OLD),T).
true(captures(NEW),T+1) :- time(T), does(robot,move(M1,N1,M2,N2),T), true(cell(M2,N2,pawn),T), true(captures(OLD),T), succ(OLD,NEW).
true(step(NEW),T+1) :- time(T), true(step(OLD),T), succ(OLD,NEW).
goal(robot,GOAL,T) :- time(T), true(captures(COUNT),T), scoremap(COUNT,GOAL).
terminal(T) :- time(T), true(step(49),T).
knightmove(M1,N1,M2,N2) :- time(T), add1row(M1,M2), add2col(N1,N2).
knightmove(M1,N1,M2,N2) :- time(T), add1row(M1,M2), add2col(N2,N1).
knightmove(M1,N1,M2,N2) :- time(T), add1row(M2,M1), add2col(N1,N2).
knightmove(M1,N1,M2,N2) :- time(T), add1row(M2,M1), add2col(N2,N1).
knightmove(M1,N1,M2,N2) :- time(T), add2row(M1,M2), add1col(N1,N2).
knightmove(M1,N1,M2,N2) :- time(T), add2row(M1,M2), add1col(N2,N1).
knightmove(M1,N1,M2,N2) :- time(T), add2row(M2,M1), add1col(N1,N2).
knightmove(M1,N1,M2,N2) :- time(T), add2row(M2,M1), add1col(N2,N1).
succ(0,1).
succ(1,2).
succ(2,3).
succ(3,4).
succ(4,5).
succ(5,6).
succ(6,7).
succ(7,8).
succ(8,9).
succ(9,10).
succ(10,11).
succ(11,12).
succ(12,13).
succ(13,14).
succ(14,15).
succ(15,16).
succ(16,17).
succ(17,18).
succ(18,19).
succ(19,20).
succ(20,21).
succ(21,22).
succ(22,23).
succ(23,24).
succ(24,25).
succ(25,26).
succ(26,27).
succ(27,28).
succ(28,29).
succ(29,30).
succ(30,31).
succ(31,32).
succ(32,33).
succ(33,34).
succ(34,35).
succ(35,36).
succ(36,37).
succ(37,38).
succ(38,39).
succ(39,40).
succ(40,41).
succ(41,42).
succ(42,43).
succ(43,44).
succ(44,45).
succ(45,46).
succ(46,47).
succ(47,48).
succ(48,49).
add1row(1,2).
add1row(2,3).
add1row(3,4).
add1row(4,5).
add1row(5,6).
add1row(6,7).
add2row(1,3).
add2row(2,4).
add2row(3,5).
add2row(4,6).
add2row(5,7).
add1col(1,2).
add1col(2,3).
add1col(3,4).
add1col(4,5).
add1col(5,6).
add1col(6,7).
add2col(1,3).
add2col(2,4).
add2col(3,5).
add2col(4,6).
add2col(5,7).
scoremap(0,4).
scoremap(1,6).
scoremap(2,8).
scoremap(3,10).
scoremap(4,12).
scoremap(5,14).
scoremap(6,16).
scoremap(7,18).
scoremap(8,20).
scoremap(9,22).
scoremap(10,24).
scoremap(11,26).
scoremap(12,28).
scoremap(13,30).
scoremap(14,32).
scoremap(15,34).
scoremap(16,36).
scoremap(17,38).
scoremap(18,40).
scoremap(19,42).
scoremap(20,44).
scoremap(21,46).
scoremap(22,48).
scoremap(23,50).
scoremap(24,52).
scoremap(25,54).
scoremap(26,56).
scoremap(27,58).
scoremap(28,60).
scoremap(29,62).
scoremap(30,64).
scoremap(31,66).
scoremap(32,68).
scoremap(33,70).
scoremap(34,72).
scoremap(35,74).
scoremap(36,76).
scoremap(37,78).
scoremap(38,80).
scoremap(39,82).
scoremap(40,84).
scoremap(41,86).
scoremap(42,88).
scoremap(43,90).
scoremap(44,92).
scoremap(45,94).
scoremap(46,96).
scoremap(47,98).
scoremap(48,100).
:- does(R,M,T), not legal(R,M,T).
time(1..49).
1{ does(R,M,T) : input(R,M) }1 :- role(R), time(T), 1 <= T, T <= 48.
:- not goal(robot,100,49).
SOLUTION (reaches goal 100, takes 34,358 seconds on my PC altogether with 11 threads, 3171 seconds for the good thread):
does(robot,move(1,1,2,3),1)
does(robot,move(2,3,1,5),2)
does(robot,move(1,5,2,7),3)
does(robot,move(2,7,4,6),4)
does(robot,move(4,6,6,7),5)
does(robot,move(6,7,7,5),6)
does(robot,move(7,5,5,4),7)
does(robot,move(5,4,6,2),8)
does(robot,move(6,2,4,1),9)
does(robot,move(4,1,2,2),10)
does(robot,move(2,2,1,4),11)
does(robot,move(1,4,3,3),12)
does(robot,move(3,3,5,2),13)
does(robot,move(5,2,7,1),14)
does(robot,move(7,1,6,3),15)
does(robot,move(6,3,5,1),16)
does(robot,move(5,1,7,2),17)
does(robot,move(7,2,6,4),18)
does(robot,move(6,4,7,6),19)
does(robot,move(7,6,5,7),20)
does(robot,move(5,7,6,5),21)
does(robot,move(6,5,7,7),22)
does(robot,move(7,7,5,6),23)
does(robot,move(5,6,3,7),24)
does(robot,move(3,7,1,6),25)
does(robot,move(1,6,3,5),26)
does(robot,move(3,5,4,3),27)
does(robot,move(4,3,3,1),28)
does(robot,move(3,1,1,2),29)
does(robot,move(1,2,2,4),30)
does(robot,move(2,4,4,5),31)
does(robot,move(4,5,5,3),32)
does(robot,move(5,3,3,2),33)
does(robot,move(3,2,4,4),34)
does(robot,move(4,4,2,5),35)
does(robot,move(2,5,1,7),36)
does(robot,move(1,7,3,6),37)
does(robot,move(3,6,5,5),38)
does(robot,move(5,5,7,4),39)
does(robot,move(7,4,6,6),40)
does(robot,move(6,6,4,7),41)
does(robot,move(4,7,2,6),42)
does(robot,move(2,6,3,4),43)
does(robot,move(3,4,1,3),44)
does(robot,move(1,3,2,1),45)
does(robot,move(2,1,4,2),46)
does(robot,move(4,2,6,1),47)
does(robot,move(6,1,7,3),48)