This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/Logtalk/examples/bricks/brick_stack.lgt
pmoura 75392e54c7 Logtalk 2.15.0 release files.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@757 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
2003-02-05 00:15:28 +00:00

60 lines
988 B
Plaintext

:- object(brick_stack,
instantiates(constrained_relation)).
:- info([
version is 1.0,
date is 1998/3/23,
author is 'Paulo Moura',
comment is 'Stack of bricks as a constrained binary relation.']).
descriptor_([top, bottom]).
domain_(top, brick).
domain_(bottom, brick).
key_([top, bottom]).
cardinality_(top, 0, 1).
cardinality_(bottom, 0, 1).
delete_option_(top, cascade).
delete_option_(bottom, restrict).
add_tuple([A, B]) :-
B::position(Xb, Yb),
Ya2 is Yb + 1,
{A::move(Xb, Ya2)},
^^add_tuple([A, B]).
activ_points_(top, before, []).
activ_points_(top, after, [move(_, _)]).
activ_points_(bottom, before, []).
activ_points_(bottom, after, [move(_, _)]).
propagate(after, move(X, Y), Top, top, [Top, Bottom]) :-
!,
Y2 is Y - 1,
(Bottom::position(X, Y2) ->
true
;
::remove_tuple([Top, Bottom])).
propagate(after, move(X, Y), Bottom, bottom, [Top, Bottom]) :-
!,
Y2 is Y + 1,
{Top::move(X, Y2)}.
:- end_object.