-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSean_the_sheep_of_the_dead_subpro.py
More file actions
127 lines (84 loc) · 3.19 KB
/
Sean_the_sheep_of_the_dead_subpro.py
File metadata and controls
127 lines (84 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 16 14:12:33 2019
@author: gynjkm
"""
#importing packages and creating list
import matplotlib.pyplot as plt
import matplotlib.animation
import agentframework_zombies
import csv
import random
import sys
#defining our arguments and creating the lists of sheep and zombiesheep
Sean_the_sheep_of_the_dead_subpro = sys.argv[0]
num_of_agents = int(sys.argv[1])
num_of_iterations = int(sys.argv[2])
neighbourhood = int(sys.argv[3])
num_of_zombsheep = int(sys.argv[4])
agents = []
zombsheep = []
#creating the environment from the csv file
environment = []
with open('in.txt', newline='') as f:
reader = csv.reader(f, quoting=csv.QUOTE_NONNUMERIC)
for row in reader:
rowlist = []
for value in row:
rowlist.append(value)
environment.append(rowlist)
#Testing to see if the environment has read in properly
"""
plt.imshow(environment)
plt.show()
"""
#Assign starting points to all our agents in their environment
for i in range (num_of_agents):
agents.append(agentframework_zombies.Agent(environment, agents))
for i in range (num_of_zombsheep):
zombsheep.append(agentframework_zombies.Zombiesheep(environment, zombsheep, agents))
#First we randomise the order of agents acting for every iteration, then we move
#them, make them eat, and share food with their neighbours
fig = plt.figure(figsize=(12, 12))
#Testing to see if our agents have acces to the locations of other agents
"""
print("Our first agent is at", agents[0].x, agents[0].y, ", some other agents he's heard of are at:")
for i in range(10):
print(agents[0].agents[i].x, agents[0].agents[i].y)
"""
def update(frame_number):
fig.clear()
plt.imshow(environment)
plt.xlim(0, agents[0].environment_width)
plt.ylim(0, agents[0].environment_height)
plt.xlim(0, zombsheep[0].environment_width)
plt.ylim(0, zombsheep[0].environment_height)
random.shuffle(agents)
random.shuffle(zombsheep)
for agent in agents:
agent.move()
agent.eat()
agent.share_with_neighbours(neighbourhood)
for zombiesheep in zombsheep:
zombiesheep.move()
target_agents = zombiesheep.bite(neighbourhood, agents, zombsheep) #creates a list of all sheep within "biting range"
for target in target_agents:
# adds a new zombie in place of the target's location
zombsheep.append(agentframework_zombies.Zombiesheep(environment, zombsheep, agents, [target.y, target.x]))
# kills the target
agents.remove(target)
#this is done in this order to avoid losing the coordinates of the target
#plots our sheep in white and our zombies in red
for agent in agents:
plt.scatter(agent.x,agent.y, c="snow")
for zombiesheep in zombsheep:
plt.scatter(zombiesheep.x,zombiesheep.y, c="red")
#Showing our agents in animation
plt.ylim(0, 299)
plt.xlim(0, 299)
plt.imshow(environment)
for i in range (num_of_agents):
plt.scatter(agents[i].x,agents[i].y)
animation = matplotlib.animation.FuncAnimation(fig, update, interval=0.1, repeat=False, frames=num_of_iterations)
plt.show()
print(len(agents))