summaryrefslogtreecommitdiff
path: root/spiderworld.py
diff options
context:
space:
mode:
authorWillem Renes <wrenes@gmail.com>2021-05-06 12:45:53 +0200
committerWillem Renes <wrenes@gmail.com>2021-05-06 12:45:53 +0200
commit142c51551bf9916bed82ddba2862082c7c06ac3a (patch)
tree7d681e628ad240053453a99f6f71bbe56240a4e8 /spiderworld.py
parent8ee57f5c47b9656f76c6db80b34214a499e63999 (diff)
downloadSpiderWorld-142c51551bf9916bed82ddba2862082c7c06ac3a.tar.gz
SpiderWorld-142c51551bf9916bed82ddba2862082c7c06ac3a.zip
updating code (partial commit experiment)
Diffstat (limited to 'spiderworld.py')
-rw-r--r--spiderworld.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/spiderworld.py b/spiderworld.py
index f998f3a..9414c23 100644
--- a/spiderworld.py
+++ b/spiderworld.py
@@ -7,23 +7,49 @@ that could have on increasing the nutrient levels.
import numpy as np
class Terrain:
- """ Terrain class represents the terrain over which the model is run. """
+ """ Terrain class represents the terrain over which the model is run.
+
+ field: Shape of the terrain, and nutrient values
+ field_mask: mask for various attributes of the field (bit mask?)
+
+ """
def __init__(self, size_x=10, size_y=10):
""" Create a new field of size_x by size_y """
- self.field = np.zeros(shape=(size_x, size_y))
+ self.field = np.zeros(shape=(size_x, size_y), dtype=int)
+ self.field_mask = np.ones(shape=(size_x, size_y), dtype=bool)
def print_terrain(self):
""" Display the field """
- print(self.field)
+ print(f"Terrain:\n"
+ f"{self.field}\n"
+ f"Terrain mask:\n"
+ f"{self.field_mask}\n"
+ )
class Critter:
""" Basic class for a creature that can appear, modify the terrain, and
procreate or die. """
- def __init__(self, nutrient_value=1):
+ def __init__(self, nutrient_value=1, pos_x=0, pos_y=0, lifespan=10):
self.nutrient_value = nutrient_value
+ self.pos_x = pos_x
+ self.pos_y = pos_y
+ self.lifespan = lifespan
+
+ def live(self):
+ """ Live another tick, decrement lifespan, and resolve """
+ print("Living another tick")
+ self.lifespan -= 1
+ if not self.lifespan:
+ print("Expires!")
+ # self.expire()
+ return self.lifespan
+
+ def get_position(self):
+ """ Return the position of the critter """
+ return self.pos_x, self.pos_y
def expire(self):
""" Death of the critter """