Performs the actions for a prey entity For prey the rules are: 1. At each chronon, a prey moves randomly to one of the adjacent unoccupied squares. If there are no free squares, no movement takes place. 2. Once a prey has survived a certain nu
(
self, entity: Entity, direction_orders: list[Literal["N", "E", "S", "W"]]
)
| 345 | entity.remaining_reproduction_time -= 1 |
| 346 | |
| 347 | def perform_prey_actions( |
| 348 | self, entity: Entity, direction_orders: list[Literal["N", "E", "S", "W"]] |
| 349 | ) -> None: |
| 350 | """ |
| 351 | Performs the actions for a prey entity |
| 352 | |
| 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. |
| 360 | |
| 361 | >>> wt = WaTor(WIDTH, HEIGHT) |
| 362 | >>> reproducable_entity = Entity(True, coords=(0, 1)) |
| 363 | >>> reproducable_entity.remaining_reproduction_time = 0 |
| 364 | >>> wt.planet = [[None, reproducable_entity]] |
| 365 | >>> wt.perform_prey_actions(reproducable_entity, |
| 366 | ... direction_orders=["N", "W", "S", "E"]) |
| 367 | >>> wt.planet # doctest: +NORMALIZE_WHITESPACE |
| 368 | [[Entity(prey=True, coords=(0, 0), remaining_reproduction_time=5), |
| 369 | Entity(prey=True, coords=(0, 1), remaining_reproduction_time=5)]] |
| 370 | """ |
| 371 | self.move_and_reproduce(entity, direction_orders) |
| 372 | |
| 373 | def perform_predator_actions( |
| 374 | self, |