root/trunk/examples/bricks/SCRIPT.txt

Revision 4662, 3.3 KB (checked in by pmoura, 6 days ago)

Updated copyright notice.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1================================================================
2Logtalk - Open source object-oriented logic programming language
3Release 2.35.0
4
5Copyright (c) 1998-2009 Paulo Moura.        All Rights Reserved.
6Logtalk is free software.  You can redistribute it and/or modify
7it under the terms of the "Artistic License 2.0" as published by
8The Perl Foundation. Consult the "LICENSE.txt" file for details.
9================================================================
10
11
12% start by loading the example and the required library files:
13
14| ?- logtalk_load(bricks(loader)).
15...
16
17
18% create four bricks, all standing on the "ground" (use your imagination... ;-)
19
20| ?- brick::(new(a, [position-(8, 1)]), new(b, [position-(6, 1)]), new(c, [position-(4, 1)]), new(d, [position-(2, 1)])).
21yes
22
23% set up ascii stack monitor so we can watch the bricks moving
24
25| ?- after_event_registry::set_monitor(_, move(_,_), _, stack_monitor).
26yes
27
28
29% make the stack
30
31| ?- brick_stack::(add_tuple([c,d]), add_tuple([b,c]), add_tuple([a,b])).
32|.c......
33|.d...b.a
34---------
35|.b......
36|.c......
37|.d.....a
38---------
39|.a
40|.b
41|.c
42|.d
43---
44yes
45
46
47% check results
48
49| ?- brick_stack::tuple(Tuple), write(Tuple), nl, fail.
50[c,d]
51[b,c]
52[a,b]
53no
54
55| ?- before_event_registry::monitors(Mb), after_event_registry::monitors(Ma).
56Ma = [brick_stack, stack_monitor]
57Mb = [brick_stack]
58yes
59
60
61% move all stack to new position by moving bottom brick; check results
62
63| ?- d::move(9, 1).
64|.a.......
65|.b.......
66|.c.......
67|........d
68----------
69|.a.......
70|.b.......
71|........c
72|........d
73----------
74|.a.......
75|........b
76|........c
77|........d
78----------
79|........a
80|........b
81|........c
82|........d
83----------
84yes
85
86| ?- a::position(Xa, Ya), b::position(Xb, Yb), c::position(Xc, Yc), d::position(Xd, Yd).
87Xa = 9,
88Xb = 9,
89Xc = 9,
90Xd = 9,
91Ya = 4,
92Yb = 3,
93Yc = 2,
94Yd = 1
95yes
96
97| ?- brick_stack::tuple(Tuple), write(Tuple), nl, fail.
98[c,d]
99[b,c]
100[a,b]
101no
102
103
104% break stack in half by moving b to the "ground"; check results
105
106| ?- b::move(3, 1).
107|........a
108|.........
109|........c
110|..b.....d
111----------
112|..a.....c
113|..b.....d
114----------
115yes
116
117| ?- a::position(Xa, Ya), b::position(Xb, Yb), c::position(Xc, Yc), d::position(Xd, Yd).
118Xa = 3,
119Xb = 3,
120Xc = 9,
121Xd = 9,
122Ya = 2,
123Yb = 1,
124Yc = 2,
125Yd = 1
126yes
127
128| ?- brick_stack::tuple(Tuple), write(Tuple), nl, fail.
129[c,d]
130[a,b]
131no
132
133
134% create new brick_stack tuple ; check results
135
136| ?- brick_stack::add_tuple([d, a]).
137|..d......
138|..a.....c
139|..b......
140----------
141|..c
142|..d
143|..a
144|..b
145----
146yes
147
148| ?- a::position(Xa, Ya), b::position(Xb, Yb), c::position(Xc, Yc), d::position(Xd, Yd).
149Xa = 3,
150Xb = 3,
151Xc = 3,
152Xd = 3,
153Ya = 2,
154Yb = 1,
155Yc = 4,
156Yd = 3
157yes
158
159| ?- brick_stack::tuple(Tuple), write(Tuple), nl, fail.
160[c,d]
161[a,b]
162[d,a]
163no
164
165
166% move all stack to new position by moving bottom brick; check results
167
168| ?- b::move(5, 1).
169|..c..
170|..d..
171|..a..
172|....b
173------
174|..c..
175|..d..
176|....a
177|....b
178------
179|..c..
180|....d
181|....a
182|....b
183------
184|....c
185|....d
186|....a
187|....b
188------
189yes
190
191| ?- a::position(Xa, Ya), b::position(Xb, Yb), c::position(Xc, Yc), d::position(Xd, Yd).
192Xa = 5,
193Xb = 5,
194Xc = 5,
195Xd = 5,
196Ya = 2,
197Yb = 1,
198Yc = 4,
199Yd = 3
200yes
201
202| ?- brick_stack::tuple(Tuple), write(Tuple), nl, fail.
203[c,d]
204[a,b]
205[d,a]
206no
207
208
209% clean up instances, tuples and monitors
210
211| ?- brick_stack::remove_all_tuples.
212yes
213
214| ?- after_event_registry::del_monitors(_, _, _, stack_monitor).
215yes
216
217| ?- brick::delete_all.
218yes
Note: See TracBrowser for help on using the browser.