Skip to content

Commit 89c4074

Browse files
committed
Improve
1 parent fb60eca commit 89c4074

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

cellular_automata/wa_tor.py

+22-27
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
"""
22
Wa-Tor algorithm (1984)
33
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
97
108
This solution aims to completely remove any systematic approach
119
to the Wa-Tor planet, and utilise fully random methods.
@@ -100,7 +98,7 @@ class WaTor:
10098
:attr time_passed: A function that is called every time
10199
time passes (a chronon) in order to visually display
102100
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.
104102
105103
>>> wt = WaTor(10, 15)
106104
>>> wt.width
@@ -353,12 +351,12 @@ def perform_prey_actions(
353351
Performs the actions for a prey entity
354352
355353
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.
362360
363361
>>> wt = WaTor(WIDTH, HEIGHT)
364362
>>> reproducable_entity = Entity(True, coords=(0, 1))
@@ -384,15 +382,15 @@ def perform_predator_actions(
384382
:param occupied_by_prey_coords: Move to this location if there is prey there
385383
386384
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.
396394
397395
>>> wt = WaTor(WIDTH, HEIGHT)
398396
>>> 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:
486484
an ascii code in terminal to clear and re-print
487485
the Wa-Tor planet at intervals.
488486
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``
495490
496491
>>> wt = WaTor(30, 30)
497492
>>> wt.set_planet([

0 commit comments

Comments
 (0)