More tests for CA evolution... need to implement classes.
catseye
12 years ago
227 | 227 | = ----- |
228 | 228 | |
229 | 229 | ##### Boolean Expressions ##### |
230 | ||
231 | -> Tests for functionality "Parse ALPACA Description" | |
232 | 230 | |
233 | 231 | The boolean expression may be: |
234 | 232 | |
254 | 252 | Example: a cellular automaton where `Thing`s become `Spaces` only |
255 | 253 | if the cell to the east is a `Thing`: |
256 | 254 | |
257 | | state Space; | |
258 | | state Thing | |
259 | | to Space when > Thing. | |
260 | = ok | |
255 | | state Space " "; | |
256 | | state Thing "*" | |
257 | | to Space when > Thing | |
258 | | begin | |
259 | | * | |
260 | | ** | |
261 | = ----- | |
262 | = * | |
263 | = * | |
264 | = ----- | |
261 | 265 | |
262 | 266 | For more clarity, an equals sign may occur between the two state referents. |
263 | 267 | |
264 | 268 | Example: a cellular automaton where `Thing`s become `Space`s only |
265 | 269 | if the cell to the north and the cell to the south are the same state: |
266 | 270 | |
267 | | state Space; | |
268 | | state Thing | |
269 | | to Space when ^ = v. | |
270 | = ok | |
271 | | state Space " "; | |
272 | | state Thing "*" | |
273 | | to Space when ^ = v | |
274 | | begin | |
275 | | * | |
276 | | ** | |
277 | = ----- | |
278 | = * | |
279 | = * | |
280 | = ----- | |
271 | 281 | |
272 | 282 | A class-inclusion predicate is similar to a state predicate, but instead |
273 | 283 | of a state referent, the second term is a class referent. An example will |
287 | 297 | Example: a cellular automaton where `Thing`s become `Space`s only if they |
288 | 298 | are not adjacent to three other `Thing`s. |
289 | 299 | |
290 | | state Space; | |
291 | | state Thing | |
292 | | to Space when not 3 Thing. | |
293 | = ok | |
300 | | state Space " "; | |
301 | | state Thing "*" | |
302 | | to Space when not 3 Thing | |
303 | | begin | |
304 | | * | |
305 | | ** | |
306 | | * | |
307 | = ----- | |
308 | = ** | |
309 | = ----- | |
294 | 310 | |
295 | 311 | ### Classes ### |
296 | 312 | |
303 | 319 | a state of the other type to the north, but they will both turn into |
304 | 320 | `Space` when there is a `Space` to the east. |
305 | 321 | |
306 | | state Space; | |
322 | | state Space " "; | |
307 | 323 | | class Animal |
308 | 324 | | to Space when > Space; |
309 | | state Dog is Animal | |
325 | | state Dog "d" is Animal | |
310 | 326 | | to Cat when ^ Cat; |
311 | | state Cat is Animal | |
312 | | to Dog when ^ Dog. | |
313 | = ok | |
327 | | state Cat "c" is Animal | |
328 | | to Dog when ^ Dog | |
329 | | begin | |
330 | | ccd | |
331 | | dcc | |
332 | = ----- | |
333 | = dc | |
334 | = cc | |
335 | = ----- | |
314 | 336 | |
315 | 337 | Each state can belong to zero or more classes. When it belongs to more |
316 | 338 | than one, class the transition rules for each class are applied in order |
323 | 345 | In it, `One`s always remain `One`s, `Two`s always remain `Two`s, and `Three`s |
324 | 346 | always remain `Three`s. |
325 | 347 | |
348 | | state Space " "; | |
326 | 349 | | class AlphaType |
327 | 350 | | to One when true; |
328 | 351 | | class BetaType |
329 | 352 | | to Two when true; |
330 | | state One is AlphaType is BetaType; | |
331 | | state Two is BetaType is AlphaType; | |
332 | | state Three is BetaType is AlphaType | |
333 | | to Three when true. | |
334 | = ok | |
353 | | state One "1" is AlphaType is BetaType; | |
354 | | state Two "2" is BetaType is AlphaType; | |
355 | | state Three "3" is BetaType is AlphaType | |
356 | | to Three when true | |
357 | | begin | |
358 | | 123 | |
359 | = ----- | |
360 | = 123 | |
361 | = ----- | |
335 | 362 | |
336 | 363 | In a transition rule, a class-inclusion predicate may be used by |
337 | 364 | giving a state referent, the token `is`, and the name of a class. |
342 | 369 | switch to the other when the cell to the north is not an `Animal` and turn |
343 | 370 | to `Space` when the cell to the east is an `Animal`. |
344 | 371 | |
345 | | state Space; | |
372 | | state Space " "; | |
346 | 373 | | class Animal |
347 | 374 | | to Space when > is Animal; |
348 | | state Dog is Animal | |
375 | | state Dog "d" is Animal | |
349 | 376 | | to Cat when not ^ is Animal; |
350 | | state Cat is Animal | |
351 | | to Dog when not ^ is Animal. | |
352 | = ok | |
377 | | state Cat "c" is Animal | |
378 | | to Dog when not ^ is Animal | |
379 | | begin | |
380 | | dcdc | |
381 | = ----- | |
382 | = dcdc | |
383 | = ----- | |
353 | 384 | |
354 | 385 | ### Neighbourhoods ### |
386 | ||
387 | -> Tests for functionality "Parse ALPACA Description" | |
355 | 388 | |
356 | 389 | A neighbourhood is a set of positions relative to a cell. A neighbourhood |
357 | 390 | is specified in ALPACA with a sequence of arrow chains inside parentheses. |