diff options
| author | Willem Renes <wrenes@gmail.com> | 2021-05-12 02:20:40 +0200 |
|---|---|---|
| committer | Willem Renes <wrenes@gmail.com> | 2021-05-12 02:20:40 +0200 |
| commit | 1b4105c7466e10ff091483f7e1c68788a2ab7182 (patch) | |
| tree | 86aa65695a0b38662d711e4c0306064fc5712a7c /spiderworld.py | |
| parent | 57be6e1608e946623f3c6cd2b245cf4025a4f8b5 (diff) | |
| download | SpiderWorld-1b4105c7466e10ff091483f7e1c68788a2ab7182.tar.gz SpiderWorld-1b4105c7466e10ff091483f7e1c68788a2ab7182.zip | |
testing stufftesting
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__': |
