%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% /gamemaster/library/knightstour/rulesheet.hrf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% metadata
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
role(robot)
base(movecount(M)) :- scoremap(M,N)
base(cell(M,N,P)) :- col(M) & row(N) & piece(P)
base(control(robot))
action(move(X1,Y1,X2,Y2)) :- col(X1) & row(Y1) & knightMove(X1,Y1,X2,Y2)
row(1)
row(2)
row(3)
row(4)
row(5)
col(1)
col(2)
col(3)
col(4)
col(5)
col(6)
piece(knight)
piece(hole)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% init
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
init(movecount(0))
init(cell(1,1,knight))
init(control(robot))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% legal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
legal(move(X1,Y1,X2,Y2)) :-
cell(X1,Y1,knight) &
knightMove(X1,Y1,X2,Y2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% operations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
move(X1,Y1,X2,Y2) :: cell(X1,Y1,hole)
move(X1,Y1,X2,Y2) ::
cell(X1,Y1,knight)
==> ~cell(X1,Y1,knight) & cell(X2,Y2,knight)
move(X1,Y1,X2,Y2) ::
movecount(Old) & add(1,count,Old,New)
==> ~movecount(Old) & movecount(New)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% goal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
goal(robot,Goal) :- movecount(Count) & scoremap(Count,Goal)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% terminal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
terminal :- cell(X,Y,knight) & cell(X,Y,hole)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Views
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
knightMove(X1,Y1,X2,Y2) :- add(1,x,X1,X2) & add(2,y,Y1,Y2)
knightMove(X1,Y1,X2,Y2) :- add(1,x,X1,X2) & add(2,y,Y2,Y1)
knightMove(X1,Y1,X2,Y2) :- add(1,x,X2,X1) & add(2,y,Y1,Y2)
knightMove(X1,Y1,X2,Y2) :- add(1,x,X2,X1) & add(2,y,Y2,Y1)
knightMove(X1,Y1,X2,Y2) :- add(2,x,X1,X2) & add(1,y,Y1,Y2)
knightMove(X1,Y1,X2,Y2) :- add(2,x,X1,X2) & add(1,y,Y2,Y1)
knightMove(X1,Y1,X2,Y2) :- add(2,x,X2,X1) & add(1,y,Y1,Y2)
knightMove(X1,Y1,X2,Y2) :- add(2,x,X2,X1) & add(1,y,Y2,Y1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Facts
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
add(1,count,0,1)
add(1,count,1,2)
add(1,count,2,3)
add(1,count,3,4)
add(1,count,4,5)
add(1,count,5,6)
add(1,count,6,7)
add(1,count,7,8)
add(1,count,8,9)
add(1,count,9,10)
add(1,count,10,11)
add(1,count,11,12)
add(1,count,12,13)
add(1,count,13,14)
add(1,count,14,15)
add(1,count,15,16)
add(1,count,16,17)
add(1,count,17,18)
add(1,count,18,19)
add(1,count,19,20)
add(1,count,20,21)
add(1,count,21,22)
add(1,count,22,23)
add(1,count,23,24)
add(1,count,24,25)
add(1,count,25,26)
add(1,count,26,27)
add(1,count,27,28)
add(1,count,28,29)
add(1,count,29,30)
add(1,x,1,2)
add(1,x,2,3)
add(1,x,3,4)
add(1,x,4,5)
add(1,x,5,6)
add(1,y,1,2)
add(1,y,2,3)
add(1,y,3,4)
add(1,y,4,5)
add(2,x,1,3)
add(2,x,2,4)
add(2,x,3,5)
add(2,x,4,6)
add(2,y,1,3)
add(2,y,2,4)
add(2,y,3,5)
scoremap(0,0)
scoremap(1,3)
scoremap(2,6)
scoremap(3,9)
scoremap(4,12)
scoremap(5,15)
scoremap(6,18)
scoremap(7,21)
scoremap(8,24)
scoremap(9,27)
scoremap(10,30)
scoremap(11,33)
scoremap(12,36)
scoremap(13,39)
scoremap(14,42)
scoremap(15,45)
scoremap(16,48)
scoremap(17,51)
scoremap(18,54)
scoremap(19,57)
scoremap(20,60)
scoremap(21,63)
scoremap(22,66)
scoremap(23,69)
scoremap(24,72)
scoremap(25,75)
scoremap(26,80)
scoremap(27,85)
scoremap(28,90)
scoremap(29,96)
scoremap(30,100)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%