diff options
Diffstat (limited to 'spiderworld.py')
| -rw-r--r-- | spiderworld.py | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/spiderworld.py b/spiderworld.py index 8cdbdf9..1f8487d 100644 --- a/spiderworld.py +++ b/spiderworld.py @@ -92,12 +92,40 @@ def update(): def main(): """ main function, do stuff """ - board = Terrain() - board.print_terrain() + board = Terrain(100, 100) - spider1 = Critter() + print(f"The board has a width of {board.size()[0]}, and a height of" + f" {board.size()[1]}.") - print("\nSpider1 left", spider1.expire(), "nutrients behind.") + spiders = [] + spider_count = 0 + + for tick in range(0, 1_000_000): + + if np.random.rand() < 0.2: + spiders.append(Critter(nutrient_value=1, + pos_x=np.random.randint(0, board.size()[0]), + pos_y=np.random.randint(0, board.size()[1]), + lifespan=10)) + print(f"Spider created at {tick}!", end='\r') + spider_count += 1 + + for spider in spiders: + state = spider.live() + + if state == 'dead': + board.update_nutrients(*spider.get_position(), spider.expire()) + spiders.remove(spider) + # print("A spider died.") + + print(f"There are {len(spiders)} spiders remaining" + f" of {spider_count} total.") + + xy = [x.get_position() for x in spiders] + print(*zip(*xy)) + plt.scatter(*zip(*xy), c="pink") + plt.imshow(board.get_terrain(), cmap='jet', interpolation="nearest") + plt.show() if __name__ == '__main__': |
