import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot
import agentframework
import csv
import matplotlib.animation 



#create environment in which agents will operate
environment=[]

#read csv downloaded file 
f = open('in.txt', newline='') 
reader = csv.reader(f, quoting=csv.QUOTE_NONNUMERIC)
for row in reader:	
    rowlist=[]		# A list of rows
    environment.append(rowlist)
    for value in row:				# A list of value
        #print(value) 				# Floats
        rowlist.append(value)
f.close() 	# Don't close until you are done with the reader;
		# the data is read on request.
        



#def distance_between(agents_row_a, agents_row_b):
#    return (((agents_row_a.x - agents_row_b.x)**2) + 
#        ((agents_row_a.y - agents_row_b.y)**2))**0.5

num_of_agents = 10
num_of_iterations = 10
neighbourhood = 20

fig = matplotlib.pyplot.figure(figsize=(7, 7))
ax = fig.add_axes([0, 0, 1, 1])
# Make the agents and connecting with the environment.
agents = []


def update(frame_number):
    
    fig.clear()   
   

    for i in range(num_of_agents):
        agents.append(agentframework.Agent(environment,agents))



# Move and eat agents with every move or iteration.
    for j in range(num_of_iterations):
        for i in range(num_of_agents):
            agents[i].move()
            agents[i].eat()
            agents[i].share_with_neighbours(neighbourhood)
            
            
        
   
        
        
# Loop through the agents in self.agents .
    # Calculate the distance between self and the current other agent:
    # distance = self.distance_between(agent) 
    # If distance is less than or equal to the neighbourhood
        # Sum self.store and agent.store .
        # Divide sum by two to calculate average.
        # self.store = average
            # agent.store = average
    # End if
# End loop         
      
      
       
    
# plot
    matplotlib.pyplot.xlim(0, 299)
    matplotlib.pyplot.ylim(0, 299)
    for i in range(num_of_agents):
        matplotlib.pyplot.scatter(agents[i].x,agents[i].y)    
    matplotlib.pyplot.imshow(environment)    
    
animation = matplotlib.animation.FuncAnimation(fig, update, interval=1)
matplotlib.pyplot.show() 



[((18, 41), 'matplotlib.use', 'matplotlib.use', (['"""TkAgg"""'], {}), "('TkAgg')\n", (32, 41), False, 'import matplotlib\n'), ((265, 308), 'csv.reader', 'csv.reader', (['f'], {'quoting': 'csv.QUOTE_NONNUMERIC'}), '(f, quoting=csv.QUOTE_NONNUMERIC)\n', (275, 308), False, 'import csv\n'), ((837, 877), 'matplotlib.pyplot.figure', 'matplotlib.pyplot.figure', ([], {'figsize': '(7, 7)'}), '(figsize=(7, 7))\n', (861, 877), False, 'import matplotlib\n'), ((2119, 2178), 'matplotlib.animation.FuncAnimation', 'matplotlib.animation.FuncAnimation', (['fig', 'update'], {'interval': '(1)'}), '(fig, update, interval=1)\n', (2153, 2178), False, 'import matplotlib\n'), ((2179, 2203), 'matplotlib.pyplot.show', 'matplotlib.pyplot.show', ([], {}), '()\n', (2201, 2203), False, 'import matplotlib\n'), ((1892, 1922), 'matplotlib.pyplot.xlim', 'matplotlib.pyplot.xlim', (['(0)', '(299)'], {}), '(0, 299)\n', (1914, 1922), False, 'import matplotlib\n'), ((1927, 1957), 'matplotlib.pyplot.ylim', 'matplotlib.pyplot.ylim', (['(0)', '(299)'], {}), '(0, 299)\n', (1949, 1957), False, 'import matplotlib\n'), ((2060, 2097), 'matplotlib.pyplot.imshow', 'matplotlib.pyplot.imshow', (['environment'], {}), '(environment)\n', (2084, 2097), False, 'import matplotlib\n'), ((2001, 2052), 'matplotlib.pyplot.scatter', 'matplotlib.pyplot.scatter', (['agents[i].x', 'agents[i].y'], {}), '(agents[i].x, agents[i].y)\n', (2026, 2052), False, 'import matplotlib\n'), ((1091, 1132), 'agentframework.Agent', 'agentframework.Agent', (['environment', 'agents'], {}), '(environment, agents)\n', (1111, 1132), False, 'import agentframework\n')]