1
1
"""
2
2
Wa-Tor algorithm (1984)
3
3
4
- @ https://en.wikipedia.org/wiki/Wa-Tor
5
-
6
- @ https://beltoforion.de/en/wator/
7
-
8
- @ https://beltoforion.de/en/wator/images/wator_medium.webm
4
+ | @ https://en.wikipedia.org/wiki/Wa-Tor
5
+ | @ https://beltoforion.de/en/wator/
6
+ | @ https://beltoforion.de/en/wator/images/wator_medium.webm
9
7
10
8
This solution aims to completely remove any systematic approach
11
9
to the Wa-Tor planet, and utilise fully random methods.
@@ -100,7 +98,7 @@ class WaTor:
100
98
:attr time_passed: A function that is called every time
101
99
time passes (a chronon) in order to visually display
102
100
the new Wa-Tor planet. The `time_passed` function can block
103
- using `time.sleep` to slow the algorithm progression.
101
+ using `` time.sleep` ` to slow the algorithm progression.
104
102
105
103
>>> wt = WaTor(10, 15)
106
104
>>> wt.width
@@ -353,12 +351,12 @@ def perform_prey_actions(
353
351
Performs the actions for a prey entity
354
352
355
353
For prey the rules are:
356
- 1. At each chronon, a prey moves randomly to one of the adjacent unoccupied
357
- squares. If there are no free squares, no movement takes place.
358
- 2. Once a prey has survived a certain number of chronons it may reproduce.
359
- This is done as it moves to a neighbouring square,
360
- leaving behind a new prey in its old position.
361
- Its reproduction time is also reset to zero.
354
+ 1. At each chronon, a prey moves randomly to one of the adjacent unoccupied
355
+ squares. If there are no free squares, no movement takes place.
356
+ 2. Once a prey has survived a certain number of chronons it may reproduce.
357
+ This is done as it moves to a neighbouring square,
358
+ leaving behind a new prey in its old position.
359
+ Its reproduction time is also reset to zero.
362
360
363
361
>>> wt = WaTor(WIDTH, HEIGHT)
364
362
>>> reproducable_entity = Entity(True, coords=(0, 1))
@@ -384,15 +382,15 @@ def perform_predator_actions(
384
382
:param occupied_by_prey_coords: Move to this location if there is prey there
385
383
386
384
For predators the rules are:
387
- 1. At each chronon, a predator moves randomly to an adjacent square occupied
388
- by a prey. If there is none, the predator moves to a random adjacent
389
- unoccupied square. If there are no free squares, no movement takes place.
390
- 2. At each chronon, each predator is deprived of a unit of energy.
391
- 3. Upon reaching zero energy, a predator dies.
392
- 4. If a predator moves to a square occupied by a prey,
393
- it eats the prey and earns a certain amount of energy.
394
- 5. Once a predator has survived a certain number of chronons
395
- it may reproduce in exactly the same way as the prey.
385
+ 1. At each chronon, a predator moves randomly to an adjacent square occupied
386
+ by a prey. If there is none, the predator moves to a random adjacent
387
+ unoccupied square. If there are no free squares, no movement takes place.
388
+ 2. At each chronon, each predator is deprived of a unit of energy.
389
+ 3. Upon reaching zero energy, a predator dies.
390
+ 4. If a predator moves to a square occupied by a prey,
391
+ it eats the prey and earns a certain amount of energy.
392
+ 5. Once a predator has survived a certain number of chronons
393
+ it may reproduce in exactly the same way as the prey.
396
394
397
395
>>> wt = WaTor(WIDTH, HEIGHT)
398
396
>>> wt.set_planet([[Entity(True, coords=(0, 0)), Entity(False, coords=(0, 1))]])
@@ -486,12 +484,9 @@ def visualise(wt: WaTor, iter_number: int, *, colour: bool = True) -> None:
486
484
an ascii code in terminal to clear and re-print
487
485
the Wa-Tor planet at intervals.
488
486
489
- Uses ascii colour codes to colourfully display
490
- the predators and prey.
491
-
492
- (0x60f197) Prey = #
493
-
494
- (0xfffff) Predator = x
487
+ Uses ascii colour codes to colourfully display the predators and prey:
488
+ * (0x60f197) Prey = ``#``
489
+ * (0xfffff) Predator = ``x``
495
490
496
491
>>> wt = WaTor(30, 30)
497
492
>>> wt.set_planet([
0 commit comments