1
1
"""
2
2
Wa-Tor algorithm (1984)
3
3
4
- @ https://en.wikipedia.org/wiki/Wa-Tor
5
- @ https://beltoforion.de/en/wator/
6
- @ 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
7
7
8
8
This solution aims to completely remove any systematic approach
9
9
to the Wa-Tor planet, and utilise fully random methods.
@@ -97,8 +97,8 @@ class WaTor:
97
97
98
98
:attr time_passed: A function that is called every time
99
99
time passes (a chronon) in order to visually display
100
- the new Wa-Tor planet. The time_passed function can block
101
- using time.sleep to slow the algorithm progression.
100
+ the new Wa-Tor planet. The ` time_passed` function can block
101
+ using `` time.sleep`` to slow the algorithm progression.
102
102
103
103
>>> wt = WaTor(10, 15)
104
104
>>> wt.width
@@ -216,7 +216,7 @@ def get_surrounding_prey(self, entity: Entity) -> list[Entity]:
216
216
"""
217
217
Returns all the prey entities around (N, S, E, W) a predator entity.
218
218
219
- Subtly different to the try_to_move_to_unoccupied square .
219
+ Subtly different to the `move_and_reproduce` .
220
220
221
221
>>> wt = WaTor(WIDTH, HEIGHT)
222
222
>>> wt.set_planet([
@@ -260,7 +260,7 @@ def move_and_reproduce(
260
260
"""
261
261
Attempts to move to an unoccupied neighbouring square
262
262
in either of the four directions (North, South, East, West).
263
- If the move was successful and the remaining_reproduction time is
263
+ If the move was successful and the `remaining_reproduction_time` is
264
264
equal to 0, then a new prey or predator can also be created
265
265
in the previous square.
266
266
@@ -351,12 +351,12 @@ def perform_prey_actions(
351
351
Performs the actions for a prey entity
352
352
353
353
For prey the rules are:
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.
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.
360
360
361
361
>>> wt = WaTor(WIDTH, HEIGHT)
362
362
>>> reproducable_entity = Entity(True, coords=(0, 1))
@@ -382,15 +382,15 @@ def perform_predator_actions(
382
382
:param occupied_by_prey_coords: Move to this location if there is prey there
383
383
384
384
For predators the rules are:
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.
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.
394
394
395
395
>>> wt = WaTor(WIDTH, HEIGHT)
396
396
>>> wt.set_planet([[Entity(True, coords=(0, 0)), Entity(False, coords=(0, 1))]])
@@ -430,7 +430,7 @@ def perform_predator_actions(
430
430
431
431
def run (self , * , iteration_count : int ) -> None :
432
432
"""
433
- Emulate time passing by looping iteration_count times
433
+ Emulate time passing by looping ` iteration_count` times
434
434
435
435
>>> wt = WaTor(WIDTH, HEIGHT)
436
436
>>> wt.run(iteration_count=PREDATOR_INITIAL_ENERGY_VALUE - 1)
@@ -484,11 +484,9 @@ def visualise(wt: WaTor, iter_number: int, *, colour: bool = True) -> None:
484
484
an ascii code in terminal to clear and re-print
485
485
the Wa-Tor planet at intervals.
486
486
487
- Uses ascii colour codes to colourfully display
488
- the predators and prey.
489
-
490
- (0x60f197) Prey = #
491
- (0xfffff) Predator = x
487
+ Uses ascii colour codes to colourfully display the predators and prey:
488
+ * (0x60f197) Prey = ``#``
489
+ * (0xfffff) Predator = ``x``
492
490
493
491
>>> wt = WaTor(30, 30)
494
492
>>> wt.set_planet([
0 commit comments