161
less_eq(A2,E).
%Thischecksiftheaddressrangeisinthesourceofamove
%foranychangeinS.
moved(A1,A2,S):-
member(M1,S),
operation(M1,move(B,E,_)),
less_eq(B,A1),
less_eq(A2,E).
next_address(LIST,R,T):-
proper_addresses(LIST,ALL),
member(T,ALL),
less(R,T),
not(between(ALL,X,R,T)).
between(ALL,X,R,T):-
member(X,ALL),
member(R,ALL),
member(T,ALL),
less(R,X),
less(X,T).
list_addresses(LIST,V1,[V1|T]):-
next_address(LIST,V1,H2),!,
list_addresses(LIST,H2,T).
list_addresses(LIST,V1,[V1]):-
not(next_address(LIST,V1,X)),!.
address_sequence(List,Result):-
proper_addresses(List,All),mergesort(All,Result).
%EnumerateallmoveswithlowerprioritythanthemovewithIDI.
recessive_moves(I,[],[]).
recessive_moves(I,[M|X],[M|S]):-
is_move(I),
is_move(M),
M=<I,!,
recessive_moves(I,X,S).
recessive_moves(I,X,[M|S]):-
is_move(I),
recessive_moves(I,X,S).
162
%avarietyofutilityfunctions.
%mergetwosortedlistsofaddresses.
merge(L1,[H|L2],[H|M]):-
less_than_head(H,L1),
!,
merge(L1,L2,M).
merge([H|L1],L2,[H|M]):-
merge(L1,L2,M).
merge([],L2,L2).
%Checkifanitemissmallerthantheheadofalist.Efficiency
%functionformerge.
less_than_head(X,[H|_]):-less(X,H).
%Mergesortforalistofaddresses.
mergesort([],[]).
mergesort([X],[X]).
mergesort(A,B):-
split(A,X,Y),
mergesort(X,XS),
mergesort(Y,YS),
merge(XS,YS,B),
!.
%Auxiliaryfunctionformergesortthatsplitsalistintoequal-sized
%pieces.
split([],[],[]).
split([A,B|T],[A|X],[B|Y]):-split(T,X,Y),!.
split([A],[A],[]).
%Listutilities:
append([],X,X).
append([X|Y],Z,[X|R]):-append(Y,Z,R).
ordered_list([]).
ordered_list([_]).
ordered_list([A,B|T]):-
less(A,B),
ordered_list([B|T]).
remove(_,[],[]).
Previous Page Next Page