@@ -77,18 +77,18 @@ def reset_reproduction_time(self) -> None:
77
77
def __repr__ (self ) -> str :
78
78
"""
79
79
>>> Entity(prey=True, coords=(1, 1))
80
- <entity_type=prey coords=(1, 1) remaining_reproduction_time=5>
81
- >>> Entity(prey=False, coords=(2, 1))
82
- <entity_type=predator coords=(2, 1) remaining_reproduction_time=20 energy=15>
80
+ Entity(prey=True, coords=(1, 1), remaining_reproduction_time=5)
81
+ >>> Entity(prey=False, coords=(2, 1)) # doctest: +NORMALIZE_WHITESPACE
82
+ Entity(prey=False, coords=(2, 1),
83
+ remaining_reproduction_time=20, energy_value=15)
83
84
"""
84
85
repr_ = (
85
- f"entity_type={ 'prey' if self .prey is True else 'predator' } "
86
- f" coords={ self .coords } "
87
- f" remaining_reproduction_time={ self .remaining_reproduction_time } "
86
+ f"Entity(prey={ self .prey } , coords={ self .coords } , "
87
+ f"remaining_reproduction_time={ self .remaining_reproduction_time } "
88
88
)
89
- if self .prey is False :
90
- repr_ += f" energy ={ self .energy_value } "
91
- return f"< { repr_ } > "
89
+ if self .energy_value is not None :
90
+ repr_ += f", energy_value ={ self .energy_value } "
91
+ return f"{ repr_ } ) "
92
92
93
93
94
94
class WaTor :
@@ -230,8 +230,8 @@ def get_surrounding_prey(self, entity: Entity) -> list[Entity]:
230
230
... [None, Entity(True, (2, 1)), None]])
231
231
>>> wt.get_surrounding_prey(
232
232
... Entity(False, (1, 1))) # doctest: +NORMALIZE_WHITESPACE
233
- [<entity_type= prey coords=(2, 1) remaining_reproduction_time=5> ,
234
- <entity_type= prey coords=(0, 1) remaining_reproduction_time=5> ]
233
+ [Entity( prey=True, coords=(2, 1), remaining_reproduction_time=5) ,
234
+ Entity( prey=True, coords=(0, 1), remaining_reproduction_time=5) ]
235
235
>>> wt.set_planet([[Entity(False, (0, 0))]])
236
236
>>> wt.get_surrounding_prey(Entity(False, (0, 0)))
237
237
[]
@@ -240,7 +240,7 @@ def get_surrounding_prey(self, entity: Entity) -> list[Entity]:
240
240
... [None, Entity(False, (1, 1)), Entity(True, (2, 1))],
241
241
... [None, None, None]])
242
242
>>> wt.get_surrounding_prey(Entity(False, (1, 0)))
243
- [<entity_type= prey coords=(0, 0) remaining_reproduction_time=5> ]
243
+ [Entity( prey=True, coords=(0, 0), remaining_reproduction_time=5) ]
244
244
"""
245
245
coords = entity .coords
246
246
row , col = coords
@@ -302,25 +302,25 @@ def move_and_reproduce(
302
302
>>> wt.set_planet(planet)
303
303
>>> wt.move_and_reproduce(Entity(True, coords=(1, 1)), direction_orders=["N"])
304
304
>>> wt.planet # doctest: +NORMALIZE_WHITESPACE
305
- [[None, <entity_type= prey coords=(0, 1) remaining_reproduction_time=4> , None],
305
+ [[None, Entity( prey=True, coords=(0, 1), remaining_reproduction_time=4) , None],
306
306
[None, None, None],
307
307
[None, None, None]]
308
308
>>> wt.planet[0][0] = Entity(True, coords=(0, 0))
309
309
>>> wt.planet[0][2] = None
310
310
>>> wt.move_and_reproduce(Entity(True, coords=(0, 1)),
311
311
... direction_orders=["N", "W", "E", "S"])
312
312
>>> wt.planet # doctest: +NORMALIZE_WHITESPACE
313
- [[<entity_type= prey coords=(0, 0) remaining_reproduction_time=5> , None,
314
- <entity_type= prey coords=(0, 2) remaining_reproduction_time=4> ],
313
+ [[Entity( prey=True, coords=(0, 0), remaining_reproduction_time=5) , None,
314
+ Entity( prey=True, coords=(0, 2), remaining_reproduction_time=4) ],
315
315
[None, None, None],
316
316
[None, None, None]]
317
317
>>> wt.planet[0][1] = wt.planet[0][2]
318
318
>>> wt.planet[0][2] = None
319
319
>>> wt.move_and_reproduce(Entity(True, coords=(0, 1)),
320
320
... direction_orders=["N", "W", "S", "E"])
321
321
>>> wt.planet # doctest: +NORMALIZE_WHITESPACE
322
- [[<entity_type= prey coords=(0, 0) remaining_reproduction_time=5> , None, None],
323
- [None, <entity_type= prey coords=(1, 1) remaining_reproduction_time=4> , None],
322
+ [[Entity( prey=True, coords=(0, 0), remaining_reproduction_time=5) , None, None],
323
+ [None, Entity( prey=True, coords=(1, 1), remaining_reproduction_time=4) , None],
324
324
[None, None, None]]
325
325
326
326
>>> wt = WaTor(WIDTH, HEIGHT)
@@ -330,8 +330,10 @@ def move_and_reproduce(
330
330
>>> wt.move_and_reproduce(reproducable_entity,
331
331
... direction_orders=["N", "W", "S", "E"])
332
332
>>> wt.planet # doctest: +NORMALIZE_WHITESPACE
333
- [[<entity_type=predator coords=(0, 0) remaining_reproduction_time=20 energy=15>,
334
- <entity_type=predator coords=(0, 1) remaining_reproduction_time=20 energy=15>]]
333
+ [[Entity(prey=False, coords=(0, 0),
334
+ remaining_reproduction_time=20, energy_value=15),
335
+ Entity(prey=False, coords=(0, 1), remaining_reproduction_time=20,
336
+ energy_value=15)]]
335
337
"""
336
338
coords = entity .coords
337
339
row , col = coords
@@ -400,8 +402,8 @@ def perform_prey_actions(
400
402
>>> wt.perform_prey_actions(reproducable_entity,
401
403
... direction_orders=["N", "W", "S", "E"])
402
404
>>> wt.planet # doctest: +NORMALIZE_WHITESPACE
403
- [[<entity_type= prey coords=(0, 0) remaining_reproduction_time=5> ,
404
- <entity_type= prey coords=(0, 1) remaining_reproduction_time=5> ]]
405
+ [[Entity( prey=True, coords=(0, 0), remaining_reproduction_time=5) ,
406
+ Entity( prey=True, coords=(0, 1), remaining_reproduction_time=5) ]]
405
407
"""
406
408
self .move_and_reproduce (entity , direction_orders )
407
409
@@ -431,8 +433,8 @@ def perform_predator_actions(
431
433
>>> wt.set_planet([[Entity(True, coords=(0, 0)), Entity(False, coords=(0, 1))]])
432
434
>>> wt.perform_predator_actions(Entity(False, coords=(0, 1)), (0, 0), [])
433
435
>>> wt.planet # doctest: +NORMALIZE_WHITESPACE
434
- [[<entity_type=predator coords=(0, 0)
435
- remaining_reproduction_time=20 energy =19> , None]]
436
+ [[Entity(prey=False, coords=(0, 0),
437
+ remaining_reproduction_time=20, energy_value =19) , None]]
436
438
"""
437
439
assert entity .energy_value is not None # [type checking]
438
440
@@ -576,9 +578,9 @@ def display_visually(wt: WaTor, iter_number: int, *, colour: bool = True) -> Non
576
578
577
579
578
580
if __name__ == "__main__" :
579
- # import doctest
581
+ import doctest
580
582
581
- # doctest.testmod()
583
+ doctest .testmod ()
582
584
583
585
wt = WaTor (WIDTH , HEIGHT )
584
586
wt .time_passed = display_visually
0 commit comments