| 1 | ================================================================ |
|---|
| 2 | Logtalk - Open source object-oriented logic programming language |
|---|
| 3 | Release 2.35.0 |
|---|
| 4 | |
|---|
| 5 | Copyright (c) 1998-2009 Paulo Moura. All Rights Reserved. |
|---|
| 6 | Logtalk is free software. You can redistribute it and/or modify |
|---|
| 7 | it under the terms of the "Artistic License 2.0" as published by |
|---|
| 8 | The 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)])). |
|---|
| 21 | yes |
|---|
| 22 | |
|---|
| 23 | % set up ascii stack monitor so we can watch the bricks moving |
|---|
| 24 | |
|---|
| 25 | | ?- after_event_registry::set_monitor(_, move(_,_), _, stack_monitor). |
|---|
| 26 | yes |
|---|
| 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 | --- |
|---|
| 44 | yes |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | % check results |
|---|
| 48 | |
|---|
| 49 | | ?- brick_stack::tuple(Tuple), write(Tuple), nl, fail. |
|---|
| 50 | [c,d] |
|---|
| 51 | [b,c] |
|---|
| 52 | [a,b] |
|---|
| 53 | no |
|---|
| 54 | |
|---|
| 55 | | ?- before_event_registry::monitors(Mb), after_event_registry::monitors(Ma). |
|---|
| 56 | Ma = [brick_stack, stack_monitor] |
|---|
| 57 | Mb = [brick_stack] |
|---|
| 58 | yes |
|---|
| 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 | ---------- |
|---|
| 84 | yes |
|---|
| 85 | |
|---|
| 86 | | ?- a::position(Xa, Ya), b::position(Xb, Yb), c::position(Xc, Yc), d::position(Xd, Yd). |
|---|
| 87 | Xa = 9, |
|---|
| 88 | Xb = 9, |
|---|
| 89 | Xc = 9, |
|---|
| 90 | Xd = 9, |
|---|
| 91 | Ya = 4, |
|---|
| 92 | Yb = 3, |
|---|
| 93 | Yc = 2, |
|---|
| 94 | Yd = 1 |
|---|
| 95 | yes |
|---|
| 96 | |
|---|
| 97 | | ?- brick_stack::tuple(Tuple), write(Tuple), nl, fail. |
|---|
| 98 | [c,d] |
|---|
| 99 | [b,c] |
|---|
| 100 | [a,b] |
|---|
| 101 | no |
|---|
| 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 | ---------- |
|---|
| 115 | yes |
|---|
| 116 | |
|---|
| 117 | | ?- a::position(Xa, Ya), b::position(Xb, Yb), c::position(Xc, Yc), d::position(Xd, Yd). |
|---|
| 118 | Xa = 3, |
|---|
| 119 | Xb = 3, |
|---|
| 120 | Xc = 9, |
|---|
| 121 | Xd = 9, |
|---|
| 122 | Ya = 2, |
|---|
| 123 | Yb = 1, |
|---|
| 124 | Yc = 2, |
|---|
| 125 | Yd = 1 |
|---|
| 126 | yes |
|---|
| 127 | |
|---|
| 128 | | ?- brick_stack::tuple(Tuple), write(Tuple), nl, fail. |
|---|
| 129 | [c,d] |
|---|
| 130 | [a,b] |
|---|
| 131 | no |
|---|
| 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 | ---- |
|---|
| 146 | yes |
|---|
| 147 | |
|---|
| 148 | | ?- a::position(Xa, Ya), b::position(Xb, Yb), c::position(Xc, Yc), d::position(Xd, Yd). |
|---|
| 149 | Xa = 3, |
|---|
| 150 | Xb = 3, |
|---|
| 151 | Xc = 3, |
|---|
| 152 | Xd = 3, |
|---|
| 153 | Ya = 2, |
|---|
| 154 | Yb = 1, |
|---|
| 155 | Yc = 4, |
|---|
| 156 | Yd = 3 |
|---|
| 157 | yes |
|---|
| 158 | |
|---|
| 159 | | ?- brick_stack::tuple(Tuple), write(Tuple), nl, fail. |
|---|
| 160 | [c,d] |
|---|
| 161 | [a,b] |
|---|
| 162 | [d,a] |
|---|
| 163 | no |
|---|
| 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 | ------ |
|---|
| 189 | yes |
|---|
| 190 | |
|---|
| 191 | | ?- a::position(Xa, Ya), b::position(Xb, Yb), c::position(Xc, Yc), d::position(Xd, Yd). |
|---|
| 192 | Xa = 5, |
|---|
| 193 | Xb = 5, |
|---|
| 194 | Xc = 5, |
|---|
| 195 | Xd = 5, |
|---|
| 196 | Ya = 2, |
|---|
| 197 | Yb = 1, |
|---|
| 198 | Yc = 4, |
|---|
| 199 | Yd = 3 |
|---|
| 200 | yes |
|---|
| 201 | |
|---|
| 202 | | ?- brick_stack::tuple(Tuple), write(Tuple), nl, fail. |
|---|
| 203 | [c,d] |
|---|
| 204 | [a,b] |
|---|
| 205 | [d,a] |
|---|
| 206 | no |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | % clean up instances, tuples and monitors |
|---|
| 210 | |
|---|
| 211 | | ?- brick_stack::remove_all_tuples. |
|---|
| 212 | yes |
|---|
| 213 | |
|---|
| 214 | | ?- after_event_registry::del_monitors(_, _, _, stack_monitor). |
|---|
| 215 | yes |
|---|
| 216 | |
|---|
| 217 | | ?- brick::delete_all. |
|---|
| 218 | yes |
|---|