+class PlayerStats:
+ def __init__(self, world):
+ roaches = world.roaches
+ self.health = sum(r.health for r in roaches)
+ self.smart = self._count_attr("smart", roaches)
+ self.fast = self._count_attr("fast", roaches)
+ self.strong = self._count_attr("strong", roaches)
+
+ def __str__(self):
+ return "<PlayerStats health=%d smart=%d fast=%d strong=%d>" % (
+ self.health, self.smart, self.fast, self.strong)
+
+ def _count_attr(self, attr, roaches):
+ attrs = [r[attr] for r in roaches]
+ attrs = [a for a in attrs if a]
+ return len(attrs)
+
+